blob: 13c6e74b05f500efbd4fad1d44e015a391925a18 [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"
100#include "cds_concurrency.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"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800116
117#ifdef MODULE
118#define WLAN_MODULE_NAME module_name(THIS_MODULE)
119#else
120#define WLAN_MODULE_NAME "wlan"
121#endif
122
123#ifdef TIMER_MANAGER
124#define TIMER_MANAGER_STR " +TIMER_MANAGER"
125#else
126#define TIMER_MANAGER_STR ""
127#endif
128
129#ifdef MEMORY_DEBUG
130#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
131#else
132#define MEMORY_DEBUG_STR ""
133#endif
134
Arun Khandavallifae92942016-08-01 13:31:08 +0530135#ifndef MODULE
136static struct gwlan_loader *wlan_loader;
137static ssize_t wlan_boot_cb(struct kobject *kobj,
138 struct kobj_attribute *attr,
139 const char *buf, size_t count);
140struct gwlan_loader {
141 bool loaded_state;
142 struct kobject *boot_wlan_obj;
143 struct attribute_group *attr_group;
144};
145
146static struct kobj_attribute wlan_boot_attribute =
147 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
148
149static struct attribute *attrs[] = {
150 &wlan_boot_attribute.attr,
151 NULL,
152};
153
154#define MODULE_INITIALIZED 1
155#endif
156
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800157/* the Android framework expects this param even though we don't use it */
158#define BUF_LEN 20
159static char fwpath_buffer[BUF_LEN];
160static struct kparam_string fwpath = {
161 .string = fwpath_buffer,
162 .maxlen = BUF_LEN,
163};
164
165static char *country_code;
166static int enable_11d = -1;
167static int enable_dfs_chan_scan = -1;
168
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800169/*
170 * spinlock for synchronizing asynchronous request/response
171 * (full description of use in wlan_hdd_main.h)
172 */
173DEFINE_SPINLOCK(hdd_context_lock);
174
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800175#define WLAN_NLINK_CESIUM 30
176
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530177static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800178
179#define WOW_MAX_FILTER_LISTS 1
180#define WOW_MAX_FILTERS_PER_LIST 4
181#define WOW_MIN_PATTERN_SIZE 6
182#define WOW_MAX_PATTERN_SIZE 64
183
184#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
185static const struct wiphy_wowlan_support wowlan_support_reg_init = {
186 .flags = WIPHY_WOWLAN_ANY |
187 WIPHY_WOWLAN_MAGIC_PKT |
188 WIPHY_WOWLAN_DISCONNECT |
189 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
190 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
191 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
192 WIPHY_WOWLAN_4WAY_HANDSHAKE |
193 WIPHY_WOWLAN_RFKILL_RELEASE,
194 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
195 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
196 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
197};
198#endif
199
200/* internal function declaration */
201
202struct sock *cesium_nl_srv_sock;
Arun Khandavalli13cb5da2017-01-19 15:43:52 +0530203struct completion wlan_start_comp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800204#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
205void wlan_hdd_auto_shutdown_cb(void);
206#endif
207
208/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530209 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
210 * @hdd_ctx: pointer to hdd_context_t
211 *
212 * Return: none
213 */
Jeff Johnson590e2012016-10-05 16:16:24 -0700214static void hdd_set_rps_cpu_mask(hdd_context_t *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530215{
216 hdd_adapter_t *adapter;
217 hdd_adapter_list_node_t *adapter_node, *next;
218 QDF_STATUS status = QDF_STATUS_SUCCESS;
219
220 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
221 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
222 adapter = adapter_node->pAdapter;
223 if (NULL != adapter)
224 hdd_send_rps_ind(adapter);
225 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
226 adapter_node = next;
227 }
228}
229
230/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
232 * @vdev_id: vdev_id
233 * @action: action type
234 * @reason: reason type
235 *
236 * Return: none
237 */
238void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
239 enum netif_action_type action, enum netif_reason_type reason)
240{
Anurag Chouhan6d760662016-02-20 16:05:43 +0530241 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800242 hdd_adapter_t *adapter;
243
244 if (!hdd_ctx) {
245 hdd_err("hdd ctx is NULL");
246 return;
247 }
248 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
249
250 wlan_hdd_netif_queue_control(adapter, action, reason);
251 return;
252}
253
254/*
255 * Store WLAN driver version info in a global variable such that crash debugger
256 * can extract it from driver debug symbol and crashdump for post processing
257 */
258uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
259
260/**
261 * hdd_device_mode_to_string() - return string conversion of device mode
262 * @device_mode: device mode
263 *
264 * This utility function helps log string conversion of device mode.
265 *
266 * Return: string conversion of device mode, if match found;
267 * "Unknown" otherwise.
268 */
269const char *hdd_device_mode_to_string(uint8_t device_mode)
270{
271 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800272 CASE_RETURN_STRING(QDF_STA_MODE);
273 CASE_RETURN_STRING(QDF_SAP_MODE);
274 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
275 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
276 CASE_RETURN_STRING(QDF_FTM_MODE);
277 CASE_RETURN_STRING(QDF_IBSS_MODE);
278 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
279 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700280 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281 default:
282 return "Unknown";
283 }
284}
285
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530286/**
287 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
288 * @adapter: HDD adapter
289 * @chan_number: Channel number
290 * @chan_bw: Bandwidth
291 *
292 * Checks if the given bandwidth is valid for the given channel number.
293 *
294 * Return: 0 for success, non-zero for failure
295 */
296int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
297 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800298 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530299{
300 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
301 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
302 bool found = false;
303 tHalHandle hal;
304
305 hal = WLAN_HDD_GET_HAL_CTX(adapter);
306 if (!hal) {
307 hdd_err("Invalid HAL context");
308 return -EINVAL;
309 }
310
311 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
312 hdd_err("No valid channel list");
313 return -EOPNOTSUPP;
314 }
315
316 for (i = 0; i < len; i++) {
317 if (chan[i] == chan_number) {
318 found = true;
319 break;
320 }
321 }
322
323 if (found == false) {
324 hdd_err("Channel not in driver's valid channel list");
325 return -EOPNOTSUPP;
326 }
327
328 if ((!CDS_IS_CHANNEL_24GHZ(chan_number)) &&
329 (!CDS_IS_CHANNEL_5GHZ(chan_number))) {
330 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
331 return -EINVAL;
332 }
333
334 if (CDS_IS_CHANNEL_24GHZ(chan_number)) {
335 if (chan_bw == CH_WIDTH_80MHZ) {
336 hdd_err("BW80 not possible in 2.4GHz band");
337 return -EINVAL;
338 }
339 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
340 (chan_bw != CH_WIDTH_MAX)) {
341 hdd_err("Only BW20 possible on channel 14");
342 return -EINVAL;
343 }
344 }
345
346 if (CDS_IS_CHANNEL_5GHZ(chan_number)) {
347 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
348 (chan_bw != CH_WIDTH_MAX)) {
349 hdd_err("Only BW20 possible on channel 165");
350 return -EINVAL;
351 }
352 }
353
354 return 0;
355}
356
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800357static int __hdd_netdev_notifier_call(struct notifier_block *nb,
358 unsigned long state, void *data)
359{
360#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
361 struct netdev_notifier_info *dev_notif_info = data;
362 struct net_device *dev = dev_notif_info->dev;
363#else
364 struct net_device *dev = data;
365#endif
366 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
367 hdd_context_t *hdd_ctx;
368
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800369 ENTER_DEV(dev);
370
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800371 /* Make sure that this callback corresponds to our device. */
372 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
373 return NOTIFY_DONE;
374
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530375 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800376 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700377 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800378 return NOTIFY_DONE;
379 }
380
381 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700382 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 return NOTIFY_DONE;
384 }
385
386 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
387 if (NULL == hdd_ctx) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700388 hdd_alert("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530389 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800390 return NOTIFY_DONE;
391 }
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800392 if (cds_is_driver_recovering())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800393 return NOTIFY_DONE;
394
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700395 hdd_notice("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800396 dev->name, state);
397
398 switch (state) {
399 case NETDEV_REGISTER:
400 break;
401
402 case NETDEV_UNREGISTER:
403 break;
404
405 case NETDEV_UP:
406 sme_ch_avoid_update_req(hdd_ctx->hHal);
407 break;
408
409 case NETDEV_DOWN:
410 break;
411
412 case NETDEV_CHANGE:
413 if (true == adapter->isLinkUpSvcNeeded)
414 complete(&adapter->linkup_event_var);
415 break;
416
417 case NETDEV_GOING_DOWN:
418 if (adapter->scan_info.mScanPending != false) {
419 unsigned long rc;
420 INIT_COMPLETION(adapter->scan_info.
421 abortscan_event_var);
422 hdd_abort_mac_scan(adapter->pHddCtx,
423 adapter->sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530424 INVALID_SCAN_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800425 eCSR_SCAN_ABORT_DEFAULT);
426 rc = wait_for_completion_timeout(
427 &adapter->scan_info.abortscan_event_var,
428 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
429 if (!rc) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700430 hdd_err("Timeout occurred while waiting for abortscan");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800431 }
432 } else {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700433 hdd_notice("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800434 }
435 break;
436
437 default:
438 break;
439 }
440
441 return NOTIFY_DONE;
442}
443
444/**
445 * hdd_netdev_notifier_call() - netdev notifier callback function
446 * @nb: pointer to notifier block
447 * @state: state
448 * @ndev: ndev pointer
449 *
450 * Return: 0 on success, error number otherwise.
451 */
452static int hdd_netdev_notifier_call(struct notifier_block *nb,
453 unsigned long state,
454 void *ndev)
455{
456 int ret;
457
458 cds_ssr_protect(__func__);
459 ret = __hdd_netdev_notifier_call(nb, state, ndev);
460 cds_ssr_unprotect(__func__);
461
462 return ret;
463}
464
465struct notifier_block hdd_netdev_notifier = {
466 .notifier_call = hdd_netdev_notifier_call,
467};
468
469/* variable to hold the insmod parameters */
470static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800471
472/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800473static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800474
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530475/**
476 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
477 * @ch_width: NL channel width
478 *
479 * Converts the NL channel width to the driver's internal representation
480 *
481 * Return: Converted channel width. In case of non matching NL channel width,
482 * CH_WIDTH_MAX will be returned.
483 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800484enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530485{
486 switch (ch_width) {
487 case NL80211_CHAN_WIDTH_20_NOHT:
488 case NL80211_CHAN_WIDTH_20:
489 return CH_WIDTH_20MHZ;
490 case NL80211_CHAN_WIDTH_40:
491 return CH_WIDTH_40MHZ;
492 break;
493 case NL80211_CHAN_WIDTH_80:
494 return CH_WIDTH_80MHZ;
495 case NL80211_CHAN_WIDTH_80P80:
496 return CH_WIDTH_80P80MHZ;
497 case NL80211_CHAN_WIDTH_160:
498 return CH_WIDTH_160MHZ;
499 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800500 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530501 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800502 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530503 default:
504 hdd_err("Invalid channel width %d, setting to default",
505 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800506 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530507 }
508}
509
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530510/* wlan_hdd_find_opclass() - Find operating class for a channel
511 * @hal: handler to HAL
512 * @channel: channel id
513 * @bw_offset: bandwidth offset
514 *
515 * Function invokes sme api to find the operating class
516 *
517 * Return: operating class
518 */
519uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
520 uint8_t bw_offset)
521{
522 uint8_t opclass = 0;
523
524 sme_get_opclass(hal, channel, bw_offset, &opclass);
525 return opclass;
526}
527
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800528/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530529 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530530 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531 * @bitmask: Bitmask of log levels to be enabled
532 *
533 * Called immediately after the cfg.ini is read in order to configure
534 * the desired trace levels.
535 *
536 * Return: None
537 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530538int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800539{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530540 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530541 int qdf_print_idx = -1;
542 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 /*
544 * if the bitmask is the default value, then a bitmask was not
545 * specified in cfg.ini, so leave the logging level alone (it
546 * will remain at the "compiled in" default value)
547 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530548 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask) {
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530549 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550 }
551
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530552 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800553
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530554 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530555 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530556 QDF_TRACE_LEVEL_NONE, 0);
557
558 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530559 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800560 /* now cycle through the bitmask until all "set" bits are serviced */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530561 level = QDF_TRACE_LEVEL_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 while (0 != bitmask) {
563 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530564 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530565 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530566 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530567 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800568 }
569 level++;
570 bitmask >>= 1;
571 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530572 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800573}
574
575/**
576 * wlan_hdd_validate_context() - check the HDD context
577 * @hdd_ctx: HDD context pointer
578 *
579 * Return: 0 if the context is valid. Error code otherwise
580 */
581int wlan_hdd_validate_context(hdd_context_t *hdd_ctx)
582{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530584 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800585 return -ENODEV;
586 }
587
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800588 if (cds_is_driver_recovering()) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530589 hdd_err("%pS Recovery in Progress. State: 0x%x Ignore!!!",
590 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800591 return -EAGAIN;
592 }
593
Rajeev Kumarfec3dbe2016-01-19 15:23:52 -0800594 if (cds_is_load_or_unload_in_progress()) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530595 hdd_err("%pS Unloading/Loading in Progress. Ignore!!!: 0x%x",
596 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800597 return -EAGAIN;
598 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530599
600 if (hdd_ctx->start_modules_in_progress ||
601 hdd_ctx->stop_modules_in_progress) {
602 hdd_err("%pS Start/Stop Modules in progress. Ignore!!!",
603 (void *)_RET_IP_);
604 return -EAGAIN;
605 }
606
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800607 return 0;
608}
609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800610/**
611 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
612 * @hdd_adapter_t Hdd adapter.
613 *
614 * This function sets the IBSS power save config parameters to WMA
615 * which will send it to firmware if FW supports IBSS power save
616 * before vdev start.
617 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530618 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800619 * on failure.
620 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530621QDF_STATUS hdd_set_ibss_power_save_params(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800622{
623 int ret;
624 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
625
626 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700627 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530628 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800629 }
630
631 ret = wma_cli_set_command(adapter->sessionId,
632 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
633 hdd_ctx->config->ibssATIMWinSize,
634 VDEV_CMD);
635 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700636 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530637 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800638 }
639
640 ret = wma_cli_set_command(adapter->sessionId,
641 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
642 hdd_ctx->config->isIbssPowerSaveAllowed,
643 VDEV_CMD);
644 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700645 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
646 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530647 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800648 }
649
650 ret = wma_cli_set_command(adapter->sessionId,
651 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
652 hdd_ctx->config->
653 isIbssPowerCollapseAllowed, VDEV_CMD);
654 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700655 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
656 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530657 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800658 }
659
660 ret = wma_cli_set_command(adapter->sessionId,
661 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
662 hdd_ctx->config->isIbssAwakeOnTxRx,
663 VDEV_CMD);
664 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700665 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530666 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667 }
668
669 ret = wma_cli_set_command(adapter->sessionId,
670 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
671 hdd_ctx->config->ibssInactivityCount,
672 VDEV_CMD);
673 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700674 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530675 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676 }
677
678 ret = wma_cli_set_command(adapter->sessionId,
679 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
680 hdd_ctx->config->ibssTxSpEndInactivityTime,
681 VDEV_CMD);
682 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700683 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
684 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530685 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686 }
687
688 ret = wma_cli_set_command(adapter->sessionId,
689 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
690 hdd_ctx->config->ibssPsWarmupTime,
691 VDEV_CMD);
692 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700693 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
694 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530695 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800696 }
697
698 ret = wma_cli_set_command(adapter->sessionId,
699 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
700 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
701 VDEV_CMD);
702 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700703 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
704 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530705 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800706 }
707
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530708 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800709}
710
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800711#define INTF_MACADDR_MASK 0x7
712
713/**
714 * hdd_update_macaddr() - update mac address
715 * @config: hdd configuration
716 * @hw_macaddr: mac address
717 *
718 * Mac address for multiple virtual interface is found as following
719 * i) The mac address of the first interface is just the actual hw mac address.
720 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
721 * define the mac address for the remaining interfaces and locally
722 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
723 * supported virtual interfaces, right now this is 0x07 (meaning 8
724 * interface).
725 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
726 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
727 *
728 * Return: None
729 */
730void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530731 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800732{
733 int8_t i;
734 uint8_t macaddr_b3, tmp_br3;
735
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530736 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530737 QDF_MAC_ADDR_SIZE);
738 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530739 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530740 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741 macaddr_b3 = config->intfMacAddr[i].bytes[3];
742 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
743 INTF_MACADDR_MASK;
744 macaddr_b3 += tmp_br3;
745
746 /* XOR-ing bit-24 of the mac address. This will give enough
747 * mac address range before collision
748 */
749 macaddr_b3 ^= (1 << 7);
750
751 /* Set locally administered bit */
752 config->intfMacAddr[i].bytes[0] |= 0x02;
753 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700754 hdd_notice("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800755 MAC_ADDRESS_STR, i,
756 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
757 }
758}
759
760static void hdd_update_tgt_services(hdd_context_t *hdd_ctx,
761 struct wma_tgt_services *cfg)
762{
763 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764
765 /* Set up UAPSD */
766 config->apUapsdEnabled &= cfg->uapsd;
767
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800768 /* 11AC mode support */
769 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
770 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
771 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772
773 /* ARP offload: override user setting if invalid */
774 config->fhostArpOffload &= cfg->arp_offload;
775
776#ifdef FEATURE_WLAN_SCAN_PNO
777 /* PNO offload */
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700778 hdd_info("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800779 if (cfg->pno_offload)
780 config->PnoOffload = true;
781#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782#ifdef FEATURE_WLAN_TDLS
783 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530784 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
785 cfg->en_tdls_offchan;
786 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
787 cfg->en_tdls_uapsd_buf_sta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta) {
789 config->fEnableTDLSSleepSta = true;
790 } else {
791 config->fEnableTDLSSleepSta = false;
792 }
793#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794#ifdef WLAN_FEATURE_ROAM_OFFLOAD
795 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
796#endif
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700797 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800798
799}
800
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700801/**
802 * hdd_update_vdev_nss() - sets the vdev nss
803 * @hdd_ctx: HDD context
804 *
805 * Sets the Nss per vdev type based on INI
806 *
807 * Return: None
808 */
809static void hdd_update_vdev_nss(hdd_context_t *hdd_ctx)
810{
811 struct hdd_config *cfg_ini = hdd_ctx->config;
812 uint8_t max_supp_nss = 1;
813
Naveen Rawat10b1c152017-01-18 11:16:06 -0800814 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700815 max_supp_nss = 2;
816
817 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
818 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
819
820 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
821 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
822}
823
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824static void hdd_update_tgt_ht_cap(hdd_context_t *hdd_ctx,
825 struct wma_tgt_ht_cap *cfg)
826{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530827 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 uint32_t value, val32;
829 uint16_t val16;
830 struct hdd_config *pconfig = hdd_ctx->config;
831 tSirMacHTCapabilityInfo *phtCapInfo;
832 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
833 uint8_t enable_tx_stbc;
834
835 /* check and update RX STBC */
836 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
837 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
838
839 /* get the MPDU density */
840 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
841
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530842 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700843 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 value = 0;
845 }
846
847 /*
848 * MPDU density:
849 * override user's setting if value is larger
850 * than the one supported by target
851 */
852 if (value > cfg->mpdu_density) {
853 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
854 cfg->mpdu_density);
855
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530856 if (status == QDF_STATUS_E_FAILURE)
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700857 hdd_alert("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 }
859
860 /* get the HT capability info */
861 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530862 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700863 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 return;
865 }
866 val16 = (uint16_t) val32;
867 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
868
869 /* Set the LDPC capability */
870 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
871
872 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
873 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
874
875 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
876 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
877
878 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
879 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
880
881 enable_tx_stbc = pconfig->enableTxSTBC;
882
883 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
884 pconfig->enable2x2 = 1;
885 } else {
886 pconfig->enable2x2 = 0;
887 enable_tx_stbc = 0;
888
889 /* 1x1 */
890 /* Update Rx Highest Long GI data Rate */
891 if (sme_cfg_set_int(hdd_ctx->hHal,
892 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700893 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530894 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700895 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 }
897
898 /* Update Tx Highest Long GI data Rate */
899 if (sme_cfg_set_int
900 (hdd_ctx->hHal,
901 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700902 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530903 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700904 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 }
906 }
907 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
908 enable_tx_stbc = 0;
909 phtCapInfo->txSTBC = enable_tx_stbc;
910
911 val32 = val16;
912 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530913 if (status != QDF_STATUS_SUCCESS)
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700914 hdd_alert("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
916 value = SIZE_OF_SUPPORTED_MCS_SET;
917 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530918 &value) == QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700919 hdd_notice("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920
921 if (pconfig->enable2x2) {
922 for (value = 0; value < cfg->num_rf_chains; value++)
923 mcs_set[value] =
924 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
925
926 status =
927 sme_cfg_set_str(hdd_ctx->hHal,
928 WNI_CFG_SUPPORTED_MCS_SET,
929 mcs_set,
930 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530931 if (status == QDF_STATUS_E_FAILURE)
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700932 hdd_alert("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 }
934 }
935#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
936}
937
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800938static void hdd_update_tgt_vht_cap(hdd_context_t *hdd_ctx,
939 struct wma_tgt_vht_cap *cfg)
940{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530941 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800942 uint32_t value = 0;
943 struct hdd_config *pconfig = hdd_ctx->config;
944 struct wiphy *wiphy = hdd_ctx->wiphy;
945 struct ieee80211_supported_band *band_5g =
Dustin Browna30892e2016-10-12 17:28:36 -0700946 wiphy->bands[NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700947 uint32_t temp = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948
Dustin Brown5e06bd32016-10-04 12:49:10 -0700949 if (!band_5g) {
950 hdd_info("5GHz band disabled, skipping capability population");
951 return;
952 }
953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800954 /* Get the current MPDU length */
955 status =
956 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
957 &value);
958
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530959 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700960 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 value = 0;
962 }
963
964 /*
965 * VHT max MPDU length:
966 * override if user configured value is too high
967 * that the target cannot support
968 */
969 if (value > cfg->vht_max_mpdu) {
970 status = sme_cfg_set_int(hdd_ctx->hHal,
971 WNI_CFG_VHT_MAX_MPDU_LENGTH,
972 cfg->vht_max_mpdu);
973
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530974 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700975 hdd_alert("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976 }
977 }
978
979 /* Get the current supported chan width */
980 status = sme_cfg_get_int(hdd_ctx->hHal,
981 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
982 &value);
983
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530984 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700985 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986 value = 0;
987 }
988
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700989 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
990 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
991
992 if (pconfig->enable2x2)
993 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
994
995 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
996 QDF_STATUS_E_FAILURE) {
997 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
998 }
999
1000 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1001 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1002 if (pconfig->enable2x2)
1003 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1004
1005 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1006 QDF_STATUS_E_FAILURE) {
1007 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1008 }
1009
1010 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1011 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1012 if (pconfig->enable2x2)
1013 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1014
1015 hdd_info("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
1016 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1017
1018 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1019 QDF_STATUS_E_FAILURE) {
1020 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1021 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001023 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001024 &value);
1025
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301026 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001027 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 value = 0;
1029 }
1030
1031 /* Set the LDPC capability */
1032 if (value && !cfg->vht_rx_ldpc) {
1033 status = sme_cfg_set_int(hdd_ctx->hHal,
1034 WNI_CFG_VHT_LDPC_CODING_CAP,
1035 cfg->vht_rx_ldpc);
1036
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301037 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001038 hdd_alert("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039 }
1040 }
1041
1042 /* Get current GI 80 value */
1043 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1044 &value);
1045
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301046 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001047 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048 value = 0;
1049 }
1050
1051 /* set the Guard interval 80MHz */
1052 if (value && !cfg->vht_short_gi_80) {
1053 status = sme_cfg_set_int(hdd_ctx->hHal,
1054 WNI_CFG_VHT_SHORT_GI_80MHZ,
1055 cfg->vht_short_gi_80);
1056
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301057 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001058 hdd_alert("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001059 }
1060 }
1061
1062 /* Get current GI 160 value */
1063 status = sme_cfg_get_int(hdd_ctx->hHal,
1064 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1065 &value);
1066
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301067 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001068 hdd_err("could not get SHORT GI 80 & 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001069 value = 0;
1070 }
1071
1072 /* Get VHT TX STBC cap */
1073 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1074
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301075 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001076 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077 value = 0;
1078 }
1079
1080 /* VHT TX STBC cap */
1081 if (value && !cfg->vht_tx_stbc) {
1082 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1083 cfg->vht_tx_stbc);
1084
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301085 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001086 hdd_alert("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001087 }
1088 }
1089
1090 /* Get VHT RX STBC cap */
1091 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1092
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301093 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001094 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001095 value = 0;
1096 }
1097
1098 /* VHT RX STBC cap */
1099 if (value && !cfg->vht_rx_stbc) {
1100 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1101 cfg->vht_rx_stbc);
1102
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301103 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001104 hdd_alert("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 }
1106 }
1107
1108 /* Get VHT SU Beamformer cap */
1109 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1110 &value);
1111
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301112 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001113 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 value = 0;
1115 }
1116
1117 /* set VHT SU Beamformer cap */
1118 if (value && !cfg->vht_su_bformer) {
1119 status = sme_cfg_set_int(hdd_ctx->hHal,
1120 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1121 cfg->vht_su_bformer);
1122
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301123 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001124 hdd_alert("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125 }
1126 }
1127
1128 /* check and update SU BEAMFORMEE capabality */
1129 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1130 pconfig->enableTxBF = cfg->vht_su_bformee;
1131
1132 status = sme_cfg_set_int(hdd_ctx->hHal,
1133 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1134 pconfig->enableTxBF);
1135
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301136 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001137 hdd_alert("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 }
1139
1140 /* Get VHT MU Beamformer cap */
1141 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1142 &value);
1143
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301144 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001145 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146 value = 0;
1147 }
1148
1149 /* set VHT MU Beamformer cap */
1150 if (value && !cfg->vht_mu_bformer) {
1151 status = sme_cfg_set_int(hdd_ctx->hHal,
1152 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1153 cfg->vht_mu_bformer);
1154
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301155 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001156 hdd_alert("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157 }
1158 }
1159
1160 /* Get VHT MU Beamformee cap */
1161 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1162 &value);
1163
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301164 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001165 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166 value = 0;
1167 }
1168
1169 /* set VHT MU Beamformee cap */
1170 if (value && !cfg->vht_mu_bformee) {
1171 status = sme_cfg_set_int(hdd_ctx->hHal,
1172 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1173 cfg->vht_mu_bformee);
1174
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301175 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001176 hdd_alert("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001177 }
1178 }
1179
1180 /* Get VHT MAX AMPDU Len exp */
1181 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
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 VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001186 value = 0;
1187 }
1188
1189 /*
1190 * VHT max AMPDU len exp:
1191 * override if user configured value is too high
1192 * that the target cannot support.
1193 * Even though Rome publish ampdu_len=7, it can
1194 * only support 4 because of some h/w bug.
1195 */
1196
1197 if (value > cfg->vht_max_ampdu_len_exp) {
1198 status = sme_cfg_set_int(hdd_ctx->hHal,
1199 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1200 cfg->vht_max_ampdu_len_exp);
1201
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301202 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001203 hdd_alert("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 }
1205 }
1206
1207 /* Get VHT TXOP PS CAP */
1208 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1209
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301210 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001211 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 value = 0;
1213 }
1214
1215 /* set VHT TXOP PS cap */
1216 if (value && !cfg->vht_txop_ps) {
1217 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1218 cfg->vht_txop_ps);
1219
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301220 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001221 hdd_alert("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001222 }
1223 }
1224
1225 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1226 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1227 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1228 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1229 else
1230 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1231
1232
Amar Singhal90aaa6a2016-03-01 16:53:37 -08001233 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 band_5g->vht_cap.cap |=
1235 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Amar Singhal90aaa6a2016-03-01 16:53:37 -08001236 else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 band_5g->vht_cap.cap |=
1238 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239
1240 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1241 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1242
1243 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1244 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1245 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1246 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1247
1248 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1249 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1250
1251 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1252 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1253 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1254 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1255 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1256 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1257
1258 band_5g->vht_cap.cap |=
1259 (cfg->vht_max_ampdu_len_exp <<
1260 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1261
1262 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1263 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1264 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1265 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1266 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1267 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1268 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1269 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1270
1271 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1272 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1273
1274}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001275
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001276/**
1277 * hdd_generate_macaddr_auto() - Auto-generate mac address
1278 * @hdd_ctx: Pointer to the HDD context
1279 *
1280 * Auto-generate mac address using device serial number.
1281 * Keep the first 3 bytes of OUI as before and replace
1282 * the last 3 bytes with the lower 3 bytes of serial number.
1283 *
1284 * Return: 0 for success
1285 * Non zero failure code for errors
1286 */
1287static int hdd_generate_macaddr_auto(hdd_context_t *hdd_ctx)
1288{
1289 unsigned int serialno = 0;
1290 struct qdf_mac_addr mac_addr = {
1291 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1292 };
1293
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001294 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001295 if (serialno == 0)
1296 return -EINVAL;
1297
1298 serialno &= 0x00ffffff;
1299
1300 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1301 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1302 mac_addr.bytes[5] = serialno & 0xff;
1303
1304 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1305 return 0;
1306}
1307
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301308/**
1309 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1310 * configuration to cfg_ini in HDD
1311 * @hdd_ctx: Pointer to hdd_ctx
1312 * @cfg: target configuration
1313 *
1314 * Return: None
1315 */
1316#ifdef FEATURE_WLAN_RA_FILTERING
1317static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1318 struct wma_tgt_cfg *cfg)
1319{
1320 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1321}
1322#else
1323static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1324 struct wma_tgt_cfg *cfg)
1325{
1326}
1327#endif
1328
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329void hdd_update_tgt_cfg(void *context, void *param)
1330{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001331 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001332 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1333 struct wma_tgt_cfg *cfg = param;
1334 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001335 struct cds_config_info *cds_cfg = cds_get_ini_config();
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301336
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001337 ret = hdd_create_and_store_pdev(hdd_ctx);
1338 if (ret) {
1339 hdd_err("pdev creation fails!");
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301340 QDF_BUG(0);
1341 }
Naveen Rawat64e477e2016-05-20 10:34:56 -07001342
1343 if (cds_cfg) {
1344 if (hdd_ctx->config->enable_sub_20_channel_width !=
1345 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1346 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1347 cds_cfg->sub_20_channel_width =
1348 WLAN_SUB_20_CH_WIDTH_NONE;
1349 } else {
1350 cds_cfg->sub_20_channel_width =
1351 hdd_ctx->config->enable_sub_20_channel_width;
1352 }
1353 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354
1355 /* first store the INI band capability */
1356 temp_band_cap = hdd_ctx->config->nBandCapability;
1357
1358 hdd_ctx->config->nBandCapability = cfg->band_cap;
1359
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001360 /*
1361 * now overwrite the target band capability with INI
1362 * setting if INI setting is a subset
1363 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364
1365 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1366 (temp_band_cap != eCSR_BAND_ALL))
1367 hdd_ctx->config->nBandCapability = temp_band_cap;
1368 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1369 (temp_band_cap != eCSR_BAND_ALL) &&
1370 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001371 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001372 }
1373
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001374 if (!cds_is_driver_recovering()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001375 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1376 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1377 }
1378
1379 /* This can be extended to other configurations like ht, vht cap... */
1380
Anurag Chouhanc5548422016-02-24 18:33:27 +05301381 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001383 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001385 static struct qdf_mac_addr default_mac_addr = {
1386 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1387 };
1388 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1389 &default_mac_addr)) {
1390 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1391 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1392 MAC_ADDRESS_STR,
1393 MAC_ADDR_ARRAY(hdd_ctx->config->
1394 intfMacAddr[0].bytes));
1395 } else {
1396 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1397 MAC_ADDRESS_STR,
1398 MAC_ADDR_ARRAY(hdd_ctx->config->
1399 intfMacAddr[0].bytes));
1400 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001401 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 }
1403
1404 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001405 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406
1407 hdd_ctx->max_intf_count = cfg->max_intf_count;
1408
Jeff Johnsonc875e242016-09-23 18:12:34 -07001409 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001410 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001411
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001412 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1413 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1414
1415 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001418
1419 hdd_update_vdev_nss(hdd_ctx);
1420
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001421 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001422 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001423 hdd_info("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001424 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001425
1426 hdd_ctx->current_antenna_mode =
1427 (hdd_ctx->config->enable2x2 == 0x01) ?
1428 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1429 hdd_info("Init current antenna mode: %d",
1430 hdd_ctx->current_antenna_mode);
1431
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001432 hdd_info("Target BPF %d Host BPF %d",
1433 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable);
1434 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1435 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301436 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301437
Arun Khandavallid454d422016-08-17 12:47:05 +05301438 /*
1439 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1440 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1441 * configure the STA mode wow pattern.
1442 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301443 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301444 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301445
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301446 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1447
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001448 /* Configure NAN datapath features */
1449 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450}
1451
1452/**
1453 * hdd_dfs_indicate_radar() - handle radar detection on current SAP channel
1454 * @context: HDD context pointer
1455 * @param: HDD radar indication pointer
1456 *
Sandeep Puligillaa8d4eec2016-06-30 15:13:11 -07001457 * This function is invoked in atomic context when a radar
1458 * is found on the SAP current operating channel and Data Tx
1459 * from netif has to be stopped to honor the DFS regulations.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460 * Actions: Stop the netif Tx queues,Indicate Radar present
1461 * in HDD context for future usage.
1462 *
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301463 * Return: true to allow radar indication to host else false
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464 */
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301465bool hdd_dfs_indicate_radar(void *context, void *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466{
1467 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1468 struct wma_dfs_radar_ind *hdd_radar_event =
1469 (struct wma_dfs_radar_ind *)param;
1470 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1471 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301472 QDF_STATUS status;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301473 hdd_ap_ctx_t *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001474
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301475 if (!hdd_ctx || !hdd_radar_event ||
1476 hdd_ctx->config->disableDFSChSwitch)
1477 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001478
1479 if (true == hdd_radar_event->dfs_radar_status) {
Arif Hussain2a7c1f32016-07-18 14:24:36 -07001480 if (qdf_atomic_inc_return(&hdd_ctx->dfs_radar_found) > 1) {
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301481 /*
1482 * Application already triggered channel switch
1483 * on current channel, so return here.
1484 */
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301485 return false;
1486 }
1487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301489 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 adapter = adapterNode->pAdapter;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301491 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1492 if ((QDF_SAP_MODE == adapter->device_mode ||
1493 QDF_P2P_GO_MODE == adapter->device_mode) &&
1494 (CHANNEL_STATE_DFS ==
1495 cds_get_channel_state(ap_ctx->operatingChannel))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 WLAN_HDD_GET_AP_CTX_PTR(adapter)->
1497 dfs_cac_block_tx = true;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301498 hdd_info("tx blocked for session:%d",
1499 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500 }
1501
1502 status = hdd_get_next_adapter(hdd_ctx,
1503 adapterNode,
1504 &pNext);
1505 adapterNode = pNext;
1506 }
1507 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301508
1509 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511
1512/**
1513 * hdd_is_valid_mac_address() - validate MAC address
1514 * @pMacAddr: Pointer to the input MAC address
1515 *
1516 * This function validates whether the given MAC address is valid or not
1517 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1518 * where X is the hexa decimal digit character and separated by ':'
1519 * This algorithm works even if MAC address is not separated by ':'
1520 *
1521 * This code checks given input string mac contains exactly 12 hexadecimal
1522 * digits and a separator colon : appears in the input string only after
1523 * an even number of hex digits.
1524 *
1525 * Return: 1 for valid and 0 for invalid
1526 */
1527bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1528{
1529 int xdigit = 0;
1530 int separator = 0;
1531 while (*pMacAddr) {
1532 if (isxdigit(*pMacAddr)) {
1533 xdigit++;
1534 } else if (':' == *pMacAddr) {
1535 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1536 break;
1537
1538 ++separator;
1539 } else {
1540 /* Invalid MAC found */
1541 return 0;
1542 }
1543 ++pMacAddr;
1544 }
1545 return xdigit == 12 && (separator == 5 || separator == 0);
1546}
1547
1548/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301549 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1550 * @dev: Handle to struct net_device to be updated.
1551 *
1552 * Return: None
1553 */
1554static void hdd_mon_mode_ether_setup(struct net_device *dev)
1555{
1556 dev->header_ops = NULL;
1557 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1558 dev->hard_header_len = ETH_HLEN;
1559 dev->mtu = ETH_DATA_LEN;
1560 dev->addr_len = ETH_ALEN;
1561 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1562 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1563 dev->priv_flags |= IFF_TX_SKB_SHARING;
1564
1565 memset(dev->broadcast, 0xFF, ETH_ALEN);
1566}
1567
1568/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001569 * __hdd__mon_open() - HDD Open function
1570 * @dev: Pointer to net_device structure
1571 *
1572 * This is called in response to ifconfig up
1573 *
1574 * Return: 0 for success; non-zero for failure
1575 */
1576static int __hdd_mon_open(struct net_device *dev)
1577{
1578 int ret;
1579
1580 ENTER_DEV(dev);
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301581 hdd_mon_mode_ether_setup(dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001582 ret = hdd_set_mon_rx_cb(dev);
1583 return ret;
1584}
1585
1586/**
1587 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1588 * @dev: Pointer to net_device structure
1589 *
1590 * This is called in response to ifconfig up
1591 *
1592 * Return: 0 for success; non-zero for failure
1593 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001594static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001595{
1596 int ret;
1597
1598 cds_ssr_protect(__func__);
1599 ret = __hdd_mon_open(dev);
1600 cds_ssr_unprotect(__func__);
1601
1602 return ret;
1603}
1604
1605/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301606 * hdd_start_adapter() - Wrapper function for device specific adapter
1607 * @adapter: pointer to HDD adapter
1608 *
1609 * This function is called to start the device specific adapter for
1610 * the mode passed in the adapter's device_mode.
1611 *
1612 * Return: 0 for success; non-zero for failure
1613 */
1614int hdd_start_adapter(hdd_adapter_t *adapter)
1615{
1616
1617 int ret;
1618 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1619
1620 ENTER_DEV(adapter->dev);
1621 hdd_info("Start_adapter for mode : %d", adapter->device_mode);
1622
1623 switch (device_mode) {
1624 case QDF_P2P_CLIENT_MODE:
1625 case QDF_P2P_DEVICE_MODE:
1626 case QDF_OCB_MODE:
1627 case QDF_STA_MODE:
1628 case QDF_MONITOR_MODE:
1629 ret = hdd_start_station_adapter(adapter);
1630 if (ret)
1631 goto err_start_adapter;
1632 break;
1633 case QDF_P2P_GO_MODE:
1634 case QDF_SAP_MODE:
1635 ret = hdd_start_ap_adapter(adapter);
1636 if (ret)
1637 goto err_start_adapter;
1638 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301639 case QDF_IBSS_MODE:
1640 /*
1641 * For IBSS interface is initialized as part of
1642 * hdd_init_station_mode()
1643 */
1644 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301645 case QDF_FTM_MODE:
1646 ret = hdd_start_ftm_adapter(adapter);
1647 if (ret)
1648 goto err_start_adapter;
1649 break;
1650 default:
1651 hdd_err("Invalid session type %d", device_mode);
1652 QDF_ASSERT(0);
1653 goto err_start_adapter;
1654 }
1655 if (hdd_set_fw_params(adapter))
1656 hdd_err("Failed to set the FW params for the adapter!");
1657
1658 /*
1659 * Action frame registered in one adapter which will
1660 * applicable to all interfaces
1661 */
1662 wlan_hdd_cfg80211_register_frames(adapter);
1663 EXIT();
1664 return 0;
1665err_start_adapter:
1666 return -EINVAL;
1667}
1668
1669/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301670 * hdd_enable_power_management() - API to Enable Power Management
1671 *
1672 * API invokes Bus Interface Layer power management functionality
1673 *
1674 * Return: None
1675 */
1676static void hdd_enable_power_management(void)
1677{
1678 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1679
1680 if (!hif_ctx) {
1681 hdd_err("Bus Interface Context is Invalid");
1682 return;
1683 }
1684
1685 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1686}
1687
1688/**
1689 * hdd_disable_power_management() - API to disable Power Management
1690 *
1691 * API disable Bus Interface Layer Power management functionality
1692 *
1693 * Return: None
1694 */
1695static void hdd_disable_power_management(void)
1696{
1697 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1698
1699 if (!hif_ctx) {
1700 hdd_err("Bus Interface Context is Invalid");
1701 return;
1702 }
1703
1704 hif_disable_power_management(hif_ctx);
1705}
1706
1707/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301708 * hdd_update_hw_sw_info() - API to update the HW/SW information
1709 *
1710 * API to update the HW and SW information in the driver
1711 *
1712 * Return: None
1713 */
1714static void hdd_update_hw_sw_info(hdd_context_t *hdd_ctx)
1715{
1716 void *hif_sc;
1717
1718 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1719 if (!hif_sc) {
1720 hdd_err("HIF context is NULL");
1721 return;
1722 }
1723
1724 /*
1725 * target hw version/revision would only be retrieved after firmware
1726 * download
1727 */
1728 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
1729 &hdd_ctx->target_hw_revision,
1730 &hdd_ctx->target_hw_name);
1731
1732 /* Get the wlan hw/fw version */
1733 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
1734
1735 return;
1736}
1737
1738/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301739 * hdd_wlan_start_modules() - Single driver state machine for starting modules
1740 * @hdd_ctx: HDD context
1741 * @adapter: HDD adapter
1742 * @reinit: flag to indicate from SSR or normal path
1743 *
1744 * This function maintains the driver state machine it will be invoked from
1745 * startup, reinit and change interface. Depending on the driver state shall
1746 * perform the opening of the modules.
1747 *
1748 * Return: 0 for success; non-zero for failure
1749 */
1750int hdd_wlan_start_modules(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
1751 bool reinit)
1752{
1753 int ret;
1754 qdf_device_t qdf_dev;
1755 QDF_STATUS status;
1756 p_cds_contextType p_cds_context;
1757 bool unint = false;
1758 void *hif_ctx;
1759
1760 ENTER();
1761
1762 p_cds_context = cds_get_global_context();
1763 if (!p_cds_context) {
1764 hdd_err("Global Context is NULL");
1765 QDF_ASSERT(0);
1766 return -EINVAL;
1767 }
1768
1769 hdd_info("start modules called in state! :%d reinit: %d",
1770 hdd_ctx->driver_status, reinit);
1771
1772 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
1773 if (!qdf_dev) {
1774 hdd_err("QDF Device Context is Invalid return");
1775 return -EINVAL;
1776 }
1777
1778 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301779 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05301780
1781 if (QDF_TIMER_STATE_RUNNING ==
1782 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
1783
1784 hdd_set_idle_ps_config(hdd_ctx, false);
1785 hdd_info("Interface change Timer running Stop timer");
1786 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
1787 }
1788
1789 switch (hdd_ctx->driver_status) {
1790 case DRIVER_MODULES_UNINITIALIZED:
1791 unint = true;
1792 /* Fall through dont add break here */
1793 case DRIVER_MODULES_CLOSED:
1794 if (!reinit && !unint) {
1795 ret = pld_power_on(qdf_dev->dev);
1796 if (ret) {
1797 hdd_err("Failed to Powerup the device: %d", ret);
1798 goto release_lock;
1799 }
1800 }
1801 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
1802 qdf_dev->bus_type,
1803 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
1804 HIF_ENABLE_TYPE_PROBE);
1805 if (ret) {
1806 hdd_err("Failed to open hif: %d", ret);
1807 goto power_down;
1808 }
1809
1810 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05301811 if (!hif_ctx) {
1812 hdd_err("hif context is null!!");
1813 goto power_down;
1814 }
1815
Arun Khandavallifae92942016-08-01 13:31:08 +05301816 status = ol_cds_init(qdf_dev, hif_ctx);
1817 if (status != QDF_STATUS_SUCCESS) {
1818 hdd_err("No Memory to Create BMI Context :%d", status);
1819 goto hif_close;
1820 }
1821
Rajeev Kumar138ef912017-01-13 15:19:48 -08001822 ret = hdd_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
1823 if (ret) {
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301824 hdd_err("Psoc creation fails!");
1825 goto ol_cds_free;
1826 }
1827
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08001828 ret = hdd_update_config(hdd_ctx);
1829 if (ret) {
1830 hdd_err("Failed to update configuration :%d", ret);
1831 goto destroy_psoc_object;
1832 }
1833
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301834 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05301835 if (!QDF_IS_STATUS_SUCCESS(status)) {
1836 hdd_err("Failed to Open CDS: %d", status);
Selvaraj, Sridhara7dc2382017-01-27 18:29:39 +05301837 goto destroy_psoc_object;
Arun Khandavallifae92942016-08-01 13:31:08 +05301838 }
1839
Mukul Sharma9d797a02017-01-05 20:26:03 +05301840 /* initalize components configurations after psoc open */
1841 ret = hdd_update_components_config(hdd_ctx);
1842 if (ret) {
1843 hdd_err("Failed to update components configs :%d",
1844 ret);
1845 goto close;
1846 }
1847
Arun Khandavallifae92942016-08-01 13:31:08 +05301848 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
1849
1850 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
1851
1852 status = cds_pre_enable(hdd_ctx->pcds_context);
1853 if (!QDF_IS_STATUS_SUCCESS(status)) {
1854 hdd_err("Failed to pre-enable CDS: %d", status);
1855 goto close;
1856 }
1857
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301858 hdd_update_hw_sw_info(hdd_ctx);
1859
Arun Khandavallifae92942016-08-01 13:31:08 +05301860 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
1861 sme_register_ftm_msg_processor(hdd_ctx->hHal,
1862 hdd_ftm_mc_process_msg);
1863 break;
1864 }
1865 if (unint) {
1866 hdd_info("In phase-1 initialization don't enable modules");
1867 break;
1868 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05301869
1870 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08001871 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
1872 hdd_err("HDD IPA UC reinit failed");
1873 goto close;
1874 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05301875 }
1876
Arun Khandavallifae92942016-08-01 13:31:08 +05301877 /* Fall through dont add break here */
1878 case DRIVER_MODULES_OPENED:
1879 if (!adapter) {
1880 hdd_alert("adapter is Null");
1881 goto close;
1882 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05301883 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
1884 hdd_err("in ftm mode, no need to configure cds modules");
1885 break;
1886 }
Arun Khandavallifae92942016-08-01 13:31:08 +05301887 if (hdd_configure_cds(hdd_ctx, adapter)) {
1888 hdd_err("Failed to Enable cds modules");
1889 goto close;
1890 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05301891 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05301892 hdd_info("Driver Modules Successfully Enabled");
1893 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
1894 break;
1895 case DRIVER_MODULES_ENABLED:
1896 hdd_info("Driver modules already Enabled");
1897 break;
1898 default:
1899 hdd_err("WLAN start invoked in wrong state! :%d\n",
1900 hdd_ctx->driver_status);
1901 goto release_lock;
1902 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301903 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05301904 mutex_unlock(&hdd_ctx->iface_change_lock);
1905 EXIT();
1906 return 0;
1907
1908close:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301909 cds_close(hdd_ctx->hdd_psoc, p_cds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05301910
Selvaraj, Sridhara7dc2382017-01-27 18:29:39 +05301911destroy_psoc_object:
1912 hdd_release_and_destroy_psoc(hdd_ctx);
1913
Arun Khandavallifae92942016-08-01 13:31:08 +05301914ol_cds_free:
1915 ol_cds_free();
1916
1917hif_close:
1918 hdd_hif_close(p_cds_context->pHIFContext);
1919power_down:
1920 if (!reinit && !unint)
1921 pld_power_off(qdf_dev->dev);
1922release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301923 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05301924 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301925 EXIT();
Arun Khandavallifae92942016-08-01 13:31:08 +05301926 return -EINVAL;
1927}
1928
1929/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 * __hdd_open() - HDD Open function
1931 * @dev: Pointer to net_device structure
1932 *
1933 * This is called in response to ifconfig up
1934 *
1935 * Return: 0 for success; non-zero for failure
1936 */
1937static int __hdd_open(struct net_device *dev)
1938{
1939 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1940 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1941 int ret;
1942
Jeff Johnson3c3994a2016-02-11 08:12:30 -08001943 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301944 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05301945 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946
1947 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301948 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001949 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001951
Arun Khandavallifae92942016-08-01 13:31:08 +05301952 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1953 if (ret) {
1954 hdd_err("Failed to start WLAN modules return");
1955 return -ret;
1956 }
1957
1958
1959 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1960 ret = hdd_start_adapter(adapter);
1961 if (ret) {
1962 hdd_err("Failed to start adapter :%d",
1963 adapter->device_mode);
1964 return ret;
1965 }
1966 }
1967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001968 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1969 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Arun Khandavallifae92942016-08-01 13:31:08 +05301970 hdd_info("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001971 /* Enable TX queues only when we are connected */
1972 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05301973 WLAN_START_ALL_NETIF_QUEUE,
1974 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001975 }
1976
Naveen Rawat286def52016-09-23 15:38:02 -07001977 /* Enable carrier and transmit queues for NDI */
1978 if (WLAN_HDD_IS_NDI(adapter)) {
1979 hdd_notice("Enabling Tx Queues");
1980 wlan_hdd_netif_queue_control(adapter,
1981 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
1982 WLAN_CONTROL_PATH);
1983 }
1984
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001985 return ret;
1986}
1987
Arun Khandavallifae92942016-08-01 13:31:08 +05301988
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989/**
1990 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
1991 * @dev: Pointer to net_device structure
1992 *
1993 * This is called in response to ifconfig up
1994 *
1995 * Return: 0 for success; non-zero for failure
1996 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001997static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998{
1999 int ret;
2000
2001 cds_ssr_protect(__func__);
2002 ret = __hdd_open(dev);
2003 cds_ssr_unprotect(__func__);
2004
2005 return ret;
2006}
2007
2008/**
2009 * __hdd_stop() - HDD stop function
2010 * @dev: Pointer to net_device structure
2011 *
2012 * This is called in response to ifconfig down
2013 *
2014 * Return: 0 for success; non-zero for failure
2015 */
2016static int __hdd_stop(struct net_device *dev)
2017{
2018 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2019 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavallifae92942016-08-01 13:31:08 +05302020 hdd_adapter_list_node_t *adapternode = NULL, *next = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002021 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302022 bool close_modules = true;
2023 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002025 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002026
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302027 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 adapter->sessionId, adapter->device_mode));
2029
2030 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302031 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002032 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002033
2034 /* Nothing to be done if the interface is not opened */
2035 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002036 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037 return -ENODEV;
2038 }
2039
2040 /* Make sure the interface is marked as closed */
2041 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Jeff Johnson1346fab2016-08-15 13:09:42 -07002042 hdd_notice("Disabling OS Tx queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002043
2044 /*
2045 * Disable TX on the interface, after this hard_start_xmit() will not
2046 * be called on that interface
2047 */
Jeff Johnson1346fab2016-08-15 13:09:42 -07002048 hdd_notice("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002049 wlan_hdd_netif_queue_control(adapter, WLAN_NETIF_TX_DISABLE_N_CARRIER,
2050 WLAN_CONTROL_PATH);
2051
2052 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002053 * NAN data interface is different in some sense. The traffic on NDI is
2054 * bursty in nature and depends on the need to transfer. The service
2055 * layer may down the interface after the usage and up again when
2056 * required. In some sense, the NDI is expected to be available
2057 * (like SAP) iface until NDI delete request is issued by the service
2058 * layer. Skip BSS termination and adapter deletion for NAN Data
2059 * interface (NDI).
2060 */
2061 if (WLAN_HDD_IS_NDI(adapter))
2062 return 0;
2063
2064 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 * The interface is marked as down for outside world (aka kernel)
2066 * But the driver is pretty much alive inside. The driver needs to
2067 * tear down the existing connection on the netdev (session)
2068 * cleanup the data pipes and wait until the control plane is stabilized
2069 * for this interface. The call also needs to wait until the above
2070 * mentioned actions are completed before returning to the caller.
2071 * Notice that the hdd_stop_adapter is requested not to close the session
2072 * That is intentional to be able to scan if it is a STA/P2P interface
2073 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302074 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002075
2076 /* DeInit the adapter. This ensures datapath cleanup as well */
2077 hdd_deinit_adapter(hdd_ctx, adapter, true);
2078
Arun Khandavallifae92942016-08-01 13:31:08 +05302079
2080 /*
2081 * Find if any iface is up. If any iface is up then can't put device to
2082 * sleep/power save mode
2083 */
2084 status = hdd_get_front_adapter(hdd_ctx, &adapternode);
2085 while ((NULL != adapternode) && (QDF_STATUS_SUCCESS == status)) {
2086 if (test_bit(DEVICE_IFACE_OPENED,
2087 &adapternode->pAdapter->event_flags)) {
2088 hdd_info("Still other ifaces are up cannot close modules");
2089 close_modules = false;
2090 break;
2091 }
2092 status = hdd_get_next_adapter(hdd_ctx, adapternode, &next);
2093 adapternode = next;
2094
2095 }
2096
2097 if (close_modules) {
2098 hdd_info("Closing all modules from the hdd_stop");
2099 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
2100 hdd_ctx->config->iface_change_wait_time
2101 * 50000);
2102 }
2103
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104 EXIT();
2105 return 0;
2106}
2107
2108/**
2109 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2110 * @dev: pointer to net_device structure
2111 *
2112 * This is called in response to ifconfig down
2113 *
2114 * Return: 0 for success and error number for failure
2115 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002116static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117{
2118 int ret;
2119
2120 cds_ssr_protect(__func__);
2121 ret = __hdd_stop(dev);
2122 cds_ssr_unprotect(__func__);
2123
2124 return ret;
2125}
2126
2127/**
2128 * __hdd_uninit() - HDD uninit function
2129 * @dev: Pointer to net_device structure
2130 *
2131 * This is called during the netdev unregister to uninitialize all data
2132 * associated with the device
2133 *
2134 * Return: None
2135 */
2136static void __hdd_uninit(struct net_device *dev)
2137{
2138 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2139
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002140 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002141
2142 do {
2143 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002144 hdd_alert("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 break;
2146 }
2147
2148 if (NULL == adapter->pHddCtx) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002149 hdd_alert("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002150 break;
2151 }
2152
2153 if (dev != adapter->dev) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002154 hdd_alert("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002155 /*
2156 * we haven't validated all cases so let this go for
2157 * now
2158 */
2159 }
2160
2161 hdd_deinit_adapter(adapter->pHddCtx, adapter, true);
2162
2163 /* after uninit our adapter structure will no longer be valid */
2164 adapter->dev = NULL;
2165 adapter->magic = 0;
2166 } while (0);
2167
2168 EXIT();
2169}
2170
2171/**
2172 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2173 * @dev: pointer to net_device structure
2174 *
2175 * This is called during the netdev unregister to uninitialize all data
2176 * associated with the device
2177 *
2178 * Return: none
2179 */
2180static void hdd_uninit(struct net_device *dev)
2181{
2182 cds_ssr_protect(__func__);
2183 __hdd_uninit(dev);
2184 cds_ssr_unprotect(__func__);
2185}
2186
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002187static int hdd_open_cesium_nl_sock(void)
2188{
2189#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2190 struct netlink_kernel_cfg cfg = {
2191 .groups = WLAN_NLINK_MCAST_GRP_ID,
2192 .input = NULL
2193 };
2194#endif
2195 int ret = 0;
2196
2197#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2198 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2199#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2200 THIS_MODULE,
2201#endif
2202 &cfg);
2203#else
2204 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2205 WLAN_NLINK_MCAST_GRP_ID,
2206 NULL, NULL, THIS_MODULE);
2207#endif
2208
2209 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002210 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002211 ret = -ECONNREFUSED;
2212 }
2213
2214 return ret;
2215}
2216
2217static void hdd_close_cesium_nl_sock(void)
2218{
2219 if (NULL != cesium_nl_srv_sock) {
2220 netlink_kernel_release(cesium_nl_srv_sock);
2221 cesium_nl_srv_sock = NULL;
2222 }
2223}
2224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002225/**
2226 * __hdd_set_mac_address() - set the user specified mac address
2227 * @dev: Pointer to the net device.
2228 * @addr: Pointer to the sockaddr.
2229 *
2230 * This function sets the user specified mac address using
2231 * the command ifconfig wlanX hw ether <mac adress>.
2232 *
2233 * Return: 0 for success, non zero for failure
2234 */
2235static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2236{
2237 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2238 hdd_context_t *hdd_ctx;
2239 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302240 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241 int ret;
2242
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002243 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002244
2245 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2246 ret = wlan_hdd_validate_context(hdd_ctx);
2247 if (0 != ret)
2248 return ret;
2249
2250 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2251 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2252
2253 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302254 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002255}
2256
2257/**
2258 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2259 * function from SSR
2260 * @dev: pointer to net_device structure
2261 * @addr: Pointer to the sockaddr
2262 *
2263 * This function sets the user specified mac address using
2264 * the command ifconfig wlanX hw ether <mac adress>.
2265 *
2266 * Return: 0 for success.
2267 */
2268static int hdd_set_mac_address(struct net_device *dev, void *addr)
2269{
2270 int ret;
2271
2272 cds_ssr_protect(__func__);
2273 ret = __hdd_set_mac_address(dev, addr);
2274 cds_ssr_unprotect(__func__);
2275
2276 return ret;
2277}
2278
2279uint8_t *wlan_hdd_get_intf_addr(hdd_context_t *hdd_ctx)
2280{
2281 int i;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302282 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002283 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2284 break;
2285 }
2286
Anurag Chouhan6d760662016-02-20 16:05:43 +05302287 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002288 return NULL;
2289
2290 hdd_ctx->config->intfAddrMask |= (1 << i);
2291 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2292}
2293
2294void wlan_hdd_release_intf_addr(hdd_context_t *hdd_ctx, uint8_t *releaseAddr)
2295{
2296 int i;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302297 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002298 if (!memcmp(releaseAddr,
2299 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2300 6)) {
2301 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2302 break;
2303 }
2304 }
2305 return;
2306}
2307
2308#ifdef WLAN_FEATURE_PACKET_FILTERING
2309/**
2310 * __hdd_set_multicast_list() - set the multicast address list
2311 * @dev: Pointer to the WLAN device.
2312 * @skb: Pointer to OS packet (sk_buff).
2313 *
2314 * This funciton sets the multicast address list.
2315 *
2316 * Return: None
2317 */
2318static void __hdd_set_multicast_list(struct net_device *dev)
2319{
2320 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002321 int i = 0, status;
2322 struct netdev_hw_addr *ha;
2323 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302324 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2325 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2326 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002327
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002328 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302329 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302330 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302331
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002332 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302333 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302334 goto out;
2335
2336 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2337 if (!mc_list_request) {
2338 hdd_notice("Cannot allocate mc_list_request");
2339 goto out;
2340 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002341
2342 if (dev->flags & IFF_ALLMULTI) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002343 hdd_notice("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302344 hdd_disable_and_flush_mc_addr_list(adapter,
2345 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002346 } else {
2347 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302348 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Dustin Brown61269462016-09-19 13:25:45 -07002349 hdd_notice("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302350 pmo_ucfg_max_mc_addr_supported(psoc));
2351 hdd_disable_and_flush_mc_addr_list(adapter,
2352 pmo_mc_list_change_notify);
2353 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002354 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002355 netdev_for_each_mc_addr(ha, dev) {
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302356 hdd_notice("ha_addr[%d] "MAC_ADDRESS_STR,
2357 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002358 if (i == mc_count)
2359 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302360 memset(&(mc_list_request->mc_addr[i].bytes),
2361 0, ETH_ALEN);
2362 memcpy(&(mc_list_request->mc_addr[i].bytes),
2363 ha->addr, ETH_ALEN);
2364 hdd_info("mlist[%d] = %pM", i,
2365 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002366 i++;
2367 }
2368 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302369
2370 mc_list_request->psoc = psoc;
2371 mc_list_request->vdev_id = adapter->sessionId;
2372 mc_list_request->count = mc_count;
2373 status = hdd_cache_mc_addr_list(mc_list_request);
2374 if (status == 0) {
2375 hdd_enable_mc_addr_filtering(adapter,
2376 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002377 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302378 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002379 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302380out:
2381 if (mc_list_request)
2382 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302383 EXIT();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302384
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002385}
2386
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002388/**
2389 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2390 * @dev: pointer to net_device
2391 *
2392 * Return: none
2393 */
2394static void hdd_set_multicast_list(struct net_device *dev)
2395{
2396 cds_ssr_protect(__func__);
2397 __hdd_set_multicast_list(dev);
2398 cds_ssr_unprotect(__func__);
2399}
2400#endif
2401
2402/**
2403 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2404 * @dev: Pointer to the WLAN device.
2405 * @skb: Pointer to OS packet (sk_buff).
2406 *
2407 * This function is registered with the Linux OS for network
2408 * core to decide which queue to use first.
2409 *
2410 * Return: ac, Queue Index/access category corresponding to UP in IP header
2411 */
2412static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2413#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2414 , void *accel_priv
2415#endif
2416#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2417 , select_queue_fallback_t fallback
2418#endif
2419)
2420{
2421 return hdd_wmm_select_queue(dev, skb);
2422}
2423
2424static struct net_device_ops wlan_drv_ops = {
2425 .ndo_open = hdd_open,
2426 .ndo_stop = hdd_stop,
2427 .ndo_uninit = hdd_uninit,
2428 .ndo_start_xmit = hdd_hard_start_xmit,
2429 .ndo_tx_timeout = hdd_tx_timeout,
2430 .ndo_get_stats = hdd_get_stats,
2431 .ndo_do_ioctl = hdd_ioctl,
2432 .ndo_set_mac_address = hdd_set_mac_address,
2433 .ndo_select_queue = hdd_select_queue,
2434#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002435 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002436#endif
2437};
2438
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002439/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
2440static struct net_device_ops wlan_mon_drv_ops = {
2441 .ndo_open = hdd_mon_open,
2442 .ndo_stop = hdd_stop,
2443 .ndo_get_stats = hdd_get_stats,
2444};
2445
2446/**
2447 * hdd_set_station_ops() - update net_device ops for monitor mode
2448 * @pWlanDev: Handle to struct net_device to be updated.
2449 * Return: None
2450 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002451void hdd_set_station_ops(struct net_device *pWlanDev)
2452{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002453 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2454 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2455 else
2456 pWlanDev->netdev_ops = &wlan_drv_ops;
2457}
2458
Komal Seelama89be8d2016-09-29 11:09:26 +05302459#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302460/**
2461 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2462 * @hdd_ctx: HDD context
2463 *
2464 * Return: None
2465 */
2466static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx)
2467{
2468 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2469
2470 ctx->scan = qdf_runtime_lock_init("scan");
Komal Seelamaa75f262016-09-29 12:32:13 +05302471 ctx->roc = qdf_runtime_lock_init("roc");
Komal Seelam81cb1662016-09-29 12:39:08 +05302472 ctx->dfs = qdf_runtime_lock_init("dfs");
Komal Seelam8634b772016-09-29 12:12:24 +05302473}
2474
2475/**
2476 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2477 * @hdd_ctx: HDD Context
2478 *
2479 * Return: None
2480 */
2481static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx)
2482{
2483 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2484
2485 qdf_runtime_lock_deinit(ctx->scan);
2486 ctx->scan = NULL;
Komal Seelamaa75f262016-09-29 12:32:13 +05302487 qdf_runtime_lock_deinit(ctx->roc);
2488 ctx->roc = NULL;
Komal Seelam81cb1662016-09-29 12:39:08 +05302489 qdf_runtime_lock_deinit(ctx->dfs);
2490 ctx->dfs = NULL;
Komal Seelam8634b772016-09-29 12:12:24 +05302491}
2492
Komal Seelama89be8d2016-09-29 11:09:26 +05302493static void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter)
2494{
2495 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2496
2497 ctx->connect = qdf_runtime_lock_init("connect");
2498}
2499
2500static void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter)
2501{
2502 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2503
2504 qdf_runtime_lock_deinit(ctx->connect);
2505 ctx->connect = NULL;
2506}
2507#else /* FEATURE_RUNTIME_PM */
Komal Seelam8634b772016-09-29 12:12:24 +05302508static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx) {}
2509static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302510static inline void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter) {}
2511static inline void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter) {}
2512#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002513/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002514 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2515 * @hdd_ctx: global hdd context
2516 * @macAddr: mac address to assign to the interface
2517 * @name: User-visible name of the interface
2518 *
2519 * hdd adapter pointer would point to the netdev->priv space, this function
2520 * would retrive the pointer, and setup the hdd adapter configuration.
2521 *
2522 * Return: the pointer to hdd adapter, otherwise NULL
2523 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002524static hdd_adapter_t *hdd_alloc_station_adapter(hdd_context_t *hdd_ctx,
2525 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002526 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002527 const char *name)
2528{
2529 struct net_device *pWlanDev = NULL;
2530 hdd_adapter_t *adapter = NULL;
2531 /*
2532 * cfg80211 initialization and registration....
2533 */
Ryan Hsu07495ea2016-01-21 15:25:39 -08002534 pWlanDev = alloc_netdev_mq(sizeof(hdd_adapter_t), name,
2535#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
2536 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002537#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002538 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
2539 hdd_mon_mode_ether_setup : ether_setup),
2540 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002541
2542 if (pWlanDev != NULL) {
2543
2544 /* Save the pointer to the net_device in the HDD adapter */
2545 adapter = (hdd_adapter_t *) netdev_priv(pWlanDev);
2546
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302547 qdf_mem_zero(adapter, sizeof(hdd_adapter_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548
2549 adapter->dev = pWlanDev;
2550 adapter->pHddCtx = hdd_ctx;
2551 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05302552 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002553
2554 init_completion(&adapter->session_open_comp_var);
2555 init_completion(&adapter->session_close_comp_var);
2556 init_completion(&adapter->disconnect_comp_var);
2557 init_completion(&adapter->linkup_event_var);
2558 init_completion(&adapter->cancel_rem_on_chan_var);
2559 init_completion(&adapter->rem_on_chan_ready_event);
2560 init_completion(&adapter->sta_authorized_event);
2561 init_completion(&adapter->offchannel_tx_event);
2562 init_completion(&adapter->tx_action_cnf_event);
2563#ifdef FEATURE_WLAN_TDLS
2564 init_completion(&adapter->tdls_add_station_comp);
2565 init_completion(&adapter->tdls_del_station_comp);
2566 init_completion(&adapter->tdls_mgmt_comp);
2567 init_completion(&adapter->tdls_link_establish_req_comp);
2568#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002569 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002570 init_completion(&adapter->change_country_code);
2571
2572
2573 init_completion(&adapter->scan_info.abortscan_event_var);
2574
2575 adapter->offloads_configured = false;
2576 adapter->isLinkUpSvcNeeded = false;
2577 adapter->higherDtimTransition = true;
2578 /* Init the net_device structure */
2579 strlcpy(pWlanDev->name, name, IFNAMSIZ);
2580
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302581 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002582 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302583 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002584 sizeof(tSirMacAddr));
2585 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002586
2587 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
2588 pWlanDev->features |=
2589 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2590 pWlanDev->features |= NETIF_F_RXCSUM;
2591
Dhanashri Atre83d373d2015-07-28 16:45:59 -07002592 hdd_set_tso_flags(hdd_ctx, pWlanDev);
2593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002594 hdd_set_station_ops(adapter->dev);
2595
2596 pWlanDev->destructor = free_netdev;
2597 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08002598 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002599 adapter->wdev.wiphy = hdd_ctx->wiphy;
2600 adapter->wdev.netdev = pWlanDev;
2601 /* set pWlanDev's parent to underlying device */
2602 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
2603 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05302604 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002605 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05302606 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002607 }
2608
2609 return adapter;
2610}
2611
Jeff Johnson590e2012016-10-05 16:16:24 -07002612static QDF_STATUS hdd_register_interface(hdd_adapter_t *adapter,
2613 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614{
2615 struct net_device *pWlanDev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002616
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08002617 if (rtnl_held) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002618 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
2619 if (dev_alloc_name(pWlanDev, pWlanDev->name) < 0) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002620 hdd_err("Failed:dev_alloc_name");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302621 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002622 }
2623 }
2624 if (register_netdevice(pWlanDev)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002625 hdd_err("Failed:register_netdev");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302626 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002627 }
2628 } else {
2629 if (register_netdev(pWlanDev)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002630 hdd_err("Failed:register_netdev");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302631 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002632 }
2633 }
2634 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
2635
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302636 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002637}
2638
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002639QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002640{
2641 hdd_adapter_t *adapter = pContext;
2642
2643 if (NULL == adapter) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002644 hdd_alert("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302645 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002646 }
2647
2648 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002649 hdd_alert("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302650 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002651 }
2652
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07002653 /*
2654 * For NAN Data interface, the close session results in the final
2655 * indication to the userspace
2656 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07002657 if (adapter->device_mode == QDF_NDI_MODE)
2658 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07002659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002660 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
2661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002662 /*
2663 * We can be blocked while waiting for scheduled work to be
2664 * flushed, and the adapter structure can potentially be freed, in
2665 * which case the magic will have been reset. So make sure the
2666 * magic is still good, and hence the adapter structure is still
2667 * valid, before signaling completion
2668 */
2669 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
2670 complete(&adapter->session_close_comp_var);
2671
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302672 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002673}
2674
Krunal Soni8c37e322016-02-03 16:08:37 -08002675/**
2676 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
2677 * @adapter: pointer to device adapter
2678 * @type: type of interface
2679 *
2680 * This routine will check the mode of adapter and if it is required then it
2681 * will initialize the TDLS operations
2682 *
2683 * Return: QDF_STATUS
2684 */
2685#ifdef FEATURE_WLAN_TDLS
2686static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter, uint32_t type)
2687{
2688 if (QDF_IBSS_MODE != type) {
2689 if (0 != wlan_hdd_tdls_init(adapter)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002690 hdd_err("wlan_hdd_tdls_init failed");
Krunal Soni8c37e322016-02-03 16:08:37 -08002691 return QDF_STATUS_E_FAILURE;
2692 }
2693 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
2694 }
2695 return QDF_STATUS_SUCCESS;
2696}
2697#else
2698static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter, uint32_t type)
2699{
2700 return QDF_STATUS_SUCCESS;
2701}
2702#endif
2703
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302704QDF_STATUS hdd_init_station_mode(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705{
2706 struct net_device *pWlanDev = adapter->dev;
2707 hdd_station_ctx_t *pHddStaCtx = &adapter->sessionCtx.station;
2708 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302709 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302710 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711 uint32_t type, subType;
2712 unsigned long rc;
2713 int ret_val;
2714
2715 INIT_COMPLETION(adapter->session_open_comp_var);
2716 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07002717 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002718 status = cds_get_vdev_types(adapter->device_mode, &type, &subType);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302719 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002720 hdd_err("failed to get vdev type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002721 goto error_sme_open;
2722 }
2723 /* Open a SME session for future operation */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302724 qdf_ret_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002725 sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
2726 (uint8_t *) &adapter->macAddressCurrent,
2727 &adapter->sessionId, type, subType);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302728 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002729 hdd_alert("sme_open_session() failed, status code %08d [x%08x]",
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302730 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302731 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002732 goto error_sme_open;
2733 }
2734 /* Block on a completion variable. Can't wait forever though. */
2735 rc = wait_for_completion_timeout(
2736 &adapter->session_open_comp_var,
2737 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
2738 if (!rc) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002739 hdd_alert("Session is not opened within timeout period code %ld",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 rc);
Sandeep Puligillae8065992016-11-14 00:23:43 -08002741 adapter->sessionId = HDD_SESSION_ID_INVALID;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302742 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743 }
2744
Rajeev Kumardeabf3e2017-01-13 15:55:05 -08002745 ret_val = hdd_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
2746 if (ret_val)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302747 goto error_vdev_create;
2748
Naveen Rawata410c5a2016-09-19 14:22:33 -07002749 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002750 /* Register wireless extensions */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302751 qdf_ret_status = hdd_register_wext(pWlanDev);
2752 if (QDF_STATUS_SUCCESS != qdf_ret_status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002753 hdd_alert("hdd_register_wext() failed, status code %08d [x%08x]",
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302754 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302755 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756 goto error_register_wext;
2757 }
2758 /* Set the Connection State to Not Connected */
Jeff Johnson1346fab2016-08-15 13:09:42 -07002759 hdd_notice("Set HDD connState to eConnectionState_NotConnected");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002760 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
2761
Deepak Dhamdherea2785822016-11-17 01:17:45 -08002762 /* set fast roaming capability in sme session */
2763 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
2764 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002765 /* Set the default operation channel */
2766 pHddStaCtx->conn_info.operationChannel =
2767 hdd_ctx->config->OperatingChannel;
2768
2769 /* Make the default Auth Type as OPEN */
2770 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2771
2772 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302773 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002774 hdd_alert("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002775 status, status);
2776 goto error_init_txrx;
2777 }
2778
2779 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2780
2781 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302782 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002783 hdd_alert("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002784 status, status);
2785 goto error_wmm_init;
2786 }
2787
2788 set_bit(WMM_INIT_DONE, &adapter->event_flags);
2789
2790 ret_val = wma_cli_set_command(adapter->sessionId,
2791 WMI_PDEV_PARAM_BURST_ENABLE,
2792 hdd_ctx->config->enableSifsBurst,
2793 PDEV_CMD);
2794
2795 if (0 != ret_val) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002796 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002797 ret_val);
2798 }
Krunal Soni8c37e322016-02-03 16:08:37 -08002799 status = hdd_check_and_init_tdls(adapter, type);
2800 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002802
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05302803 status = hdd_lro_enable(hdd_ctx, adapter);
2804 if (status != QDF_STATUS_SUCCESS)
2805 goto error_lro_enable;
2806
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302807 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002808
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05302809error_lro_enable:
2810 wlan_hdd_tdls_exit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811error_tdls_init:
2812 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
2813 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814error_wmm_init:
2815 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2816 hdd_deinit_tx_rx(adapter);
2817error_init_txrx:
2818 hdd_unregister_wext(pWlanDev);
2819error_register_wext:
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08002820 ret_val = hdd_release_and_destroy_vdev(adapter);
2821 if (ret_val)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302822 hdd_err("vdev delete failed");
2823error_vdev_create:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2825 INIT_COMPLETION(adapter->session_close_comp_var);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302826 if (QDF_STATUS_SUCCESS == sme_close_session(hdd_ctx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827 adapter->sessionId,
2828 hdd_sme_close_session_callback,
2829 adapter)) {
2830 unsigned long rc;
2831
2832 /*
2833 * Block on a completion variable.
2834 * Can't wait forever though.
2835 */
2836 rc = wait_for_completion_timeout(
2837 &adapter->session_close_comp_var,
2838 msecs_to_jiffies
2839 (WLAN_WAIT_TIME_SESSIONOPENCLOSE));
2840 if (rc <= 0)
Jeff Johnson1346fab2016-08-15 13:09:42 -07002841 hdd_err("Session is not opened within timeout period code %ld",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002842 rc);
2843 }
2844 }
2845error_sme_open:
2846 return status;
2847}
2848
2849void hdd_cleanup_actionframe(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
2850{
2851 hdd_cfg80211_state_t *cfgState;
2852
2853 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
2854
2855 if (NULL != cfgState->buf) {
2856 unsigned long rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002857 rc = wait_for_completion_timeout(
2858 &adapter->tx_action_cnf_event,
2859 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
2860 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07002861 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05302862 /*
2863 * Inform tx status as FAILURE to upper layer and free
2864 * cfgState->buf
2865 */
2866 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867 }
2868 }
2869 return;
2870}
2871
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302872/**
2873 * hdd_station_adapter_deinit() - De-initialize the station adapter
2874 * @hdd_ctx: global hdd context
2875 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07002876 * @rtnl_held: Used to indicate whether or not the caller is holding
2877 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302878 *
2879 * This function De-initializes the STA/P2P/OCB adapter.
2880 *
2881 * Return: None.
2882 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002883static void hdd_station_adapter_deinit(hdd_context_t *hdd_ctx,
2884 hdd_adapter_t *adapter,
2885 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302886{
2887 ENTER_DEV(adapter->dev);
2888
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05302889 if (adapter->dev) {
2890 if (rtnl_held)
2891 adapter->dev->wireless_handlers = NULL;
2892 else {
2893 rtnl_lock();
2894 adapter->dev->wireless_handlers = NULL;
2895 rtnl_unlock();
2896 }
2897 }
2898
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302899 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
2900 hdd_deinit_tx_rx(adapter);
2901 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2902 }
2903
2904 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
2905 hdd_wmm_adapter_close(adapter);
2906 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
2907 }
2908
2909 hdd_cleanup_actionframe(hdd_ctx, adapter);
2910 wlan_hdd_tdls_exit(adapter);
2911
2912 EXIT();
2913}
2914
2915/**
2916 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
2917 * @hdd_ctx: global hdd context
2918 * @adapter: HDD adapter
2919 * @rtnl_held: the rtnl lock hold flag
2920 * This function De-initializes the AP/P2PGo adapter.
2921 *
2922 * Return: None.
2923 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002924static void hdd_ap_adapter_deinit(hdd_context_t *hdd_ctx,
2925 hdd_adapter_t *adapter,
2926 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302927{
2928 ENTER_DEV(adapter->dev);
2929
2930 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
2931 hdd_wmm_adapter_close(adapter);
2932 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
2933 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04002934 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302935
2936 hdd_cleanup_actionframe(hdd_ctx, adapter);
2937
2938 hdd_unregister_hostapd(adapter, rtnl_held);
2939
2940 EXIT();
2941}
2942
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002943void hdd_deinit_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
2944 bool rtnl_held)
2945{
2946 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302947
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08002949 case QDF_STA_MODE:
2950 case QDF_P2P_CLIENT_MODE:
2951 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002952 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05302953 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002954 break;
2955 }
2956
Krunal Soni9b04c9b2016-03-10 13:08:05 -08002957 case QDF_SAP_MODE:
2958 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002959 {
2960
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302961 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002962 break;
2963 }
2964
2965 default:
2966 break;
2967 }
2968
2969 EXIT();
2970}
2971
Jeff Johnson590e2012016-10-05 16:16:24 -07002972static void hdd_cleanup_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
2973 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002974{
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08002975 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976 struct net_device *pWlanDev = NULL;
2977
2978 if (adapter)
2979 pWlanDev = adapter->dev;
2980 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07002981 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982 return;
2983 }
2984
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08002985 ret = hdd_release_and_destroy_vdev(adapter);
2986 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302987 hdd_err("vdev delete failed");
2988
Rajeev Kumardca5f812016-02-04 17:28:06 -08002989 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05302990
2991 if (adapter->scan_info.default_scan_ies) {
2992 qdf_mem_free(adapter->scan_info.default_scan_ies);
2993 adapter->scan_info.default_scan_ies = NULL;
2994 }
2995
Komal Seelama89be8d2016-09-29 11:09:26 +05302996 hdd_adapter_runtime_suspend_denit(adapter);
2997
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002998 /*
2999 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3000 * the driver is almost closed and cannot handle either control
3001 * messages or data. However, unregister_netdevice() call above will
3002 * eventually invoke hdd_stop (ndo_close) driver callback, which attempts
3003 * to close the active connections (basically excites control path) which
3004 * is not right. Setting this flag helps hdd_stop() to recognize that
3005 * the interface is closed and restricts any operations on that
3006 */
3007 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3008
3009 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
3010 if (rtnl_held) {
3011 unregister_netdevice(pWlanDev);
3012 } else {
3013 unregister_netdev(pWlanDev);
3014 }
3015 /*
3016 * Note that the adapter is no longer valid at this point
3017 * since the memory has been reclaimed
3018 */
3019 }
3020}
3021
Jeff Johnson590e2012016-10-05 16:16:24 -07003022static QDF_STATUS hdd_check_for_existing_macaddr(hdd_context_t *hdd_ctx,
3023 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003024{
3025 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
3026 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303027 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003028 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303029 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030 adapter = adapterNode->pAdapter;
3031 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303032 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003033 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303034 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003035 }
3036 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3037 adapterNode = pNext;
3038 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303039 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003041
Arun Khandavalli2358d522016-05-16 18:05:37 +05303042#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3043/**
3044 * hdd_set_fw_log_params() - Set log parameters to FW
3045 * @hdd_ctx: HDD Context
3046 * @adapter: HDD Adapter
3047 *
3048 * This function set the FW Debug log level based on the INI.
3049 *
3050 * Return: None
3051 */
3052static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3053 hdd_adapter_t *adapter)
3054{
3055 uint8_t count = 0, numentries = 0,
3056 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3057 uint32_t value = 0;
3058 int ret;
3059
Arun Khandavallifae92942016-08-01 13:31:08 +05303060 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3061 (!hdd_ctx->config->enable_fw_log)) {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303062 hdd_info("enable_fw_log not enabled in INI or in FTM mode return");
3063 return;
3064 }
3065
Arun Khandavallifae92942016-08-01 13:31:08 +05303066 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303067 hdd_ctx->fw_log_settings.dl_type =
3068 hdd_ctx->config->enableFwLogType;
3069 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303070 WMI_DBGLOG_TYPE,
3071 hdd_ctx->config->enableFwLogType,
3072 DBG_CMD);
3073 if (ret != 0)
3074 hdd_err("Failed to enable FW log type ret %d",
3075 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303076
3077 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303078 hdd_ctx->config->enableFwLogLevel;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303079 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303080 WMI_DBGLOG_LOG_LEVEL,
3081 hdd_ctx->config->enableFwLogLevel,
3082 DBG_CMD);
3083 if (ret != 0)
3084 hdd_err("Failed to enable FW log level ret %d",
3085 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303086
3087 hdd_string_to_u8_array(
3088 hdd_ctx->config->enableFwModuleLogLevel,
3089 moduleloglevel,
3090 &numentries,
3091 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3092
3093 while (count < numentries) {
3094 /*
3095 * FW module log level input string looks like
3096 * below:
3097 * gFwDebugModuleLoglevel=<FW Module ID>,
3098 * <Log Level>,...
3099 * For example:
3100 * gFwDebugModuleLoglevel=
3101 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3102 * Above input string means :
3103 * For FW module ID 1 enable log level 0
3104 * For FW module ID 2 enable log level 1
3105 * For FW module ID 3 enable log level 2
3106 * For FW module ID 4 enable log level 3
3107 * For FW module ID 5 enable log level 4
3108 * For FW module ID 6 enable log level 5
3109 * For FW module ID 7 enable log level 6
3110 */
3111
Nishank Aggarwale239d962017-03-03 12:26:02 +05303112 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3113 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3114 hdd_err("Module id %d and dbglog level %d input length is more than max",
3115 moduleloglevel[count],
3116 moduleloglevel[count + 1]);
3117 return;
3118 }
3119
3120 value = moduleloglevel[count] << 16;
3121 value |= moduleloglevel[count + 1];
Arun Khandavalli2358d522016-05-16 18:05:37 +05303122 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303123 WMI_DBGLOG_MOD_LOG_LEVEL,
3124 value, DBG_CMD);
3125 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303126 hdd_err("Failed to enable FW module log level %d ret %d",
3127 value, ret);
3128
3129 count += 2;
3130 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303131
Arun Khandavalli2358d522016-05-16 18:05:37 +05303132}
3133#else
3134static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3135 hdd_adapter_t *adapter)
3136{
3137}
3138
3139#endif
3140
3141/**
3142 * hdd_set_fw_params() - Set parameters to firmware
3143 * @adapter: HDD adapter
3144 *
3145 * This function Sets various parameters to fw once the
3146 * adapter is started.
3147 *
3148 * Return: 0 on success or errno on failure
3149 */
3150int hdd_set_fw_params(hdd_adapter_t *adapter)
3151{
3152 int ret;
3153 hdd_context_t *hdd_ctx;
3154
3155 ENTER_DEV(adapter->dev);
3156
3157 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3158 if (!hdd_ctx)
3159 return -EINVAL;
3160
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003161 if ((cds_get_conparam() != QDF_GLOBAL_FTM_MODE) &&
Arun Khandavallifae92942016-08-01 13:31:08 +05303162 (!hdd_ctx->config->enable2x2)) {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303163#define HDD_DTIM_1CHAIN_RX_ID 0x5
3164#define HDD_SMPS_PARAM_VALUE_S 29
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003165 /*
3166 * Disable DTIM 1 chain Rx when in 1x1,
3167 * we are passing two value
3168 * as param_id << 29 | param_value.
3169 * Below param_value = 0(disable)
3170 */
3171 ret = wma_cli_set_command(adapter->sessionId,
3172 WMI_STA_SMPS_PARAM_CMDID,
3173 HDD_DTIM_1CHAIN_RX_ID <<
3174 HDD_SMPS_PARAM_VALUE_S,
3175 VDEV_CMD);
3176 if (ret) {
3177 hdd_err("DTIM 1 chain set failed %d", ret);
3178 goto error;
3179 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303180
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003181 ret = wma_cli_set_command(adapter->sessionId,
3182 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3183 hdd_ctx->config->txchainmask1x1,
3184 PDEV_CMD);
3185 if (ret) {
3186 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3187 ret);
3188 goto error;
3189 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303190
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003191 ret = wma_cli_set_command(adapter->sessionId,
3192 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3193 hdd_ctx->config->rxchainmask1x1,
3194 PDEV_CMD);
3195 if (ret) {
3196 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3197 ret);
3198 goto error;
3199 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303200#undef HDD_DTIM_1CHAIN_RX_ID
3201#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003202 } else {
3203 hdd_info("FTM Mode or 2x2 mode - Do not set 1x1 params");
3204 }
3205
Arun Khandavallifae92942016-08-01 13:31:08 +05303206 if (QDF_GLOBAL_FTM_MODE != cds_get_conparam()) {
3207 ret = wma_cli_set_command(adapter->sessionId,
3208 WMI_PDEV_PARAM_HYST_EN,
3209 hdd_ctx->config->enableMemDeepSleep,
3210 PDEV_CMD);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303211
Arun Khandavallifae92942016-08-01 13:31:08 +05303212 if (ret) {
3213 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d",
3214 ret);
3215 goto error;
3216 }
Rajeev Kumar Sirasanagandla2dab3ec2016-10-18 16:10:15 +05303217
3218 ret = wma_cli_set_command(adapter->sessionId,
3219 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3220 hdd_ctx->config->rts_profile,
3221 VDEV_CMD);
3222 if (ret) {
3223 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3224 goto error;
3225 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303226 }
3227
3228 hdd_set_fw_log_params(hdd_ctx, adapter);
3229
3230 EXIT();
3231 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303232
Arun Khandavalli2358d522016-05-16 18:05:37 +05303233error:
3234 return -EINVAL;
3235}
3236
Ryan Hsu07495ea2016-01-21 15:25:39 -08003237/**
3238 * hdd_open_adapter() - open and setup the hdd adatper
3239 * @hdd_ctx: global hdd context
3240 * @session_type: type of the interface to be created
3241 * @iface_name: User-visible name of the interface
3242 * @macAddr: MAC address to assign to the interface
3243 * @name_assign_type: the name of assign type of the netdev
3244 * @rtnl_held: the rtnl lock hold flag
3245 *
3246 * This function open and setup the hdd adpater according to the device
3247 * type request, assign the name, the mac address assigned, and then prepared
3248 * the hdd related parameters, queue, lock and ready to start.
3249 *
3250 * Return: the pointer of hdd adapter, otherwise NULL.
3251 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003252hdd_adapter_t *hdd_open_adapter(hdd_context_t *hdd_ctx, uint8_t session_type,
3253 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003254 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003255 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003256{
3257 hdd_adapter_t *adapter = NULL;
3258 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303259 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003260 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261
Arun Khandavallifae92942016-08-01 13:31:08 +05303262 hdd_info("iface(%s) type(%d)", iface_name, session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263
3264 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3265 /*
3266 * Max limit reached on the number of vdevs configured by the
3267 * host. Return error
3268 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303269 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3270 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 return NULL;
3272 }
3273
3274 if (macAddr == NULL) {
3275 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303276 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277 return NULL;
3278 }
3279 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303280 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303281 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3282 " already exists",
3283 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284 return NULL;
3285 }
3286
3287 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003288 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289 /* Reset locally administered bit if the device mode is STA */
3290 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3291 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003292 case QDF_P2P_CLIENT_MODE:
3293 case QDF_P2P_DEVICE_MODE:
3294 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003295 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303296 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003297 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3298 name_assign_type,
3299 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300
3301 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303302 hdd_err("failed to allocate adapter for session %d",
3303 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003304 return NULL;
3305 }
3306
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003307 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003309 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303311 else if (QDF_MONITOR_MODE == session_type)
3312 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003313 else
3314 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3315
3316 adapter->device_mode = session_type;
3317
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303318 if (QDF_NDI_MODE == session_type) {
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003319 status = hdd_init_nan_data_mode(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303320 if (QDF_STATUS_SUCCESS != status)
3321 goto err_free_netdev;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303322 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003323
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324 /*
3325 * Workqueue which gets scheduled in IPv4 notification
3326 * callback
3327 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3329 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003330
3331#ifdef WLAN_NS_OFFLOAD
3332 /*
3333 * Workqueue which gets scheduled in IPv6
3334 * notification callback.
3335 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3337 hdd_ipv6_notifier_work_queue);
3338#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303340 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303342 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003343 }
3344
3345 /* Stop the Interface TX queue. */
Arun Khandavallifae92942016-08-01 13:31:08 +05303346 hdd_info("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003347 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303348 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3349 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003350 break;
Arun Khandavallifae92942016-08-01 13:31:08 +05303351
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003353 case QDF_P2P_GO_MODE:
3354 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003355 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3356 name_assign_type,
3357 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003358 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303359 hdd_alert("failed to allocate adapter for session %d",
3360 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 return NULL;
3362 }
3363
3364 adapter->wdev.iftype =
3365 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003366 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003367 NL80211_IFTYPE_P2P_GO;
3368 adapter->device_mode = session_type;
3369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003370 status = hdd_register_hostapd(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303371 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003372 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3373 goto err_free_netdev;
3374 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303375 hdd_info("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003376 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303377 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3378 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303380 case QDF_FTM_MODE:
3381 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3382 name_assign_type,
3383 "wlan0");
3384 if (NULL == adapter) {
3385 hdd_err("Failed to allocate adapter for FTM mode");
3386 return NULL;
3387 }
3388 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3389 adapter->device_mode = session_type;
3390 status = hdd_register_interface(adapter, rtnl_held);
3391 if (QDF_STATUS_SUCCESS != status) {
3392 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3393 goto err_free_netdev;
3394 }
3395 /* Stop the Interface TX queue. */
3396 hdd_info("Disabling queues");
3397 wlan_hdd_netif_queue_control(adapter,
3398 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3399 WLAN_CONTROL_PATH);
3400 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401 default:
Arun Khandavallifae92942016-08-01 13:31:08 +05303402 hdd_alert("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303403 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 return NULL;
3405 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406
3407 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3408 mutex_init(&cfgState->remain_on_chan_ctx_lock);
3409
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303410 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411 /* Add it to the hdd's session list. */
3412 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303413 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003414 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303415 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 } else {
3417 pHddAdapterNode->pAdapter = adapter;
3418 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
3419 }
3420 }
3421
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303422 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423 if (NULL != adapter) {
3424 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
3425 adapter = NULL;
3426 }
3427 if (NULL != pHddAdapterNode) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303428 qdf_mem_free(pHddAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 }
3430 return NULL;
3431 }
3432
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303433 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003434 cds_set_concurrency_mode(session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435
3436 /* Initialize the WoWL service */
3437 if (!hdd_init_wowl(adapter)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003438 hdd_alert("hdd_init_wowl failed");
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303439 goto err_close_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 }
3441
3442 /* Adapter successfully added. Increment the vdev count */
3443 hdd_ctx->current_intf_count++;
3444
Jeff Johnson5880d792016-08-15 13:32:30 -07003445 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003446 hdd_ctx->current_intf_count);
3447
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003448 cds_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 }
3450
Rajeev Kumardca5f812016-02-04 17:28:06 -08003451 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
3452 hdd_err("Interface %s wow debug_fs init failed", iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453
3454 return adapter;
3455
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303456err_close_adapter:
3457 hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303460 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461
3462 return NULL;
3463}
3464
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303465QDF_STATUS hdd_close_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003466 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467{
3468 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303469 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003470
3471 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303472 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003473 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 status);
3475 return status;
3476 }
3477
3478 while (pCurrent->pAdapter != adapter) {
3479 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303480 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481 break;
3482
3483 pCurrent = pNext;
3484 }
3485 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303486 if (QDF_STATUS_SUCCESS == status) {
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05303487 hdd_info("wait for bus bw work to flush");
3488 cancel_work_sync(&hdd_ctx->bus_bw_work);
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003489 cds_clear_concurrency_mode(adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
3491
3492 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303493 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494 adapterNode = NULL;
3495
3496 /* Adapter removed. Decrement vdev count */
3497 if (hdd_ctx->current_intf_count != 0)
3498 hdd_ctx->current_intf_count--;
3499
3500 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303501 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303503
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303504 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003505}
3506
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003507/**
3508 * hdd_close_all_adapters - Close all open adapters
3509 * @hdd_ctx: Hdd context
3510 * rtnl_held: True if RTNL lock held
3511 *
3512 * Close all open adapters.
3513 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303514 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003515 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303516QDF_STATUS hdd_close_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003517{
3518 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303519 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520
3521 ENTER();
3522
3523 do {
3524 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303525 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303526 wlan_hdd_release_intf_addr(hdd_ctx,
3527 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003529 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303530 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303531 /* Adapter removed. Decrement vdev count */
3532 if (hdd_ctx->current_intf_count != 0)
3533 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303535 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536
3537 EXIT();
3538
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303539 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540}
3541
3542void wlan_hdd_reset_prob_rspies(hdd_adapter_t *pHostapdAdapter)
3543{
Anurag Chouhan6d760662016-02-20 16:05:43 +05303544 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003545 tSirUpdateIE updateIE;
3546 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003547 case QDF_STA_MODE:
3548 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003549 {
3550 hdd_station_ctx_t *pHddStaCtx =
3551 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003552 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553 break;
3554 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003555 case QDF_SAP_MODE:
3556 case QDF_P2P_GO_MODE:
3557 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003558 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003559 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560 break;
3561 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003562 case QDF_FTM_MODE:
3563 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564 default:
3565 /*
3566 * wlan_hdd_reset_prob_rspies should not have been called
3567 * for these kind of devices
3568 */
Jeff Johnson5880d792016-08-15 13:32:30 -07003569 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570 pHostapdAdapter->device_mode);
3571 return;
3572 }
3573
Anurag Chouhanc5548422016-02-24 18:33:27 +05303574 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003575 updateIE.smeSessionId = pHostapdAdapter->sessionId;
3576 updateIE.ieBufferlength = 0;
3577 updateIE.pAdditionIEBuffer = NULL;
3578 updateIE.append = true;
3579 updateIE.notify = false;
3580 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
3581 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303582 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003583 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 }
3585}
3586
Peng Xu66162de2016-02-11 17:01:20 -08003587/**
3588 * hdd_wait_for_sme_close_sesion() - Close and wait for SME session close
3589 * @hdd_ctx: HDD context which is already NULL validated
3590 * @adapter: HDD adapter which is already NULL validated
3591 *
3592 * Close the SME session and wait for its completion, if needed.
3593 *
3594 * Return: None
3595 */
3596static void hdd_wait_for_sme_close_sesion(hdd_context_t *hdd_ctx,
3597 hdd_adapter_t *adapter)
3598{
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08003599 int ret;
Peng Xu66162de2016-02-11 17:01:20 -08003600 unsigned long rc;
3601
3602 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3603 hdd_err("session is not opened:%d", adapter->sessionId);
3604 return;
3605 }
3606
3607 INIT_COMPLETION(adapter->session_close_comp_var);
3608 if (QDF_STATUS_SUCCESS ==
3609 sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3610 hdd_sme_close_session_callback,
3611 adapter)) {
3612 /*
3613 * Block on a completion variable. Can't wait
3614 * forever though.
3615 */
3616 rc = wait_for_completion_timeout(
3617 &adapter->session_close_comp_var,
3618 msecs_to_jiffies
3619 (WLAN_WAIT_TIME_SESSIONOPENCLOSE));
Sandeep Puligillaada72922016-09-29 19:31:21 -07003620 if (!rc) {
Peng Xu66162de2016-02-11 17:01:20 -08003621 hdd_err("failure waiting for session_close_comp_var");
Sandeep Puligillaada72922016-09-29 19:31:21 -07003622 if (adapter->device_mode == QDF_NDI_MODE)
3623 hdd_ndp_session_end_handler(adapter);
3624 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Hanumanth Reddy Pothula33702122016-10-07 17:27:04 +05303625 return;
Sandeep Puligillaada72922016-09-29 19:31:21 -07003626 }
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08003627 ret = hdd_release_and_destroy_vdev(adapter);
3628 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303629 hdd_err("vdev delete failed");
3630
Hanumanth Reddy Pothula33702122016-10-07 17:27:04 +05303631 adapter->sessionId = HDD_SESSION_ID_INVALID;
Peng Xu66162de2016-02-11 17:01:20 -08003632 }
3633}
3634
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303635QDF_STATUS hdd_stop_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636 const bool bCloseSession)
3637{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303638 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003639 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
3640 union iwreq_data wrqu;
3641 tSirUpdateIE updateIE;
3642 unsigned long rc;
Sachin Ahuja988fd102016-09-15 17:16:25 +05303643 hdd_scaninfo_t *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644
3645 ENTER();
3646
Sachin Ahuja988fd102016-09-15 17:16:25 +05303647 scan_info = &adapter->scan_info;
Jeff Johnson5880d792016-08-15 13:32:30 -07003648 hdd_notice("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 wlan_hdd_netif_queue_control(adapter, WLAN_NETIF_TX_DISABLE_N_CARRIER,
3650 WLAN_CONTROL_PATH);
3651 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003652 case QDF_STA_MODE:
3653 case QDF_P2P_CLIENT_MODE:
3654 case QDF_IBSS_MODE:
3655 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003656 case QDF_NDI_MODE:
3657 if ((QDF_NDI_MODE == adapter->device_mode) ||
3658 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
3660 hdd_is_connecting(
3661 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003662 INIT_COMPLETION(adapter->disconnect_comp_var);
3663 /*
3664 * For NDI do not use pWextState from sta_ctx, if needed
3665 * extract from ndi_ctx.
3666 */
3667 if (QDF_NDI_MODE == adapter->device_mode)
3668 qdf_ret_status = sme_roam_disconnect(
3669 hdd_ctx->hHal,
3670 adapter->sessionId,
3671 eCSR_DISCONNECT_REASON_NDI_DELETE);
3672 else if (pWextState->roamProfile.BSSType ==
3673 eCSR_BSS_TYPE_START_IBSS)
3674 qdf_ret_status = sme_roam_disconnect(
3675 hdd_ctx->hHal,
3676 adapter->sessionId,
3677 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003679 qdf_ret_status = sme_roam_disconnect(
3680 hdd_ctx->hHal,
3681 adapter->sessionId,
3682 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683 /* success implies disconnect command got queued up successfully */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303684 if (qdf_ret_status == QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003685 rc = wait_for_completion_timeout(
3686 &adapter->disconnect_comp_var,
3687 msecs_to_jiffies
3688 (WLAN_WAIT_TIME_DISCONNECT));
3689 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003690 hdd_err("wait on disconnect_comp_var failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003691 }
3692 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003693 hdd_err("failed to post disconnect event to SME");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694 }
3695 memset(&wrqu, '\0', sizeof(wrqu));
3696 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3697 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3698 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
3699 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05303700 }
3701 if (scan_info != NULL && scan_info->mScanPending) {
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05303702 wlan_hdd_scan_abort(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703 }
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05303704 hdd_lro_disable(hdd_ctx, adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05303705 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706
3707#ifdef WLAN_OPEN_SOURCE
3708 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
3709#endif
3710
3711 hdd_deregister_tx_flow_control(adapter);
3712
3713#ifdef WLAN_NS_OFFLOAD
3714#ifdef WLAN_OPEN_SOURCE
3715 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
3716#endif
3717#endif
3718
3719 /*
3720 * It is possible that the caller of this function does not
3721 * wish to close the session
3722 */
Krunal Soni985b8132017-02-10 18:49:08 -08003723 if (true == bCloseSession) {
3724 if (0 != wlan_hdd_try_disconnect(adapter)) {
3725 hdd_err("Error: Can't disconnect adapter");
3726 return QDF_STATUS_E_FAILURE;
3727 }
Peng Xu66162de2016-02-11 17:01:20 -08003728 hdd_wait_for_sme_close_sesion(hdd_ctx, adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08003729 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003730 break;
3731
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003732 case QDF_SAP_MODE:
3733 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734 if (hdd_ctx->config->conc_custom_rule1 &&
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003735 (QDF_SAP_MODE == adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003736 /*
3737 * Before stopping the sap adapter, lets make sure there
3738 * is no sap restart work pending.
3739 */
3740 cds_flush_work(&hdd_ctx->sap_start_work);
Jeff Johnson5880d792016-08-15 13:32:30 -07003741 hdd_info("Canceled the pending SAP restart work");
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003742 cds_change_sap_restart_required_status(false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003743 }
3744 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003745 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
3747
3748 hdd_deregister_tx_flow_control(adapter);
3749
3750 mutex_lock(&hdd_ctx->sap_lock);
3751 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303752 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05303753 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003754
3755 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756 status = wlansap_stop_bss(
3757 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303759 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760 hdd_hostapd_state_t *hostapd_state =
3761 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05303762 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303763 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05303764 qdf_status =
3765 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08003766 qdf_stop_bss_event,
3767 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003768
Anurag Chouhance0dc992016-02-16 18:18:03 +05303769 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003770 hdd_err("failure waiting for wlansap_stop_bss %d",
3771 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772 }
3773 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003774 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003775 }
3776 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003777 cds_decr_session_set_pcl(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 adapter->device_mode,
3779 adapter->sessionId);
3780
Anurag Chouhanc5548422016-02-24 18:33:27 +05303781 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003782 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783 updateIE.smeSessionId = adapter->sessionId;
3784 updateIE.ieBufferlength = 0;
3785 updateIE.pAdditionIEBuffer = NULL;
3786 updateIE.append = false;
3787 updateIE.notify = false;
3788 /* Probe bcn reset */
3789 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
3790 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303791 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003792 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003793 }
3794 /* Assoc resp reset */
3795 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
3796 &updateIE,
3797 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303798 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003799 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003800 }
3801 /* Reset WNI_CFG_PROBE_RSP Flags */
3802 wlan_hdd_reset_prob_rspies(adapter);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303803 qdf_mem_free(adapter->sessionCtx.ap.beacon);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003804 adapter->sessionCtx.ap.beacon = NULL;
3805 }
3806 mutex_unlock(&hdd_ctx->sap_lock);
Peng Xu66162de2016-02-11 17:01:20 -08003807 if (true == bCloseSession)
3808 hdd_wait_for_sme_close_sesion(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003809 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003810 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08003811 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003812 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07003813 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003814 break;
3815 default:
3816 break;
3817 }
3818
3819 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303820 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003821}
3822
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05303823/**
3824 * hdd_deinit_all_adapters - deinit all adapters
3825 * @hdd_ctx: HDD context
3826 * @rtnl_held: True if RTNL lock held
3827 *
3828 */
3829void hdd_deinit_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
3830{
3831 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3832 QDF_STATUS status;
3833 hdd_adapter_t *adapter;
3834
3835 ENTER();
3836
3837 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3838
3839 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3840 adapter = adapter_node->pAdapter;
3841 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3842 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
3843 adapter_node = next;
3844 }
3845
3846 EXIT();
3847}
3848
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303849QDF_STATUS hdd_stop_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850{
3851 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303852 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853 hdd_adapter_t *adapter;
3854
3855 ENTER();
3856
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303857 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
3858
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003859 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
3860
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303861 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 adapter = adapterNode->pAdapter;
3863 hdd_stop_adapter(hdd_ctx, adapter, true);
3864 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3865 adapterNode = pNext;
3866 }
3867
3868 EXIT();
3869
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303870 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003871}
3872
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303873QDF_STATUS hdd_reset_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003874{
3875 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303876 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003877 hdd_adapter_t *adapter;
3878
3879 ENTER();
3880
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303881 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
3882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
3884
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303885 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 adapter = adapterNode->pAdapter;
Jeff Johnson5880d792016-08-15 13:32:30 -07003887 hdd_notice("Disabling queues");
Arun Khandavallicc544b32017-01-30 19:52:16 +05303888 if (hdd_ctx->config->sap_internal_restart &&
3889 adapter->device_mode == QDF_SAP_MODE) {
3890 wlan_hdd_netif_queue_control(adapter,
3891 WLAN_NETIF_TX_DISABLE,
3892 WLAN_CONTROL_PATH);
3893 hdd_sap_indicate_disconnect_for_sta(adapter);
3894 hdd_cleanup_actionframe(hdd_ctx, adapter);
3895 hdd_sap_destroy_events(adapter);
3896 } else
3897 wlan_hdd_netif_queue_control(adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003898 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3899 WLAN_CONTROL_PATH);
3900
3901 adapter->sessionCtx.station.hdd_ReassocScenario = false;
3902
3903 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyya4adb3682016-01-07 15:07:12 -08003904 cds_decr_session_set_pcl(adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003905 adapter->sessionId);
3906 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3907 hdd_wmm_adapter_close(adapter);
3908 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3909 }
3910
Wu Gao36717432016-11-21 15:09:48 +08003911 /*
3912 * If adapter is SAP, set session ID to invalid since SAP
3913 * session will be cleanup during SSR.
3914 */
3915 if (adapter->device_mode == QDF_SAP_MODE)
3916 wlansap_set_invalid_session(
3917 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
3918
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3920 adapterNode = pNext;
3921 }
3922
3923 EXIT();
3924
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303925 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926}
3927
Arun Khandavallifae92942016-08-01 13:31:08 +05303928/**
3929 * hdd_is_interface_up()- Checkfor interface up before ssr
3930 * @hdd_ctx: HDD context
3931 *
3932 * check if there are any wlan interfaces before SSR accordingly start
3933 * the interface.
3934 *
3935 * Return: 0 if interface was opened else false
3936 */
3937static bool hdd_is_interface_up(hdd_adapter_t *adapter)
3938{
3939 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
3940 return true;
3941 else
3942 return false;
3943}
3944
Anurag Chouhanc4092922016-09-08 15:56:11 +05303945#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
Abhishek Singhb5e38ef2017-01-02 12:09:34 +05303946 && !defined(WITH_BACKPORTS)
Anurag Chouhanc4092922016-09-08 15:56:11 +05303947struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
3948 struct ieee80211_channel *channel,
3949 const u8 *bssid, const u8 *ssid,
3950 size_t ssid_len)
3951{
3952 return cfg80211_get_bss(wiphy, channel, bssid,
3953 ssid, ssid_len,
3954 WLAN_CAPABILITY_ESS,
3955 WLAN_CAPABILITY_ESS);
3956}
3957#else
3958struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
3959 struct ieee80211_channel *channel,
3960 const u8 *bssid, const u8 *ssid,
3961 size_t ssid_len)
3962{
3963 return cfg80211_get_bss(wiphy, channel, bssid,
3964 ssid, ssid_len,
3965 IEEE80211_BSS_TYPE_ESS,
3966 IEEE80211_PRIVACY_ANY);
3967}
3968#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05303969
Abhishek Singha84d3952016-09-13 13:45:05 +05303970#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05303971#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
3972 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
3973/**
3974 * hdd_convert_timeout_reason() - Convert to kernel specific enum
3975 * @timeout_reason: reason for connect timeout
3976 *
3977 * This function is used to convert host timeout
3978 * reason enum to kernel specific enum.
3979 *
3980 * Return: nl timeout enum
3981 */
3982static enum nl80211_timeout_reason hdd_convert_timeout_reason(
3983 tSirResultCodes timeout_reason)
3984{
3985 switch (timeout_reason) {
3986 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
3987 return NL80211_TIMEOUT_SCAN;
3988 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
3989 return NL80211_TIMEOUT_AUTH;
3990 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
3991 return NL80211_TIMEOUT_ASSOC;
3992 default:
3993 return NL80211_TIMEOUT_UNSPECIFIED;
3994 }
3995}
3996
3997/**
3998 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
3999 * @dev: network device
4000 * @bssid: bssid to which we want to associate
4001 * @timeout_reason: reason for connect timeout
4002 *
4003 * This API is used to send connection timeout reason to supplicant
4004 *
4005 * Return: void
4006 */
4007static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4008 const u8 *bssid,
4009 tSirResultCodes timeout_reason)
4010{
4011 enum nl80211_timeout_reason nl_timeout_reason;
4012 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4013
4014 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4015 nl_timeout_reason);
4016}
4017
4018/**
4019 * __hdd_connect_bss() - API to send connection status to supplicant
4020 * @dev: network device
4021 * @bssid: bssid to which we want to associate
4022 * @req_ie: Request Information Element
4023 * @req_ie_len: len of the req IE
4024 * @resp_ie: Response IE
4025 * @resp_ie_len: len of ht response IE
4026 * @status: status
4027 * @gfp: Kernel Flag
4028 * @timeout_reason: reason for connect timeout
4029 *
4030 * Return: void
4031 */
4032static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4033 struct cfg80211_bss *bss, const u8 *req_ie,
4034 size_t req_ie_len, const u8 *resp_ie,
4035 size_t resp_ie_len, int status, gfp_t gfp,
4036 tSirResultCodes timeout_reason)
4037{
4038 enum nl80211_timeout_reason nl_timeout_reason;
4039 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4040
4041 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4042 resp_ie, resp_ie_len, status, gfp,
4043 nl_timeout_reason);
4044}
4045#else
4046#if defined CFG80211_CONNECT_TIMEOUT
4047static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4048 const u8 *bssid,
4049 tSirResultCodes timeout_reason)
4050{
4051 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4052}
4053#endif
4054
4055static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4056 struct cfg80211_bss *bss, const u8 *req_ie,
4057 size_t req_ie_len, const u8 *resp_ie,
4058 size_t resp_ie_len, int status, gfp_t gfp,
4059 tSirResultCodes timeout_reason)
4060{
4061 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4062 resp_ie, resp_ie_len, status, gfp);
4063}
4064#endif
4065
Abhishek Singha84d3952016-09-13 13:45:05 +05304066/**
4067 * hdd_connect_bss() - API to send connection status to supplicant
4068 * @dev: network device
4069 * @bssid: bssid to which we want to associate
4070 * @req_ie: Request Information Element
4071 * @req_ie_len: len of the req IE
4072 * @resp_ie: Response IE
4073 * @resp_ie_len: len of ht response IE
4074 * @status: status
4075 * @gfp: Kernel Flag
4076 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304077 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304078 *
4079 * The API is a wrapper to send connection status to supplicant
4080 *
4081 * Return: Void
4082 */
4083#if defined CFG80211_CONNECT_TIMEOUT
4084static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4085 struct cfg80211_bss *bss, const u8 *req_ie,
4086 size_t req_ie_len, const u8 *resp_ie,
4087 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304088 bool connect_timeout,
4089 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304090{
4091 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304092 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304093 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304094 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4095 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304096}
4097#else
4098static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4099 struct cfg80211_bss *bss, const u8 *req_ie,
4100 size_t req_ie_len, const u8 *resp_ie,
4101 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304102 bool connect_timeout,
4103 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304104{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304105 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4106 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304107}
4108#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304109
4110/**
4111 * hdd_connect_result() - API to send connection status to supplicant
4112 * @dev: network device
4113 * @bssid: bssid to which we want to associate
4114 * @roam_info: information about connected bss
4115 * @req_ie: Request Information Element
4116 * @req_ie_len: len of the req IE
4117 * @resp_ie: Response IE
4118 * @resp_ie_len: len of ht response IE
4119 * @status: status
4120 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304121 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304122 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304123 *
4124 * The API is a wrapper to send connection status to supplicant
4125 * and allow runtime suspend
4126 *
4127 * Return: Void
4128 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304129void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4130 tCsrRoamInfo *roam_info, const u8 *req_ie,
4131 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304132 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304133 bool connect_timeout,
4134 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304135{
4136 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4137 struct cfg80211_bss *bss = NULL;
4138
4139 if (WLAN_STATUS_SUCCESS == status) {
4140 struct ieee80211_channel *chan;
4141 int freq;
4142 int chan_no = roam_info->pBssDesc->channelId;
4143
4144 if (chan_no <= 14)
4145 freq = ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -07004146 NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304147 else
4148 freq = ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -07004149 NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304150
4151 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4152 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4153 roam_info->u.pConnectedProfile->SSID.ssId,
4154 roam_info->u.pConnectedProfile->SSID.length);
4155 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304156
Abhishek Singha84d3952016-09-13 13:45:05 +05304157 hdd_connect_bss(dev, bssid, bss, req_ie,
4158 req_ie_len, resp_ie, resp_ie_len,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304159 status, gfp, connect_timeout, timeout_reason);
Komal Seelama89be8d2016-09-29 11:09:26 +05304160
4161 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304162}
4163#else
4164void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4165 tCsrRoamInfo *roam_info, const u8 *req_ie,
4166 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304167 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304168 bool connect_timeout,
4169 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304170{
Komal Seelama89be8d2016-09-29 11:09:26 +05304171 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4172
Anurag Chouhanc4092922016-09-08 15:56:11 +05304173 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4174 resp_ie, resp_ie_len, status, gfp);
Komal Seelama89be8d2016-09-29 11:09:26 +05304175 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304176}
4177#endif
4178
4179
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304180QDF_STATUS hdd_start_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181{
4182 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304183 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184 hdd_adapter_t *adapter;
4185#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05304186 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187#endif
4188 eConnectionState connState;
4189
4190 ENTER();
4191
4192 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304193 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 adapter = adapterNode->pAdapter;
4195
Arun Khandavallifae92942016-08-01 13:31:08 +05304196 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304197 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05304198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004199 hdd_wmm_init(adapter);
4200
4201 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004202 case QDF_STA_MODE:
4203 case QDF_P2P_CLIENT_MODE:
4204 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205
4206 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
4207 ->conn_info.connState;
4208
4209 hdd_init_station_mode(adapter);
4210 /* Open the gates for HDD to receive Wext commands */
4211 adapter->isLinkUpSvcNeeded = false;
4212 adapter->scan_info.mScanPending = false;
4213
4214 /* Indicate disconnect event to supplicant if associated previously */
4215 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07004216 eConnectionState_IbssConnected == connState ||
4217 eConnectionState_NotConnected == connState ||
4218 eConnectionState_IbssDisconnected == connState ||
4219 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220 union iwreq_data wrqu;
4221 memset(&wrqu, '\0', sizeof(wrqu));
4222 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4223 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4224 wireless_send_event(adapter->dev, SIOCGIWAP,
4225 &wrqu, NULL);
4226 adapter->sessionCtx.station.
4227 hdd_ReassocScenario = false;
4228
4229 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05304230 wlan_hdd_cfg80211_indicate_disconnect(
4231 adapter->dev, false,
4232 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004233 } else if (eConnectionState_Connecting == connState) {
4234 /*
4235 * Indicate connect failure to supplicant if we were in the
4236 * process of connecting
4237 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304238 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304239 NULL, 0, NULL, 0,
4240 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
4241 GFP_KERNEL, false,
4242 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243 }
4244
4245 hdd_register_tx_flow_control(adapter,
4246 hdd_tx_resume_timer_expired_handler,
4247 hdd_tx_resume_cb);
4248
4249 break;
4250
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004251 case QDF_SAP_MODE:
Arun Khandavallicc544b32017-01-30 19:52:16 +05304252 if (hdd_ctx->config->sap_internal_restart)
4253 hdd_init_ap_mode(adapter, true);
4254
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004255 break;
4256
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004257 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004258#ifdef MSM_PLATFORM
Jeff Johnson5880d792016-08-15 13:32:30 -07004259 hdd_err("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
4261#else
Jeff Johnson5880d792016-08-15 13:32:30 -07004262 hdd_err("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004263 /* event supplicant to restart */
4264 cfg80211_del_sta(adapter->dev,
4265 (const u8 *)&bcastMac.bytes[0],
4266 GFP_KERNEL);
4267#endif
4268 break;
4269
4270 default:
4271 break;
4272 }
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304273get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4275 adapterNode = pNext;
4276 }
4277
4278 EXIT();
4279
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304280 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004281}
4282
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304283QDF_STATUS hdd_get_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284 hdd_adapter_list_node_t **padapterNode)
4285{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304286 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004287 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304288 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
4289 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004290 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 return status;
4292}
4293
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304294QDF_STATUS hdd_get_next_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295 hdd_adapter_list_node_t *adapterNode,
4296 hdd_adapter_list_node_t **pNextAdapterNode)
4297{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304298 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004299 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304300 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
4301 (qdf_list_node_t *) adapterNode,
4302 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004304 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305 return status;
4306}
4307
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304308QDF_STATUS hdd_remove_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309 hdd_adapter_list_node_t *adapterNode)
4310{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304311 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004312 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304313 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004315 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316 return status;
4317}
4318
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304319QDF_STATUS hdd_remove_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004320 hdd_adapter_list_node_t **padapterNode)
4321{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304322 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004323 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304324 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
4325 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004326 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 return status;
4328}
4329
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304330QDF_STATUS hdd_add_adapter_back(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 hdd_adapter_list_node_t *adapterNode)
4332{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304333 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004334 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304335 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
4336 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004337 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338 return status;
4339}
4340
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304341QDF_STATUS hdd_add_adapter_front(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004342 hdd_adapter_list_node_t *adapterNode)
4343{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304344 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004345 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304346 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
4347 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004348 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349 return status;
4350}
4351
4352hdd_adapter_t *hdd_get_adapter_by_macaddr(hdd_context_t *hdd_ctx,
4353 tSirMacAddr macAddr)
4354{
4355 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4356 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304357 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358
4359 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4360
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304361 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362 adapter = adapterNode->pAdapter;
4363
4364 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304365 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366 macAddr, sizeof(tSirMacAddr))) {
4367 return adapter;
4368 }
4369 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4370 adapterNode = pNext;
4371 }
4372
4373 return NULL;
4374
4375}
4376
4377hdd_adapter_t *hdd_get_adapter_by_vdev(hdd_context_t *hdd_ctx,
4378 uint32_t vdev_id)
4379{
4380 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4381 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304382 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304384 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304386 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004387 adapter = adapterNode->pAdapter;
4388
4389 if (adapter->sessionId == vdev_id)
4390 return adapter;
4391
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304392 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4394 adapterNode = pNext;
4395 }
4396
Jeff Johnson5880d792016-08-15 13:32:30 -07004397 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398
4399 return NULL;
4400}
4401
Abhishek Singh7996eb72015-12-30 17:24:02 +05304402/**
4403 * hdd_get_adapter_by_sme_session_id() - Return adapter with
4404 * the sessionid
4405 * @hdd_ctx: hdd context.
4406 * @sme_session_id: sme session is for the adapter to get.
4407 *
4408 * This function is used to get the adapter with provided session id
4409 *
4410 * Return: adapter pointer if found
4411 *
4412 */
4413hdd_adapter_t *hdd_get_adapter_by_sme_session_id(hdd_context_t *hdd_ctx,
4414 uint32_t sme_session_id)
4415{
4416 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4417 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304418 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05304419
4420
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304421 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05304422
4423 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304424 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05304425 adapter = adapter_node->pAdapter;
4426
4427 if (adapter &&
4428 adapter->sessionId == sme_session_id)
4429 return adapter;
4430
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304431 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05304432 hdd_get_next_adapter(hdd_ctx,
4433 adapter_node, &next);
4434 adapter_node = next;
4435 }
4436 return NULL;
4437}
4438
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004439/**
4440 * hdd_get_adapter() - to get adapter matching the mode
4441 * @hdd_ctx: hdd context
4442 * @mode: adapter mode
4443 *
4444 * This routine will return the pointer to adapter matching
4445 * with the passed mode.
4446 *
4447 * Return: pointer to adapter or null
4448 */
4449hdd_adapter_t *hdd_get_adapter(hdd_context_t *hdd_ctx,
4450 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451{
4452 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4453 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304454 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455
4456 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4457
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304458 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004459 adapter = adapterNode->pAdapter;
4460
4461 if (adapter && (mode == adapter->device_mode))
4462 return adapter;
4463
4464 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4465 adapterNode = pNext;
4466 }
4467
4468 return NULL;
4469
4470}
4471
4472/**
4473 * hdd_get_operating_channel() - return operating channel of the device mode
4474 * @hdd_ctx: Pointer to the HDD context.
4475 * @mode: Device mode for which operating channel is required.
4476 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004477 * QDF_STA_MODE,
4478 * QDF_P2P_CLIENT_MODE,
4479 * QDF_SAP_MODE,
4480 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481 *
4482 * This API returns the operating channel of the requested device mode
4483 *
4484 * Return: channel number. "0" id the requested device is not found OR it is
4485 * not connected.
4486 */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004487uint8_t hdd_get_operating_channel(hdd_context_t *hdd_ctx,
4488 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489{
4490 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304491 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004492 hdd_adapter_t *adapter;
4493 uint8_t operatingChannel = 0;
4494
4495 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4496
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304497 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004498 adapter = adapterNode->pAdapter;
4499
4500 if (mode == adapter->device_mode) {
4501 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004502 case QDF_STA_MODE:
4503 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504 if (hdd_conn_is_connected
4505 (WLAN_HDD_GET_STATION_CTX_PTR
4506 (adapter))) {
4507 operatingChannel =
4508 (WLAN_HDD_GET_STATION_CTX_PTR
4509 (adapter))->conn_info.
4510 operationChannel;
4511 }
4512 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004513 case QDF_SAP_MODE:
4514 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004515 /* softap connection info */
4516 if (test_bit
4517 (SOFTAP_BSS_STARTED,
4518 &adapter->event_flags))
4519 operatingChannel =
4520 (WLAN_HDD_GET_AP_CTX_PTR
4521 (adapter))->operatingChannel;
4522 break;
4523 default:
4524 break;
4525 }
4526
4527 break; /* Found the device of interest. break the loop */
4528 }
4529
4530 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4531 adapterNode = pNext;
4532 }
4533 return operatingChannel;
4534}
4535
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304536static inline QDF_STATUS hdd_unregister_wext_all_adapters(hdd_context_t *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537 hdd_ctx)
4538{
4539 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304540 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004541 hdd_adapter_t *adapter;
4542
4543 ENTER();
4544
4545 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4546
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304547 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004548 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004549 if ((adapter->device_mode == QDF_STA_MODE) ||
4550 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4551 (adapter->device_mode == QDF_IBSS_MODE) ||
4552 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4553 (adapter->device_mode == QDF_SAP_MODE) ||
4554 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004555 wlan_hdd_cfg80211_deregister_frames(adapter);
4556 hdd_unregister_wext(adapter->dev);
4557 }
4558 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4559 adapterNode = pNext;
4560 }
4561
4562 EXIT();
4563
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304564 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565}
4566
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304567QDF_STATUS hdd_abort_mac_scan_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568{
4569 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304570 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571 hdd_adapter_t *adapter;
4572
4573 ENTER();
4574
4575 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4576
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304577 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004578 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004579 if ((adapter->device_mode == QDF_STA_MODE) ||
4580 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4581 (adapter->device_mode == QDF_IBSS_MODE) ||
4582 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4583 (adapter->device_mode == QDF_SAP_MODE) ||
4584 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 hdd_abort_mac_scan(hdd_ctx, adapter->sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304586 INVALID_SCAN_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004587 eCSR_SCAN_ABORT_DEFAULT);
4588 }
4589 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4590 adapterNode = pNext;
4591 }
4592
4593 EXIT();
4594
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304595 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004596}
4597
Dustin Brownf27bce82016-11-03 12:52:27 -07004598/**
4599 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
4600 * adapters
4601 * @hdd_ctx: The HDD context containing the adapters to operate on
4602 *
4603 * return: QDF_STATUS_SUCCESS
4604 */
4605static QDF_STATUS hdd_abort_sched_scan_all_adapters(hdd_context_t *hdd_ctx)
4606{
4607 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
4608 QDF_STATUS status;
4609 hdd_adapter_t *adapter;
4610 int err;
4611
4612 ENTER();
4613
4614 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4615
4616 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4617 adapter = adapter_node->pAdapter;
4618 if ((adapter->device_mode == QDF_STA_MODE) ||
4619 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4620 (adapter->device_mode == QDF_IBSS_MODE) ||
4621 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4622 (adapter->device_mode == QDF_SAP_MODE) ||
4623 (adapter->device_mode == QDF_P2P_GO_MODE)) {
4624 err = wlan_hdd_sched_scan_stop(adapter->dev);
4625 if (err)
4626 hdd_err("Unable to stop scheduled scan");
4627 }
4628 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next_node);
4629 adapter_node = next_node;
4630 }
4631
4632 EXIT();
4633
4634 return QDF_STATUS_SUCCESS;
4635}
4636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637#ifdef WLAN_NS_OFFLOAD
4638/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004639 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004640 * @hdd_ctx: Pointer to hdd context
4641 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004642 * Unregister for IPv6 address change notifications.
4643 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 * Return: None
4645 */
4646static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
4647{
4648 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
4649
4650 return;
4651}
4652
4653/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004654 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 * @hdd_ctx: Pointer to hdd context
4656 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004657 * Register for IPv6 address change notifications.
4658 *
4659 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004661static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662{
4663 int ret;
4664
4665 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
4666 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004667 if (ret) {
4668 hdd_err("Failed to register IPv6 notifier: %d", ret);
4669 goto out;
4670 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004671
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004672 hdd_info("Registered IPv6 notifier");
4673out:
4674 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004675}
4676#else
4677/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004678 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679 * @hdd_ctx: Pointer to hdd context
4680 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004681 * Unregister for IPv6 address change notifications.
4682 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004683 * Return: None
4684 */
4685static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
4686{
4687}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004688
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004690 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004691 * @hdd_ctx: Pointer to hdd context
4692 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004693 * Register for IPv6 address change notifications.
4694 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004695 * Return: None
4696 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004697static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004698{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004699 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004700}
4701#endif
4702
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304703#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
4704/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004705 * hdd_logging_sock_activate_svc() - Activate logging
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304706 * @hdd_ctx: HDD context
4707 *
4708 * Activates the logging service
4709 *
4710 * Return: Zero in case of success, negative value otherwise
4711 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004712static int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304713{
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004714 int ret;
4715 struct hdd_config *config = hdd_ctx->config;
4716
4717 if (!config->wlanLoggingEnable)
4718 return 0;
4719
4720 ret = wlan_logging_sock_activate_svc(config->wlanLoggingFEToConsole,
4721 config->wlanLoggingNumBuf);
4722 if (ret)
4723 hdd_err("wlan_logging_sock_activate_svc failed: %d", ret);
4724 return ret;
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304725}
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004726
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304727/**
4728 * wlan_hdd_logging_sock_deactivate_svc() - Deactivate logging
4729 * @hdd_ctx: HDD context
4730 *
4731 * Deactivates the logging service
4732 *
4733 * Return: 0 on deactivating the logging service
4734 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004735static int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304736{
4737 if (hdd_ctx && hdd_ctx->config->wlanLoggingEnable)
4738 return wlan_logging_sock_deactivate_svc();
4739
4740 return 0;
4741}
4742#else
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004743static inline int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304744{
4745 return 0;
4746}
4747
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004748static inline int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304749{
4750 return 0;
4751}
4752#endif
4753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004755 * hdd_register_notifiers - Register netdev notifiers.
4756 * @hdd_ctx: HDD context
4757 *
4758 * Register netdev notifiers like IPv4 and IPv6.
4759 *
4760 * Return: 0 on success and errno on failure
4761 */
4762static int hdd_register_notifiers(hdd_context_t *hdd_ctx)
4763{
4764 int ret;
4765
4766 ret = register_netdevice_notifier(&hdd_netdev_notifier);
4767 if (ret) {
4768 hdd_err("register_netdevice_notifier failed: %d", ret);
4769 goto out;
4770 }
4771
4772 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
4773 if (ret)
4774 goto unregister_notifier;
4775
4776 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
4777 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
4778 if (ret) {
4779 hdd_err("Failed to register IPv4 notifier: %d", ret);
4780 goto unregister_ip6_notifier;
4781 }
4782
4783 return 0;
4784
4785unregister_ip6_notifier:
4786 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
4787unregister_notifier:
4788 unregister_netdevice_notifier(&hdd_netdev_notifier);
4789out:
4790 return ret;
4791
4792}
4793
4794/**
4795 * hdd_unregister_notifiers - Unregister netdev notifiers.
4796 * @hdd_ctx: HDD context
4797 *
4798 * Unregister netdev notifiers like IPv4 and IPv6.
4799 *
4800 * Return: None.
4801 */
4802static void hdd_unregister_notifiers(hdd_context_t *hdd_ctx)
4803{
4804 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
4805
4806 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
4807
4808 unregister_netdevice_notifier(&hdd_netdev_notifier);
4809}
4810
4811/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004812 * hdd_exit_netlink_services - Exit netlink services
4813 * @hdd_ctx: HDD context
4814 *
4815 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
4816 * nl service.
4817 *
4818 * Return: None.
4819 */
4820static void hdd_exit_netlink_services(hdd_context_t *hdd_ctx)
4821{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004822 hdd_close_cesium_nl_sock();
4823
4824 ptt_sock_deactivate_svc();
4825
4826 nl_srv_exit();
4827}
4828
4829/**
4830 * hdd_init_netlink_services- Init netlink services
4831 * @hdd_ctx: HDD context
4832 *
4833 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
4834 * nl service.
4835 *
4836 * Return: 0 on success and errno on failure.
4837 */
4838static int hdd_init_netlink_services(hdd_context_t *hdd_ctx)
4839{
4840 int ret;
4841
Ryan Hsuceddceb2016-04-28 10:20:14 -07004842 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004843 if (ret) {
4844 hdd_alert("nl_srv_init failed: %d", ret);
4845 goto out;
4846 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07004847 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004848
4849 ret = oem_activate_service(hdd_ctx);
4850 if (ret) {
4851 hdd_alert("oem_activate_service failed: %d", ret);
4852 goto err_nl_srv;
4853 }
4854
4855 ret = ptt_sock_activate_svc();
4856 if (ret) {
4857 hdd_alert("ptt_sock_activate_svc failed: %d", ret);
4858 goto err_nl_srv;
4859 }
4860
4861 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07004862 if (ret)
4863 hdd_warn("hdd_open_cesium_nl_sock failed");
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004864
4865 ret = cnss_diag_activate_service();
4866 if (ret) {
4867 hdd_alert("cnss_diag_activate_service failed: %d", ret);
4868 goto err_close_cesium;
4869 }
4870
4871 return 0;
4872
4873err_close_cesium:
4874 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004875 ptt_sock_deactivate_svc();
4876err_nl_srv:
4877 nl_srv_exit();
4878out:
4879 return ret;
4880}
4881
Prashanth Bhatta527fd752016-04-28 12:35:23 -07004882/**
4883 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
4884 * @hdd_ctx: HDD context.
4885 *
4886 * Destroy RX wakelock.
4887 *
4888 * Return: None.
4889 */
4890static void hdd_rx_wake_lock_destroy(hdd_context_t *hdd_ctx)
4891{
4892 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
4893}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004894
4895/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07004896 * hdd_rx_wake_lock_create() - Create RX wakelock
4897 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004898 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07004899 * Create RX wakelock.
4900 *
4901 * Return: None.
4902 */
4903static void hdd_rx_wake_lock_create(hdd_context_t *hdd_ctx)
4904{
4905 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
4906}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07004907
4908/**
4909 * hdd_roc_context_init() - Init ROC context
4910 * @hdd_ctx: HDD context.
4911 *
4912 * Initialize ROC context.
4913 *
4914 * Return: 0 on success and errno on failure.
4915 */
4916static int hdd_roc_context_init(hdd_context_t *hdd_ctx)
4917{
4918 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
4919 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
4920
4921 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
4922
4923 return 0;
4924}
4925
4926/**
4927 * hdd_roc_context_destroy() - Destroy ROC context
4928 * @hdd_ctx: HDD context.
4929 *
4930 * Destroy roc list and flush the pending roc work.
4931 *
4932 * Return: None.
4933 */
4934static void hdd_roc_context_destroy(hdd_context_t *hdd_ctx)
4935{
4936 flush_delayed_work(&hdd_ctx->roc_req_work);
4937 qdf_list_destroy(&hdd_ctx->hdd_roc_req_q);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08004938 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07004939}
4940
4941/**
Houston Hoffman160db392016-10-10 17:37:51 -07004942 * hdd_context_deinit() - Deinitialize HDD context
4943 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07004944 *
Houston Hoffman160db392016-10-10 17:37:51 -07004945 * Deinitialize HDD context along with all the feature specific contexts but
4946 * do not free hdd context itself. Caller of this API is supposed to free
4947 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004948 *
Houston Hoffman160db392016-10-10 17:37:51 -07004949 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004950 */
Houston Hoffman160db392016-10-10 17:37:51 -07004951static int hdd_context_deinit(hdd_context_t *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004952{
Houston Hoffman160db392016-10-10 17:37:51 -07004953 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004954
Prashanth Bhatta527fd752016-04-28 12:35:23 -07004955 hdd_roc_context_destroy(hdd_ctx);
4956
4957 hdd_sap_context_destroy(hdd_ctx);
4958
4959 hdd_rx_wake_lock_destroy(hdd_ctx);
4960
4961 hdd_tdls_context_destroy(hdd_ctx);
4962
4963 hdd_scan_context_destroy(hdd_ctx);
4964
4965 qdf_list_destroy(&hdd_ctx->hddAdapters);
4966
Houston Hoffman160db392016-10-10 17:37:51 -07004967 return 0;
4968}
4969
4970/**
4971 * hdd_context_destroy() - Destroy HDD context
4972 * @hdd_ctx: HDD context to be destroyed.
4973 *
4974 * Free config and HDD context as well as destroy all the resources.
4975 *
4976 * Return: None
4977 */
4978static void hdd_context_destroy(hdd_context_t *hdd_ctx)
4979{
4980 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
4981 hdd_logging_sock_deactivate_svc(hdd_ctx);
4982
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05304983 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
4984
Houston Hoffman160db392016-10-10 17:37:51 -07004985 hdd_context_deinit(hdd_ctx);
4986
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304987 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004988 hdd_ctx->config = NULL;
4989
4990 wiphy_free(hdd_ctx->wiphy);
4991}
4992
4993/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004994 * hdd_wlan_exit() - HDD WLAN exit function
4995 * @hdd_ctx: Pointer to the HDD Context
4996 *
4997 * This is the driver exit point (invoked during rmmod)
4998 *
4999 * Return: None
5000 */
Jeff Johnson590e2012016-10-05 16:16:24 -07005001static void hdd_wlan_exit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002{
5003 v_CONTEXT_t p_cds_context = hdd_ctx->pcds_context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305004 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305006 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005007
5008 ENTER();
5009
Arun Khandavallifae92942016-08-01 13:31:08 +05305010 if (QDF_TIMER_STATE_RUNNING ==
5011 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
5012 hdd_info("Stpp interface change timer");
5013 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014 }
5015
Arun Khandavallifae92942016-08-01 13:31:08 +05305016 if (!QDF_IS_STATUS_SUCCESS
5017 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5018 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005019
Arun Khandavallifae92942016-08-01 13:31:08 +05305020
5021 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022
Nitesh Shah61c10d92016-10-19 19:29:15 +05305023 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5024
Prashanth Bhattaab004382016-10-11 16:08:11 -07005025 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026
5027#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305028 if (QDF_TIMER_STATE_RUNNING ==
5029 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5030 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031 }
5032
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305033 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305034 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005035 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005036 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005037 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5038 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5039 hdd_ctx->last_acs_channel_list = NULL;
5040 hdd_ctx->num_of_channels = 0;
5041 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043
Arun Khandavallifae92942016-08-01 13:31:08 +05305044 mutex_lock(&hdd_ctx->iface_change_lock);
5045 driver_status = hdd_ctx->driver_status;
5046 mutex_unlock(&hdd_ctx->iface_change_lock);
5047
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005048 /*
5049 * Powersave Offload Case
5050 * Disable Idle Power Save Mode
5051 */
5052 hdd_set_idle_ps_config(hdd_ctx, false);
5053
Arun Khandavallifae92942016-08-01 13:31:08 +05305054 if (driver_status != DRIVER_MODULES_CLOSED) {
5055 hdd_unregister_wext_all_adapters(hdd_ctx);
5056 /*
5057 * Cancel any outstanding scan requests. We are about to close
5058 * all of our adapters, but an adapter structure is what SME
5059 * passes back to our callback function. Hence if there
5060 * are any outstanding scan requests then there is a
5061 * race condition between when the adapter is closed and
5062 * when the callback is invoked. We try to resolve that
5063 * race condition here by canceling any outstanding scans
5064 * before we close the adapters.
5065 * Note that the scans may be cancelled in an asynchronous
5066 * manner, so ideally there needs to be some kind of
5067 * synchronization. Rather than introduce a new
5068 * synchronization here, we will utilize the fact that we are
5069 * about to Request Full Power, and since that is synchronized,
5070 * the expectation is that by the time Request Full Power has
5071 * completed, all scans will be cancelled
5072 */
5073 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005074 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305075 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076 }
5077
5078 /*
5079 * Close the scheduler before calling cds_close to make sure no thread
5080 * is scheduled after the each module close is called i.e after all the
5081 * data structures are freed.
5082 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305083 qdf_status = cds_sched_close(p_cds_context);
5084 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005085 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305086 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305089 hdd_wlan_stop_modules(hdd_ctx);
5090
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305091 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5092 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5093 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5094
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005095 /*
5096 * Close CDS
5097 * This frees pMac(HAL) context. There should not be any call
5098 * that requires pMac access after this.
5099 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005101 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005102 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005103
Komal Seelam8634b772016-09-29 12:12:24 +05305104 hdd_runtime_suspend_context_deinit(hdd_ctx);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005105 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005106
5107 hdd_ipa_cleanup(hdd_ctx);
5108
5109 /* Free up RoC request queue and flush workqueue */
5110 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005111
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305112 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305113 wlan_hdd_deinit_chan_info(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005114 wiphy_unregister(wiphy);
Abhishek Singhf512bf32016-05-04 16:47:46 +05305115 wlan_hdd_cfg80211_deinit(wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005116
Jeff Johnsonf7f66f02016-09-23 14:50:11 -07005117 hdd_lpass_notify_stop(hdd_ctx);
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005118
Arun Khandavallifae92942016-08-01 13:31:08 +05305119 hdd_exit_netlink_services(hdd_ctx);
5120 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005121 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122}
5123
5124void __hdd_wlan_exit(void)
5125{
5126 hdd_context_t *hdd_ctx;
5127
5128 ENTER();
5129
Anurag Chouhan6d760662016-02-20 16:05:43 +05305130 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005131 if (!hdd_ctx) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005132 hdd_alert("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133 EXIT();
5134 return;
5135 }
5136
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005137 /* Check IPA HW Pipe shutdown */
5138 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
5139
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005140 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05305141 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005142
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 /* Do all the cleanup before deregistering the driver */
5144 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07005145
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005146 EXIT();
5147}
5148
5149#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04005150/**
5151 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
5152 * @data: pointer to hdd_context_t
5153 *
5154 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
5155 * Then new ACS request will do a fresh scan without reusing the cached
5156 * scan information.
5157 *
5158 * Return: void
5159 */
Tang Yingying523322d2017-01-17 23:28:43 +08005160static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005161{
5162 hdd_context_t *hdd_ctx = (hdd_context_t *) data;
5163
Jeff Johnson760350b2016-08-15 14:01:52 -07005164 hdd_notice("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04005166 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5167 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5168 hdd_ctx->last_acs_channel_list = NULL;
5169 hdd_ctx->num_of_channels = 0;
5170 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171
5172 if (!hdd_ctx->hHal)
5173 return;
5174 sme_scan_flush_result(hdd_ctx->hHal);
5175}
5176#endif
5177
5178#ifdef QCA_HT_2040_COEX
5179/**
5180 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
5181 * @adapter: pointer to adapter
5182 * @staId: station id
5183 * @macAddrSTA: station MAC address
5184 * @channel_type: channel type
5185 *
5186 * This function notifies FW with HT20/HT40 mode
5187 *
5188 * Return: 0 if successful, error number otherwise
5189 */
5190int hdd_wlan_set_ht2040_mode(hdd_adapter_t *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305191 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192{
5193 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305194 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005195 hdd_context_t *hdd_ctx = NULL;
5196
5197 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5198
5199 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305200 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005201 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 if (!hdd_ctx->hHal)
5204 return -EINVAL;
5205
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305206 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305208 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005209 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 return -EINVAL;
5211 }
5212
5213 return 0;
5214}
5215#endif
5216
5217/**
5218 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
5219 * @state: state
5220 *
5221 * This function notifies FW with modem power status
5222 *
5223 * Return: 0 if successful, error number otherwise
5224 */
5225int hdd_wlan_notify_modem_power_state(int state)
5226{
5227 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305228 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005229 hdd_context_t *hdd_ctx;
5230
Anurag Chouhan6d760662016-02-20 16:05:43 +05305231 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305233 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305235
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 if (!hdd_ctx->hHal)
5237 return -EINVAL;
5238
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305239 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
5240 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005241 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005242 state);
5243 return -EINVAL;
5244 }
5245 return 0;
5246}
5247
5248/**
5249 *
5250 * hdd_post_cds_enable_config() - HDD post cds start config helper
5251 * @adapter - Pointer to the HDD
5252 *
5253 * Return: None
5254 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305255QDF_STATUS hdd_post_cds_enable_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005256{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305257 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258
5259 /*
5260 * Send ready indication to the HDD. This will kick off the MAC
5261 * into a 'running' state and should kick off an initial scan.
5262 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305263 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
5264 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005265 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
5266 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305267 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 }
5269
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305270 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271}
5272
5273/* wake lock APIs for HDD */
5274void hdd_prevent_suspend(uint32_t reason)
5275{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305276 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277}
5278
5279void hdd_allow_suspend(uint32_t reason)
5280{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305281 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282}
5283
5284void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
5285{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05305286 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
5287 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005288}
5289
5290/**
5291 * hdd_exchange_version_and_caps() - exchange version and capability with target
5292 * @hdd_ctx: Pointer to HDD context
5293 *
5294 * This is the HDD function to exchange version and capability information
5295 * between Host and Target
5296 *
5297 * This function gets reported version of FW.
5298 * It also finds the version of target headers used to compile the host;
5299 * It compares the above two and prints a warning if they are different;
5300 * It gets the SW and HW version string;
5301 * Finally, it exchanges capabilities between host and target i.e. host
5302 * and target exchange a msg indicating the features they support through a
5303 * bitmap
5304 *
5305 * Return: None
5306 */
5307void hdd_exchange_version_and_caps(hdd_context_t *hdd_ctx)
5308{
5309
5310 tSirVersionType versionCompiled;
5311 tSirVersionType versionReported;
5312 tSirVersionString versionString;
5313 uint8_t fwFeatCapsMsgSupported = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305314 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315
5316 memset(&versionCompiled, 0, sizeof(versionCompiled));
5317 memset(&versionReported, 0, sizeof(versionReported));
5318
5319 /* retrieve and display WCNSS version information */
5320 do {
5321
5322 vstatus = sme_get_wcnss_wlan_compiled_version(hdd_ctx->hHal,
5323 &versionCompiled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305324 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005325 hdd_alert("unable to retrieve WCNSS WLAN compiled version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005326 break;
5327 }
5328
5329 vstatus = sme_get_wcnss_wlan_reported_version(hdd_ctx->hHal,
5330 &versionReported);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305331 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005332 hdd_alert("unable to retrieve WCNSS WLAN reported version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005333 break;
5334 }
5335
5336 if ((versionCompiled.major != versionReported.major) ||
5337 (versionCompiled.minor != versionReported.minor) ||
5338 (versionCompiled.version != versionReported.version) ||
5339 (versionCompiled.revision != versionReported.revision)) {
5340 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
5341 "Host expected %u.%u.%u.%u\n",
5342 WLAN_MODULE_NAME,
5343 (int)versionReported.major,
5344 (int)versionReported.minor,
5345 (int)versionReported.version,
5346 (int)versionReported.revision,
5347 (int)versionCompiled.major,
5348 (int)versionCompiled.minor,
5349 (int)versionCompiled.version,
5350 (int)versionCompiled.revision);
5351 } else {
5352 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
5353 WLAN_MODULE_NAME,
5354 (int)versionReported.major,
5355 (int)versionReported.minor,
5356 (int)versionReported.version,
5357 (int)versionReported.revision);
5358 }
5359
5360 vstatus = sme_get_wcnss_software_version(hdd_ctx->hHal,
5361 versionString,
5362 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305363 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005364 hdd_alert("unable to retrieve WCNSS software version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005365 break;
5366 }
5367
5368 pr_info("%s: WCNSS software version %s\n",
5369 WLAN_MODULE_NAME, versionString);
5370
5371 vstatus = sme_get_wcnss_hardware_version(hdd_ctx->hHal,
5372 versionString,
5373 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305374 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnsonb7082ae2016-08-23 13:13:30 -07005375 hdd_alert("unable to retrieve WCNSS hardware version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376 break;
5377 }
5378
5379 pr_info("%s: WCNSS hardware version %s\n",
5380 WLAN_MODULE_NAME, versionString);
5381
5382 /*
5383 * 1.Check if FW version is greater than 0.1.1.0. Only then
5384 * send host-FW capability exchange message
5385 * 2.Host-FW capability exchange message is only present on
5386 * target 1.1 so send the message only if it the target is 1.1
5387 * minor numbers for different target branches:
5388 * 0 -> (1.0)Mainline Build
5389 * 1 -> (1.1)Mainline Build
5390 * 2->(1.04) Stability Build
5391 */
5392 if (((versionReported.major > 0) || (versionReported.minor > 1)
5393 || ((versionReported.minor >= 1)
5394 && (versionReported.version >= 1)))
5395 && ((versionReported.major == 1)
5396 && (versionReported.minor >= 1)))
5397 fwFeatCapsMsgSupported = 1;
5398
5399 if (fwFeatCapsMsgSupported) {
5400 /*
5401 * Indicate if IBSS heartbeat monitoring needs to be
5402 * offloaded
5403 */
5404 if (!hdd_ctx->config->enableIbssHeartBeatOffload) {
5405 sme_disable_feature_capablity
5406 (IBSS_HEARTBEAT_OFFLOAD);
5407 }
5408
5409 sme_feature_caps_exchange(hdd_ctx->hHal);
5410 }
5411
5412 } while (0);
5413
5414}
5415
5416/* Initialize channel list in sme based on the country code */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305417QDF_STATUS hdd_set_sme_chan_list(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005418{
5419 return sme_init_chan_list(hdd_ctx->hHal, hdd_ctx->reg.alpha2,
5420 hdd_ctx->reg.cc_src);
5421}
5422
5423/**
5424 * hdd_is_5g_supported() - check if hardware supports 5GHz
5425 * @hdd_ctx: Pointer to the hdd context
5426 *
5427 * HDD function to know if hardware supports 5GHz
5428 *
5429 * Return: true if hardware supports 5GHz
5430 */
5431bool hdd_is_5g_supported(hdd_context_t *hdd_ctx)
5432{
zdingf54169a2016-10-12 17:08:45 +08005433 if (!hdd_ctx || !hdd_ctx->config)
5434 return true;
5435
5436 if (hdd_ctx->config->nBandCapability != eCSR_BAND_24)
5437 return true;
5438 else
5439 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005440}
5441
Amar Singhale4f28ee2015-10-21 14:36:56 -07005442static int hdd_wiphy_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005443{
5444 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07005445 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005446
5447 wiphy = hdd_ctx->wiphy;
5448
5449 /*
5450 * The channel information in
5451 * wiphy needs to be initialized before wiphy registration
5452 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07005453 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
5454 if (ret_val) {
5455 hdd_alert("regulatory init failed");
5456 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005457 }
5458
5459#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
5460 wiphy->wowlan = &wowlan_support_reg_init;
5461#else
5462 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
5463 WIPHY_WOWLAN_MAGIC_PKT |
5464 WIPHY_WOWLAN_DISCONNECT |
5465 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
5466 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
5467 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
5468 WIPHY_WOWLAN_4WAY_HANDSHAKE |
5469 WIPHY_WOWLAN_RFKILL_RELEASE;
5470
5471 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
5472 WOW_MAX_FILTERS_PER_LIST);
5473 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
5474 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
5475#endif
5476
5477 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07005478 ret_val = wlan_hdd_cfg80211_register(wiphy);
5479 if (0 > ret_val)
5480 hdd_err("wiphy registration failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005481
Amar Singhale4f28ee2015-10-21 14:36:56 -07005482 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005483}
5484
Ravi Joshie2331e82015-07-01 18:18:54 -07005485/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07005486 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07005487 * @hdd_ctx - handle to hdd context
5488 * @tx_packets - transmit packet count
5489 * @rx_packets - receive packet count
5490 *
5491 * The function controls the bus bandwidth and dynamic control of
5492 * tcp delayed ack configuration
5493 *
5494 * Returns: None
5495 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005496#ifdef MSM_PLATFORM
Jeff Johnson590e2012016-10-05 16:16:24 -07005497static void hdd_pld_request_bus_bandwidth(hdd_context_t *hdd_ctx,
5498 const uint64_t tx_packets,
5499 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005500{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005501 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08005502 uint64_t temp_rx = 0;
5503 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07005504 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08005505 enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
5506 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07005507 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005508
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005509 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005510 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005511 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005512 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07005513 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005514 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07005515 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07005516 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005517
Mohit Khannae71e2262015-11-10 09:37:24 -08005518 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].next_vote_level =
5519 next_vote_level;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005520
5521 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07005522 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
5523 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524 hdd_ctx->cur_vote_level = next_vote_level;
Yuanyuan Liu13738502016-04-06 17:41:37 -07005525 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05305526 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05305527 if (hdd_ctx->hbw_requested) {
5528 pld_remove_pm_qos(hdd_ctx->parent_dev);
5529 hdd_ctx->hbw_requested = false;
5530 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05305531 if (cds_sched_handle_throughput_req(false))
Jeff Johnsonb7082ae2016-08-23 13:13:30 -07005532 hdd_err("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05305533 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05305534 if (!hdd_ctx->hbw_requested) {
5535 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
5536 hdd_ctx->hbw_requested = true;
5537 }
5538
Nirav Shah3bbfa512016-05-12 16:43:49 +05305539 if (cds_sched_handle_throughput_req(true))
Jeff Johnsonb7082ae2016-08-23 13:13:30 -07005540 hdd_err("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05305541 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07005542 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543 }
Mohit Khannae71e2262015-11-10 09:37:24 -08005544
5545 /* fine-tuning parameters for RX Flows */
5546 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
5547
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548 hdd_ctx->prev_rx = rx_packets;
Ravi Joshifed83572016-10-07 16:20:37 -07005549 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
5550 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
5551 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
5552 next_rx_level = WLAN_SVC_TP_HIGH;
5553 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07005554 } else {
Mohit Khannae71e2262015-11-10 09:37:24 -08005555 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07005556 hdd_ctx->rx_high_ind_cnt = 0;
5557 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558
Mohit Khannae71e2262015-11-10 09:37:24 -08005559 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].next_rx_level =
5560 next_rx_level;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561
5562 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07005563 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005564 next_rx_level, temp_rx);
5565 hdd_ctx->cur_rx_level = next_rx_level;
Ravi Joshie2331e82015-07-01 18:18:54 -07005566 /* Send throughput indication only if it is enabled.
5567 * Disabling tcp_del_ack will revert the tcp stack behavior
5568 * to default delayed ack. Note that this will disable the
5569 * dynamic delayed ack mechanism across the system
5570 */
5571 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05305572 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
5573 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005574 &next_rx_level,
5575 sizeof(next_rx_level));
5576 }
5577
Mohit Khannae71e2262015-11-10 09:37:24 -08005578 /* fine-tuning parameters for TX Flows */
5579 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
5580 hdd_ctx->prev_tx = tx_packets;
5581 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
5582 next_tx_level = WLAN_SVC_TP_HIGH;
5583 else
5584 next_tx_level = WLAN_SVC_TP_LOW;
5585
5586 if (hdd_ctx->cur_tx_level != next_tx_level) {
5587 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
5588 next_tx_level, temp_tx);
5589 hdd_ctx->cur_tx_level = next_tx_level;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05305590 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
5591 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08005592 &next_tx_level,
5593 sizeof(next_tx_level));
5594 }
5595
5596 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].next_tx_level =
5597 next_tx_level;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598 hdd_ctx->hdd_txrx_hist_idx++;
5599 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005600}
5601
5602#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305603static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005604{
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305605 hdd_context_t *hdd_ctx = container_of(work, hdd_context_t,
5606 bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005607 hdd_adapter_t *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305608 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05305609 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
5610 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611 uint64_t total_tx = 0, total_rx = 0;
5612 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305613 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305614 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005615 bool connected = false;
5616 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
5617
Prashanth Bhattaab004382016-10-11 16:08:11 -07005618 if (wlan_hdd_validate_context(hdd_ctx))
5619 return;
5620
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005621 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305622 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005623 status =
5624 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
5625
5626 if (adapterNode->pAdapter == NULL)
5627 continue;
5628 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05305629 /*
5630 * Validate magic so we don't end up accessing
5631 * an invalid adapter.
5632 */
5633 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
5634 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005636 if ((adapter->device_mode == QDF_STA_MODE ||
5637 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005638 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
5639 != eConnectionState_Associated) {
5640
5641 continue;
5642 }
5643
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005644 if ((adapter->device_mode == QDF_SAP_MODE ||
5645 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
5647
5648 continue;
5649 }
5650
5651 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
5652 adapter->prev_tx_packets);
5653 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
5654 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305655
5656 if (adapter->device_mode == QDF_SAP_MODE ||
5657 adapter->device_mode == QDF_P2P_GO_MODE ||
5658 adapter->device_mode == QDF_IBSS_MODE) {
5659
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08005660 ret = cdp_get_intra_bss_fwd_pkts_count(
5661 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305662 adapter->sessionId,
5663 &fwd_tx_packets, &fwd_rx_packets);
5664 if (ret == A_OK) {
5665 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
5666 fwd_tx_packets,
5667 adapter->prev_fwd_tx_packets);
5668 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
5669 fwd_tx_packets,
5670 adapter->prev_fwd_rx_packets);
5671 }
5672 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673
5674 total_rx += adapter->stats.rx_packets;
5675 total_tx += adapter->stats.tx_packets;
5676
5677 spin_lock_bh(&hdd_ctx->bus_bw_lock);
5678 adapter->prev_tx_packets = adapter->stats.tx_packets;
5679 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305680 adapter->prev_fwd_tx_packets = fwd_tx_packets;
5681 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005682 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
5683 connected = true;
5684 }
5685
5686 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].total_rx = total_rx;
5687 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].total_tx = total_tx;
5688 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].interval_rx =
5689 rx_packets;
5690 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].interval_tx =
5691 tx_packets;
5692
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305693 /* add intra bss forwarded tx and rx packets */
5694 tx_packets += fwd_tx_packets_diff;
5695 rx_packets += fwd_rx_packets_diff;
5696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
5698 tx_packets += (uint64_t)ipa_tx_packets;
5699 rx_packets += (uint64_t)ipa_rx_packets;
5700
5701 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005702 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703 return;
5704 }
5705
Yuanyuan Liu13738502016-04-06 17:41:37 -07005706 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707
5708 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
5709 hdd_ipa_uc_stat_request(adapter, 2);
5710
Dustin Brown2ed60362017-01-18 12:25:50 -08005711 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08005712 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08005713 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05305714 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08005715 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08005716 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005717}
Prashanth Bhattaab004382016-10-11 16:08:11 -07005718
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305719/**
5720 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
5721 * @arg: Argument of timer function
5722 *
5723 * Schedule a workqueue in this function where all the processing is done.
5724 *
5725 * Return: None.
5726 */
5727static void __hdd_bus_bw_cbk(void *arg)
5728{
5729 hdd_context_t *hdd_ctx = (hdd_context_t *) arg;
5730
5731 if (wlan_hdd_validate_context(hdd_ctx))
5732 return;
5733
5734 schedule_work(&hdd_ctx->bus_bw_work);
5735}
5736
5737/**
5738 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
5739 * @arg: Argument of timer function
5740 *
5741 * Return: None.
5742 */
5743static void hdd_bus_bw_cbk(void *arg)
5744{
5745 cds_ssr_protect(__func__);
5746 __hdd_bus_bw_cbk(arg);
5747 cds_ssr_unprotect(__func__);
5748}
5749
Prashanth Bhattaab004382016-10-11 16:08:11 -07005750int hdd_bus_bandwidth_init(hdd_context_t *hdd_ctx)
5751{
5752 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305753 INIT_WORK(&hdd_ctx->bus_bw_work,
5754 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08005755 hdd_ctx->bus_bw_timer_running = false;
5756 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305757 qdf_timer_init(NULL,
5758 &hdd_ctx->bus_bw_timer,
5759 hdd_bus_bw_cbk, (void *)hdd_ctx,
5760 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07005761
5762 return 0;
5763}
5764
5765void hdd_bus_bandwidth_destroy(hdd_context_t *hdd_ctx)
5766{
Dustin Brownfce08d12017-01-17 16:29:38 -08005767 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07005768 hdd_reset_tcp_delack(hdd_ctx);
5769
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305770 hdd_info("wait for bus bw work to flush");
5771 cancel_work_sync(&hdd_ctx->bus_bw_work);
5772 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08005773 hdd_ctx->bus_bw_timer_running = false;
5774 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07005775}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776#endif
5777
5778/**
Nirav Shahed34b212016-04-25 10:59:16 +05305779 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
5780 * @hdd_ctx: hdd context
5781 *
5782 * Return: 0 for success or error code
5783 */
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07005784static int wlan_hdd_init_tx_rx_histogram(hdd_context_t *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05305785{
5786 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
5787 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
5788 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005789 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05305790 return -ENOMEM;
5791 }
5792 return 0;
5793}
5794
5795/**
5796 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
5797 * @hdd_ctx: hdd context
5798 *
5799 * Return: none
5800 */
5801void wlan_hdd_deinit_tx_rx_histogram(hdd_context_t *hdd_ctx)
5802{
5803 if (hdd_ctx->hdd_txrx_hist) {
5804 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
5805 hdd_ctx->hdd_txrx_hist = NULL;
5806 }
5807}
5808
Nirav Shahda008342016-05-17 18:50:40 +05305809static uint8_t *convert_level_to_string(uint32_t level)
5810{
5811 switch (level) {
5812 /* initialize the wlan sub system */
5813 case WLAN_SVC_TP_NONE:
5814 return "NONE";
5815 case WLAN_SVC_TP_LOW:
5816 return "LOW";
5817 case WLAN_SVC_TP_MEDIUM:
5818 return "MED";
5819 case WLAN_SVC_TP_HIGH:
5820 return "HIGH";
5821 default:
5822 return "INVAL";
5823 }
5824}
5825
Nirav Shahed34b212016-04-25 10:59:16 +05305826
5827/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005828 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
5829 * @hdd_ctx: hdd context
5830 *
5831 * Return: none
5832 */
5833void wlan_hdd_display_tx_rx_histogram(hdd_context_t *hdd_ctx)
5834{
5835 int i;
5836
5837#ifdef MSM_PLATFORM
Jeff Johnson760350b2016-08-15 14:01:52 -07005838 hdd_err("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05305839 hdd_ctx->config->busBandwidthComputeInterval);
Jeff Johnson760350b2016-08-15 14:01:52 -07005840 hdd_err("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005841 hdd_ctx->config->busBandwidthHighThreshold,
5842 hdd_ctx->config->busBandwidthMediumThreshold,
5843 hdd_ctx->config->busBandwidthLowThreshold);
Jeff Johnson760350b2016-08-15 14:01:52 -07005844 hdd_err("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05305845 hdd_ctx->config->enable_tcp_delack);
Jeff Johnson760350b2016-08-15 14:01:52 -07005846 hdd_err("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005847 hdd_ctx->config->tcpDelackThresholdHigh,
5848 hdd_ctx->config->tcpDelackThresholdLow);
Jeff Johnson760350b2016-08-15 14:01:52 -07005849 hdd_err("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05305850 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005851#endif
5852
Jeff Johnson760350b2016-08-15 14:01:52 -07005853 hdd_err("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05305854 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
5855
Jeff Johnson760350b2016-08-15 14:01:52 -07005856 hdd_err("index, total_rx, interval_rx, total_tx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005857
5858 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005859 hdd_err("%d: %llu, %llu, %llu, %llu, %s, %s, %s",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005860 i, hdd_ctx->hdd_txrx_hist[i].total_rx,
5861 hdd_ctx->hdd_txrx_hist[i].interval_rx,
5862 hdd_ctx->hdd_txrx_hist[i].total_tx,
5863 hdd_ctx->hdd_txrx_hist[i].interval_tx,
Nirav Shahda008342016-05-17 18:50:40 +05305864 convert_level_to_string(
5865 hdd_ctx->hdd_txrx_hist[i].next_vote_level),
5866 convert_level_to_string(
5867 hdd_ctx->hdd_txrx_hist[i].next_rx_level),
5868 convert_level_to_string(
5869 hdd_ctx->hdd_txrx_hist[i].next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005870 }
5871 return;
5872}
5873
5874/**
5875 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
5876 * @hdd_ctx: hdd context
5877 *
5878 * Return: none
5879 */
5880void wlan_hdd_clear_tx_rx_histogram(hdd_context_t *hdd_ctx)
5881{
5882 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05305883 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
5884 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005885}
5886
5887/**
5888 * wlan_hdd_display_netif_queue_history() - display netif queue operation history
5889 * @pHddCtx: hdd context
5890 *
5891 * Return: none
5892 */
5893void wlan_hdd_display_netif_queue_history(hdd_context_t *hdd_ctx)
5894{
5895
5896 hdd_adapter_t *adapter = NULL;
5897 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305898 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005899 int i;
Nirav Shahda008342016-05-17 18:50:40 +05305900 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901
5902 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305903 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005904 adapter = adapter_node->pAdapter;
5905
Jeff Johnson760350b2016-08-15 14:01:52 -07005906 hdd_err("\nNetif queue operation statistics:");
5907 hdd_err("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05305908 adapter->sessionId, adapter->device_mode);
Jeff Johnson760350b2016-08-15 14:01:52 -07005909 hdd_err("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05305910 curr_time = qdf_system_ticks();
5911 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05305912 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05305913 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05305914 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05305915 unpause = adapter->total_unpause_time;
5916 } else {
Nirav Shahda008342016-05-17 18:50:40 +05305917 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05305918 pause = adapter->total_pause_time;
5919 }
Jeff Johnson760350b2016-08-15 14:01:52 -07005920 hdd_err("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05305921 qdf_system_ticks_to_msecs(total),
5922 qdf_system_ticks_to_msecs(pause),
5923 qdf_system_ticks_to_msecs(unpause));
Jeff Johnson760350b2016-08-15 14:01:52 -07005924 hdd_err("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005925
Nirav Shahda008342016-05-17 18:50:40 +05305926 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
5927 qdf_time_t pause_delta = 0;
5928
5929 if (adapter->pause_map & (1 << i))
5930 pause_delta = delta;
5931
Jeff Johnson760350b2016-08-15 14:01:52 -07005932 hdd_err("%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005933 hdd_reason_type_to_string(i),
5934 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05305935 adapter->queue_oper_stats[i].unpause_count,
5936 qdf_system_ticks_to_msecs(
5937 adapter->queue_oper_stats[i].total_pause_time +
5938 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005939 }
5940
Jeff Johnson760350b2016-08-15 14:01:52 -07005941 hdd_err("\nNetif queue operation history:");
5942 hdd_err("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05305943 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
5944
Jeff Johnson760350b2016-08-15 14:01:52 -07005945 hdd_err("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946
5947 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005948 hdd_err("%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05305949 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950 adapter->queue_oper_history[i].time),
5951 hdd_action_type_to_string(
5952 adapter->queue_oper_history[i].netif_action),
5953 hdd_reason_type_to_string(
5954 adapter->queue_oper_history[i].netif_reason),
5955 adapter->queue_oper_history[i].pause_map);
5956 }
5957
5958 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
5959 adapter_node = next;
5960 }
5961
5962
5963}
5964
5965/**
5966 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
5967 * @hdd_ctx: hdd context
5968 *
5969 * Return: none
5970 */
5971void wlan_hdd_clear_netif_queue_history(hdd_context_t *hdd_ctx)
5972{
5973 hdd_adapter_t *adapter = NULL;
5974 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305975 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005976
5977 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305978 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979 adapter = adapter_node->pAdapter;
5980
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305981 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305983 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05305985 adapter->history_index = 0;
5986 adapter->start_time = adapter->last_time = qdf_system_ticks();
5987 adapter->total_pause_time = 0;
5988 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
5990 adapter_node = next;
5991 }
5992}
5993
5994/**
5995 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
5996 * @halHandle: Hal handle
5997 * @pContext: Pointer to the context
5998 * @sessionId: Session ID
5999 * @scanId: Scan ID
6000 * @status: Status
6001 *
6002 * This is the callback to be executed when 11d scan is completed to flush out
6003 * the scan results
6004 *
6005 * 11d scan is done during driver load and is a passive scan on all
6006 * channels supported by the device, 11d scans may find some APs on
6007 * frequencies which are forbidden to be used in the regulatory domain
6008 * the device is operating in. If these APs are notified to the supplicant
6009 * it may try to connect to these APs, thus flush out all the scan results
6010 * which are present in SME after 11d scan is done.
6011 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306012 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006013 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306014static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015 uint8_t sessionId, uint32_t scanId,
6016 eCsrScanStatus status)
6017{
6018 ENTER();
6019
6020 sme_scan_flush_result(halHandle);
6021
6022 EXIT();
6023
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306024 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025}
6026
6027#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6028/**
6029 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6030 * @hdd_ctx: hdd global context
6031 *
6032 * Return: none
6033 */
6034static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6035{
6036 uint8_t i;
6037
6038 mutex_init(&hdd_ctx->op_ctx.op_lock);
6039 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6040 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6041 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6042 }
6043}
6044#else
6045static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6046{
6047}
6048#endif
6049
Yingying Tang95409972016-10-20 15:16:15 +08006050#ifdef WLAN_FEATURE_WOW_PULSE
6051/**
6052 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
6053 * @phddctx: hdd_context_t structure pointer
6054 * @enable: enable or disable this behaviour
6055 *
6056 * Return: int
6057 */
6058static int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6059{
6060 struct hdd_config *pcfg_ini = phddctx->config;
6061 struct wow_pulse_mode wow_pulse_set_info;
6062 QDF_STATUS status;
6063
6064 hdd_notice("wow pulse enable flag is %d", enable);
6065
6066 if (false == phddctx->config->wow_pulse_support)
6067 return 0;
6068
6069 /* prepare the request to send to SME */
6070 if (enable == true) {
6071 wow_pulse_set_info.wow_pulse_enable = true;
6072 wow_pulse_set_info.wow_pulse_pin =
6073 pcfg_ini->wow_pulse_pin;
6074 wow_pulse_set_info.wow_pulse_interval_low =
6075 pcfg_ini->wow_pulse_interval_low;
6076 wow_pulse_set_info.wow_pulse_interval_high =
6077 pcfg_ini->wow_pulse_interval_high;
6078 } else {
6079 wow_pulse_set_info.wow_pulse_enable = false;
6080 wow_pulse_set_info.wow_pulse_pin = 0;
6081 wow_pulse_set_info.wow_pulse_interval_low = 0;
6082 wow_pulse_set_info.wow_pulse_interval_high = 0;
6083 }
6084 hdd_notice("enable %d pin %d low %d high %d",
6085 wow_pulse_set_info.wow_pulse_enable,
6086 wow_pulse_set_info.wow_pulse_pin,
6087 wow_pulse_set_info.wow_pulse_interval_low,
6088 wow_pulse_set_info.wow_pulse_interval_high);
6089
6090 status = sme_set_wow_pulse(&wow_pulse_set_info);
6091 if (QDF_STATUS_E_FAILURE == status) {
6092 hdd_notice("sme_set_wow_pulse failure!");
6093 return -EIO;
6094 }
6095 hdd_notice("sme_set_wow_pulse success!");
6096 return 0;
6097}
6098#else
6099static inline int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6100{
6101 return 0;
6102}
6103#endif
6104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105#ifdef WLAN_FEATURE_FASTPATH
6106/**
6107 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6108 * @hdd_cfg: hdd config
6109 * @context: lower layer context
6110 *
6111 * Return: none
6112 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306113void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006114 void *context)
6115{
6116 if (hdd_cfg->fastpath_enable)
6117 hif_enable_fastpath(context);
6118}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119#endif
6120
Yuanyuan Liu13738502016-04-06 17:41:37 -07006121#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122/**
6123 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006124 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006125 * @level: thermal level
6126 *
6127 * Change IPA data path to SW path when the thermal throttle level greater
6128 * than 0, and restore the original data path when throttle level is 0
6129 *
6130 * Return: none
6131 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006132static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006133{
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006134 hdd_context_t *hdd_ctx = context;
6135
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006136 /* Change IPA to SW path when throttle level greater than 0 */
6137 if (level > THROTTLE_LEVEL_0)
6138 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6139 else
6140 /* restore original concurrency mode */
6141 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6142}
6143
6144/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306145 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6146 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306147 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006148 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306149 * Get a safe channel to restart SAP. PCL already takes into account the
6150 * unsafe channels. So, the PCL is validated with the ACS range to provide
6151 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306153 * Return: Channel number to restart SAP in case of success. In case of any
6154 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006155 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306156static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
6157 hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006158{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306159 struct sir_pcl_list pcl;
6160 QDF_STATUS status;
6161 uint32_t i, j;
6162 tHalHandle *hal_handle;
6163 hdd_context_t *hdd_ctx;
6164 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306166 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6167 if (!hdd_ctx) {
6168 hdd_err("invalid HDD context");
6169 return INVALID_CHANNEL_ID;
6170 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006171
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306172 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6173 if (!hal_handle) {
6174 hdd_err("invalid HAL handle");
6175 return INVALID_CHANNEL_ID;
6176 }
6177
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306178 status = cds_get_pcl_for_existing_conn(CDS_SAP_MODE,
6179 pcl.pcl_list, &pcl.pcl_len,
6180 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list));
6181 if (QDF_IS_STATUS_ERROR(status)) {
6182 hdd_err("Get PCL failed");
6183 return INVALID_CHANNEL_ID;
6184 }
6185
6186 if (!pcl.pcl_len) {
6187 hdd_alert("pcl length is zero. this is not expected");
6188 return INVALID_CHANNEL_ID;
6189 }
6190
6191 hdd_info("start:%d end:%d",
6192 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
6193 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
6194
6195 /* PCL already takes unsafe channel into account */
6196 for (i = 0; i < pcl.pcl_len; i++) {
6197 hdd_info("chan[%d]:%d", i, pcl.pcl_list[i]);
6198 if ((pcl.pcl_list[i] >=
6199 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6200 (pcl.pcl_list[i] <=
6201 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
6202 hdd_info("found PCL safe chan:%d", pcl.pcl_list[i]);
6203 return pcl.pcl_list[i];
6204 }
6205 }
6206
6207 hdd_info("no safe channel from PCL found in ACS range");
6208
6209 /* Try for safe channel from all valid channel */
6210 pcl.pcl_len = MAX_NUM_CHAN;
6211 status = sme_get_cfg_valid_channels(hal_handle, pcl.pcl_list,
6212 &pcl.pcl_len);
6213 if (QDF_IS_STATUS_ERROR(status)) {
6214 hdd_err("error in getting valid channel list");
6215 return INVALID_CHANNEL_ID;
6216 }
6217
6218 for (i = 0; i < pcl.pcl_len; i++) {
6219 hdd_info("chan[%d]:%d", i, pcl.pcl_list[i]);
6220 found = false;
6221 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006222 if (pcl.pcl_list[i] ==
6223 hdd_ctx->unsafe_channel_list[j]) {
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306224 hdd_info("unsafe chan:%d", pcl.pcl_list[i]);
6225 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006226 break;
6227 }
6228 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306229
6230 if (found)
6231 continue;
6232
6233 if ((pcl.pcl_list[i] >=
6234 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6235 (pcl.pcl_list[i] <=
6236 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
6237 hdd_info("found safe chan:%d", pcl.pcl_list[i]);
6238 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006239 }
6240 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306241
6242 return INVALID_CHANNEL_ID;
6243}
6244
6245/**
6246 * hdd_restart_sap() - Restarts SAP on the given channel
6247 * @adapter: AP adapter
6248 * @channel: Channel
6249 *
6250 * Restarts the SAP interface by invoking the function which executes the
6251 * callback to perform channel switch using (E)CSA.
6252 *
6253 * Return: None
6254 */
Kapil Gupta8878ad92017-02-13 11:56:04 +05306255void hdd_restart_sap(hdd_adapter_t *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306256{
6257 hdd_ap_ctx_t *hdd_ap_ctx;
6258 tHalHandle *hal_handle;
6259
6260 if (!adapter) {
6261 hdd_err("invalid adapter");
6262 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006263 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306264
6265 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
6266
6267 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6268 if (!hal_handle) {
6269 hdd_err("invalid HAL handle");
6270 return;
6271 }
6272
6273 hdd_ap_ctx->sapConfig.channel = channel;
6274 hdd_ap_ctx->sapConfig.ch_params.ch_width =
6275 hdd_ap_ctx->sapConfig.ch_width_orig;
6276
6277 hdd_info("chan:%d width:%d",
6278 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
6279
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -07006280 cds_set_channel_params(hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306281 hdd_ap_ctx->sapConfig.sec_ch,
6282 &hdd_ap_ctx->sapConfig.ch_params);
6283
6284 cds_change_sap_channel_with_csa(adapter, hdd_ap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285}
Kapil Gupta8878ad92017-02-13 11:56:04 +05306286
6287int hdd_update_acs_timer_reason(hdd_adapter_t *adapter, uint8_t reason)
6288{
6289 struct hdd_external_acs_timer_context *timer_context;
6290
6291 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
6292
6293 if (QDF_TIMER_STATE_RUNNING ==
6294 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
6295 ap.vendor_acs_timer)) {
6296 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
6297 }
6298 timer_context = (struct hdd_external_acs_timer_context *)
6299 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
6300 timer_context->reason = reason;
6301 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
6302 WLAN_VENDOR_ACS_WAIT_TIME);
6303 /* Update config to application */
6304 hdd_cfg80211_update_acs_config(adapter, reason);
6305 hdd_notice("Updated ACS config to nl with reason %d", reason);
6306
6307 return 0;
6308}
6309
Agrawal Ashish467dde42016-09-08 18:44:22 +05306310/**
6311 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
6312 * @hdd_ctx: hdd context pointer
6313 *
6314 * hdd_unsafe_channel_restart_sap check all unsafe channel list
6315 * and if ACS is enabled, driver will ask userspace to restart the
6316 * sap. User space on LTE coex indication restart driver.
6317 *
6318 * Return - none
6319 */
6320void hdd_unsafe_channel_restart_sap(hdd_context_t *hdd_ctxt)
6321{
6322 QDF_STATUS status;
6323 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
6324 hdd_adapter_t *adapter_temp;
6325 uint32_t i;
6326 bool found = false;
6327 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006328
Agrawal Ashish467dde42016-09-08 18:44:22 +05306329 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
6330 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
6331 adapter_temp = adapter_node->pAdapter;
6332
6333 if (!adapter_temp) {
6334 hdd_err("adapter is NULL, moving to next one");
6335 goto next_adapater;
6336 }
6337
6338 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
6339 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
6340 hdd_info("skip device mode:%d acs:%d",
6341 adapter_temp->device_mode,
6342 adapter_temp->sessionCtx.ap.sapConfig.
6343 acs_cfg.acs_mode);
6344 goto next_adapater;
6345 }
6346
6347 found = false;
6348 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006349 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05306350 hdd_ctxt->unsafe_channel_list[i]) {
6351 found = true;
6352 hdd_info("operating ch:%d is unsafe",
6353 adapter_temp->sessionCtx.ap.operatingChannel);
6354 break;
6355 }
6356 }
6357
6358 if (!found) {
6359 hdd_info("ch:%d is safe. no need to change channel",
6360 adapter_temp->sessionCtx.ap.operatingChannel);
6361 goto next_adapater;
6362 }
6363
Kapil Gupta8878ad92017-02-13 11:56:04 +05306364 if (hdd_ctxt->config->vendor_acs_support &&
6365 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
6366 hdd_update_acs_timer_reason(adapter_temp,
6367 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
6368 goto next_adapater;
6369 } else
6370 restart_chan =
6371 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05306372 adapter_temp);
6373 if (!restart_chan) {
6374 hdd_alert("fail to restart SAP");
6375 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08006376 /*
6377 * SAP restart due to unsafe channel. While
6378 * restarting the SAP, make sure to clear
6379 * acs_channel, channel to reset to
6380 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05306381 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08006382 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05306383 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
6384 adapter_temp->sessionCtx.ap.sapConfig.channel =
6385 AUTO_CHANNEL_SELECT;
Agrawal Ashish467dde42016-09-08 18:44:22 +05306386 hdd_info("sending coex indication");
6387 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
6388 WLAN_SVC_LTE_COEX_IND, NULL, 0);
6389 hdd_restart_sap(adapter_temp, restart_chan);
6390 }
6391
6392next_adapater:
6393 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
6394 adapter_node = next;
6395 }
6396}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006397/**
6398 * hdd_ch_avoid_cb() - Avoid notified channels from FW handler
6399 * @adapter: HDD adapter pointer
6400 * @indParam: Channel avoid notification parameter
6401 *
6402 * Avoid channel notification from FW handler.
6403 * FW will send un-safe channel list to avoid over wrapping.
6404 * hostapd should not use notified channel
6405 *
6406 * Return: None
6407 */
Agrawal Ashish467dde42016-09-08 18:44:22 +05306408void hdd_ch_avoid_cb(void *hdd_context, void *indi_param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006409{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410 hdd_context_t *hdd_ctxt;
6411 tSirChAvoidIndType *ch_avoid_indi;
6412 uint8_t range_loop;
Amar Singhalb8d4f152016-02-10 10:21:43 -08006413 enum channel_enum channel_loop, start_channel_idx = INVALID_CHANNEL,
6414 end_channel_idx = INVALID_CHANNEL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006415 uint16_t start_channel;
6416 uint16_t end_channel;
6417 v_CONTEXT_t cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006418 tHddAvoidFreqList hdd_avoid_freq_list;
6419 uint32_t i;
6420
6421 /* Basic sanity */
6422 if (!hdd_context || !indi_param) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006423 hdd_err("Invalid arguments");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424 return;
6425 }
6426
6427 hdd_ctxt = (hdd_context_t *) hdd_context;
6428 ch_avoid_indi = (tSirChAvoidIndType *) indi_param;
6429 cds_context = hdd_ctxt->pcds_context;
6430
6431 /* Make unsafe channel list */
Jeff Johnson34c88b72016-08-15 14:27:11 -07006432 hdd_notice("band count %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006433 ch_avoid_indi->avoid_range_count);
6434
6435 /* generate vendor specific event */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306436 qdf_mem_zero((void *)&hdd_avoid_freq_list, sizeof(tHddAvoidFreqList));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006437 for (i = 0; i < ch_avoid_indi->avoid_range_count; i++) {
6438 hdd_avoid_freq_list.avoidFreqRange[i].startFreq =
6439 ch_avoid_indi->avoid_freq_range[i].start_freq;
6440 hdd_avoid_freq_list.avoidFreqRange[i].endFreq =
6441 ch_avoid_indi->avoid_freq_range[i].end_freq;
6442 }
6443 hdd_avoid_freq_list.avoidFreqRangeCount =
6444 ch_avoid_indi->avoid_range_count;
6445
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006446 /* clear existing unsafe channel cache */
6447 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306448 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006449 sizeof(hdd_ctxt->unsafe_channel_list));
6450
6451 for (range_loop = 0; range_loop < ch_avoid_indi->avoid_range_count;
6452 range_loop++) {
Amar Singhalb8d4f152016-02-10 10:21:43 -08006453 if (hdd_ctxt->unsafe_channel_count >= NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006454 hdd_warn("LTE Coex unsafe channel list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006455 break;
6456 }
6457
6458 start_channel = ieee80211_frequency_to_channel(
6459 ch_avoid_indi->avoid_freq_range[range_loop].start_freq);
6460 end_channel = ieee80211_frequency_to_channel(
6461 ch_avoid_indi->avoid_freq_range[range_loop].end_freq);
Jeff Johnson34c88b72016-08-15 14:27:11 -07006462 hdd_notice("start %d : %d, end %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006463 ch_avoid_indi->avoid_freq_range[range_loop].start_freq,
6464 start_channel,
6465 ch_avoid_indi->avoid_freq_range[range_loop].end_freq,
6466 end_channel);
6467
6468 /* do not process frequency bands that are not mapped to
6469 * predefined channels
6470 */
6471 if (start_channel == 0 || end_channel == 0)
6472 continue;
6473
Amar Singhalb8d4f152016-02-10 10:21:43 -08006474 for (channel_loop = CHAN_ENUM_1; channel_loop <=
6475 CHAN_ENUM_184; channel_loop++) {
Amar Singhal7a1726a2015-10-14 16:28:11 -07006476 if (CDS_CHANNEL_FREQ(channel_loop) >=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006477 ch_avoid_indi->avoid_freq_range[
6478 range_loop].start_freq) {
6479 start_channel_idx = channel_loop;
6480 break;
6481 }
6482 }
Amar Singhalb8d4f152016-02-10 10:21:43 -08006483 for (channel_loop = CHAN_ENUM_1; channel_loop <=
6484 CHAN_ENUM_184; channel_loop++) {
Amar Singhal7a1726a2015-10-14 16:28:11 -07006485 if (CDS_CHANNEL_FREQ(channel_loop) >=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006486 ch_avoid_indi->avoid_freq_range[
6487 range_loop].end_freq) {
6488 end_channel_idx = channel_loop;
Amar Singhal7a1726a2015-10-14 16:28:11 -07006489 if (CDS_CHANNEL_FREQ(channel_loop) >
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006490 ch_avoid_indi->avoid_freq_range[
6491 range_loop].end_freq)
6492 end_channel_idx--;
6493 break;
6494 }
6495 }
6496
Amar Singhalb8d4f152016-02-10 10:21:43 -08006497 if (start_channel_idx == INVALID_CHANNEL ||
6498 end_channel_idx == INVALID_CHANNEL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499 continue;
6500
6501 for (channel_loop = start_channel_idx; channel_loop <=
6502 end_channel_idx; channel_loop++) {
6503 hdd_ctxt->unsafe_channel_list[
Amar Singhal7a1726a2015-10-14 16:28:11 -07006504 hdd_ctxt->unsafe_channel_count++] =
Krunal Soni15f0db12016-10-11 18:53:37 -07006505 CDS_CHANNEL_NUM(channel_loop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 if (hdd_ctxt->unsafe_channel_count >=
Amar Singhalb8d4f152016-02-10 10:21:43 -08006507 NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006508 hdd_warn("LTECoex unsafe ch list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006509 break;
6510 }
6511 }
6512 }
6513
Jeff Johnson34c88b72016-08-15 14:27:11 -07006514 hdd_notice("number of unsafe channels is %d ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006515 hdd_ctxt->unsafe_channel_count);
6516
Yuanyuan Liu13738502016-04-06 17:41:37 -07006517 if (pld_set_wlan_unsafe_channel(hdd_ctxt->parent_dev,
6518 hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006519 hdd_ctxt->unsafe_channel_count)) {
6520 hdd_err("Failed to set unsafe channel");
6521
6522 /* clear existing unsafe channel cache */
6523 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306524 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006525 sizeof(hdd_ctxt->unsafe_channel_list));
6526
6527 return;
6528 }
6529
6530 for (channel_loop = 0;
6531 channel_loop < hdd_ctxt->unsafe_channel_count; channel_loop++) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006532 hdd_notice("channel %d is not safe ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006533 hdd_ctxt->unsafe_channel_list[channel_loop]);
6534 }
6535
Kondabattini, Ganeshcf7b60f2016-08-10 16:31:55 +05306536 /*
6537 * first update the unsafe channel list to the platform driver and
6538 * send the avoid freq event to the application
6539 */
6540 wlan_hdd_send_avoid_freq_event(hdd_ctxt, &hdd_avoid_freq_list);
6541
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306542 if (!hdd_ctxt->unsafe_channel_count) {
6543 hdd_info("no unsafe channels - not restarting SAP");
6544 return;
6545 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05306546 hdd_unsafe_channel_restart_sap(hdd_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006547 return;
6548}
6549
6550/**
6551 * hdd_init_channel_avoidance() - Initialize channel avoidance
6552 * @hdd_ctx: HDD global context
6553 *
6554 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07006555 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006556 * down to the lower layers. Then subscribe to subsequent channel
6557 * avoidance events.
6558 *
6559 * Return: None
6560 */
6561static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
6562{
6563 uint16_t unsafe_channel_count;
6564 int index;
6565
Yuanyuan Liu13738502016-04-06 17:41:37 -07006566 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
6567 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08006569 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570
Jeff Johnson34c88b72016-08-15 14:27:11 -07006571 hdd_notice("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006572 hdd_ctx->unsafe_channel_count);
6573
Anurag Chouhan6d760662016-02-20 16:05:43 +05306574 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08006575 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006576
6577 for (index = 0; index < unsafe_channel_count; index++) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006578 hdd_notice("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006579 hdd_ctx->unsafe_channel_list[index]);
6580
6581 }
6582
6583 /* Plug in avoid channel notification callback */
6584 sme_add_ch_avoid_callback(hdd_ctx->hHal, hdd_ch_avoid_cb);
6585}
6586#else
6587static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
6588{
6589}
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006590static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591{
6592}
Yuanyuan Liu13738502016-04-06 17:41:37 -07006593#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594
6595/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08006596 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
6597 * user space
6598 * @frame_ind: Management frame data to be informed.
6599 *
6600 * This function is used to indicate management frame to
6601 * user space
6602 *
6603 * Return: None
6604 *
6605 */
6606void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
6607{
6608 hdd_context_t *hdd_ctx = NULL;
6609 hdd_adapter_t *adapter = NULL;
6610 void *cds_context = NULL;
6611 int i;
6612
6613 /* Get the global VOSS context.*/
6614 cds_context = cds_get_global_context();
6615 if (!cds_context) {
6616 hdd_err("Global CDS context is Null");
6617 return;
6618 }
6619 /* Get the HDD context.*/
6620 hdd_ctx = (hdd_context_t *)cds_get_context(QDF_MODULE_ID_HDD);
6621
6622 if (0 != wlan_hdd_validate_context(hdd_ctx))
6623 return;
6624
6625 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
6626 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
6627 adapter =
6628 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
6629 if (adapter)
6630 break;
6631 }
6632 } else {
6633 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
6634 frame_ind->sessionId);
6635 }
6636
6637 if ((NULL != adapter) &&
6638 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
6639 __hdd_indicate_mgmt_frame(adapter,
6640 frame_ind->frame_len,
6641 frame_ind->frameBuf,
6642 frame_ind->frameType,
6643 frame_ind->rxChan,
6644 frame_ind->rxRssi);
6645 return;
6646}
6647
Kapil Gupta8878ad92017-02-13 11:56:04 +05306648static void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
6649 hdd_context_t *hdd_ctx)
6650{
6651 uint8_t restart_chan = 0;
6652
6653 restart_chan =
6654 hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
6655 if (!restart_chan) {
6656 hdd_alert("fail to restart SAP");
6657 } else {
6658 /* SAP restart due to unsafe channel. While restarting
6659 * the SAP, make sure to clear acs_channel, channel to
6660 * reset to 0. Otherwise these settings will override
6661 * the ACS while restart.
6662 */
6663 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
6664 adapter->sessionCtx.ap.sapConfig.channel =
6665 AUTO_CHANNEL_SELECT;
6666 hdd_info("sending coex indication");
6667 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6668 WLAN_SVC_LTE_COEX_IND, NULL, 0);
6669 hdd_restart_sap(adapter, restart_chan);
6670 }
6671}
6672
6673void hdd_acs_response_timeout_handler(void *context)
6674{
6675 struct hdd_external_acs_timer_context *timer_context =
6676 (struct hdd_external_acs_timer_context *)context;
6677 hdd_adapter_t *adapter;
6678 hdd_context_t *hdd_ctx;
6679 uint8_t reason;
6680
6681 ENTER();
6682 if (!timer_context) {
6683 hdd_err("invlaid timer context");
6684 return;
6685 }
6686 adapter = timer_context->adapter;
6687 reason = timer_context->reason;
6688
6689
6690 if ((!adapter) ||
6691 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
6692 hdd_err("invalid adapter or adapter has invalid magic");
6693 return;
6694 }
6695 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6696 if (wlan_hdd_validate_context(hdd_ctx))
6697 return;
6698
6699 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
6700 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
6701 else
6702 return;
6703
6704 hdd_err("ACS timeout happened for %s reason %d",
6705 adapter->dev->name, reason);
6706 switch (reason) {
6707 /* SAP init case */
6708 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
6709 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
6710 false);
6711 wlan_hdd_cfg80211_start_acs(adapter);
6712 break;
6713 /* DFS detected on current channel */
6714 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
6715 wlan_sap_update_next_channel(
6716 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
6717 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
6718 adapter->sessionId);
6719 break;
6720 /* LTE coex event on current channel */
6721 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
6722 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
6723 break;
6724 default:
6725 hdd_info("invalid reason for timer invoke");
6726
6727 }
6728}
6729
Rajeev Kumard004abc2016-02-17 12:09:56 -08006730/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
6732 * @hdd_ctx: HDD context
6733 *
6734 * Disables all the dual mac features like DBS, Agile DFS etc.
6735 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306736 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006737 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306738static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739{
6740 struct sir_dual_mac_config cfg;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306741 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006742
6743 if (!hdd_ctx) {
6744 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306745 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006746 }
6747
6748 cfg.scan_config = 0;
6749 cfg.fw_mode_config = 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +05306750 cfg.set_dual_mac_cb = cds_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751
6752 hdd_debug("Disabling all dual mac features...");
6753
6754 status = sme_soc_set_dual_mac_config(hdd_ctx->hHal, cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306755 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006756 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
6757 return status;
6758 }
6759
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306760 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006761}
6762
6763/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006764 * hdd_override_ini_config - Override INI config
6765 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006767 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006769 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006771static void hdd_override_ini_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006774 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
6775 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
6776 hdd_notice("Module enable_dfs_chan_scan set to %d",
6777 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006779 if (0 == enable_11d || 1 == enable_11d) {
6780 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
6781 hdd_notice("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006782 }
Leo Chang11545d62016-10-17 14:53:50 -07006783
6784 if (!hdd_ipa_is_present(hdd_ctx))
6785 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006786}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006788/**
6789 * hdd_set_trace_level_for_each - Set trace level for each INI config
6790 * @hdd_ctx - HDD context
6791 *
6792 * Set trace level for each module based on INI config.
6793 *
6794 * Return: None
6795 */
6796static void hdd_set_trace_level_for_each(hdd_context_t *hdd_ctx)
6797{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306798 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
6799 hdd_ctx->config->qdf_trace_enable_wdi);
6800 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
6801 hdd_ctx->config->qdf_trace_enable_hdd);
6802 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
6803 hdd_ctx->config->qdf_trace_enable_sme);
6804 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
6805 hdd_ctx->config->qdf_trace_enable_pe);
6806 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
6807 hdd_ctx->config->qdf_trace_enable_wma);
6808 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
6809 hdd_ctx->config->qdf_trace_enable_sys);
6810 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
6811 hdd_ctx->config->qdf_trace_enable_qdf);
6812 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
6813 hdd_ctx->config->qdf_trace_enable_sap);
6814 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
6815 hdd_ctx->config->qdf_trace_enable_hdd_sap);
6816 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
6817 hdd_ctx->config->qdf_trace_enable_bmi);
6818 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
6819 hdd_ctx->config->qdf_trace_enable_cfg);
6820 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
6821 hdd_ctx->config->qdf_trace_enable_epping);
6822 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
6823 hdd_ctx->config->qdf_trace_enable_qdf_devices);
6824 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Bhargav Shah480a90f2015-06-24 15:10:14 +05306825 hdd_ctx->config->cfd_trace_enable_txrx);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306826 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
6827 hdd_ctx->config->qdf_trace_enable_htc);
6828 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
6829 hdd_ctx->config->qdf_trace_enable_hif);
6830 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
6831 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
6832 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
6833 hdd_ctx->config->qdf_trace_enable_hdd_data);
Bhargav Shah480a90f2015-06-24 15:10:14 +05306834
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006835 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006836}
6837
6838/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006839 * hdd_context_init() - Initialize HDD context
6840 * @hdd_ctx: HDD context.
6841 *
6842 * Initialize HDD context along with all the feature specific contexts.
6843 *
6844 * return: 0 on success and errno on failure.
6845 */
6846static int hdd_context_init(hdd_context_t *hdd_ctx)
6847{
6848 int ret;
6849
6850 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
6851 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
6852
6853 hdd_init_ll_stats_ctx();
6854
6855 init_completion(&hdd_ctx->mc_sus_event_var);
6856 init_completion(&hdd_ctx->ready_to_suspend);
6857
6858 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306859 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006860 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306861
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006862 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
6863
6864 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
6865
6866 ret = hdd_scan_context_init(hdd_ctx);
6867 if (ret)
6868 goto list_destroy;
6869
Nitesh Shahd1266d72017-01-25 22:07:07 +05306870 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006871
6872 hdd_rx_wake_lock_create(hdd_ctx);
6873
6874 ret = hdd_sap_context_init(hdd_ctx);
6875 if (ret)
6876 goto scan_destroy;
6877
6878 ret = hdd_roc_context_init(hdd_ctx);
6879 if (ret)
6880 goto sap_destroy;
6881
6882 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
6883
6884 hdd_init_offloaded_packets_ctx(hdd_ctx);
6885
6886 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
6887 hdd_ctx->config);
6888 if (ret)
6889 goto roc_destroy;
6890
6891 return 0;
6892
6893roc_destroy:
6894 hdd_roc_context_destroy(hdd_ctx);
6895
6896sap_destroy:
6897 hdd_sap_context_destroy(hdd_ctx);
6898
6899scan_destroy:
6900 hdd_scan_context_destroy(hdd_ctx);
6901 hdd_rx_wake_lock_destroy(hdd_ctx);
6902 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006903list_destroy:
6904 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08006905
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006906 return ret;
6907}
6908
6909/**
6910 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05306911 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006912 *
6913 * Allocate and initialize HDD context. HDD context is allocated as part of
6914 * wiphy allocation and then context is initialized.
6915 *
6916 * Return: HDD context on success and ERR_PTR on failure
6917 */
Jeff Johnson590e2012016-10-05 16:16:24 -07006918static hdd_context_t *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006919{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306920 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006921 int ret = 0;
6922 hdd_context_t *hdd_ctx;
6923 v_CONTEXT_t p_cds_context;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05306924 int qdf_print_idx = -1;
6925
6926 struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
6927 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
6928 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
6929 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
6930 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
6931 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
6932 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
6933 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
6934 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
6935 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
6936 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
6937 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
6938 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
6939 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
6940 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
6941 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
6942 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
6943 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
6944 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
6945 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
6946 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiyaf928edf2017-02-06 14:43:24 +05306947 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
6948 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
6949 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
6950 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
6951 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
6952 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
Mukul Sharma4d7d6b02017-02-13 20:45:22 +05306953 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh9679dbf2017-02-15 11:35:41 +05306954 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
6955 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL}
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05306956 };
6957
6958 status = qdf_print_setup();
6959 if (status != QDF_STATUS_SUCCESS) {
6960 pr_err("QDF print control object setup failed\n");
6961 ret = -EINVAL;
6962 goto err_out;
6963 }
6964 /* Register the module here with QDF */
6965 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL,
6966 "MCL_WLAN");
6967
6968 /* if qdf_print_idx is negative */
6969 if (qdf_print_idx < 0) {
6970 pr_err("QDF print control can not be registered %d\n",
6971 qdf_print_idx);
6972 ret = -EINVAL;
6973 goto err_out;
6974 }
6975
6976 /* Store the qdf_pidx information into qdf module */
6977 qdf_set_pidx(qdf_print_idx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006978
6979 ENTER();
6980
6981 p_cds_context = cds_get_global_context();
6982 if (p_cds_context == NULL) {
6983 hdd_alert("Failed to get CDS global context");
6984 ret = -EINVAL;
6985 goto err_out;
6986 }
6987
6988 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t));
6989
6990 if (hdd_ctx == NULL) {
6991 ret = -ENOMEM;
6992 goto err_out;
6993 }
6994
6995 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006996 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05306997 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006998
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306999 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007000 if (hdd_ctx->config == NULL) {
7001 hdd_alert("Failed to alloc memory for HDD config!");
7002 ret = -ENOMEM;
7003 goto err_free_hdd_context;
7004 }
7005
7006 /* Read and parse the qcom_cfg.ini file */
7007 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307008 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307009 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007010 WLAN_INI_FILE);
7011 ret = -EINVAL;
7012 goto err_free_config;
7013 }
7014
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007015 hdd_notice("Setting configuredMcastBcastFilter: %d",
7016 hdd_ctx->config->mcastBcastFilterSetting);
7017
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307018 if (hdd_ctx->config->fhostNSOffload)
7019 hdd_ctx->ns_offload_enable = true;
7020
Abhishek Singh5ea86532016-04-27 14:10:53 +05307021 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7022
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007023 hdd_override_ini_config(hdd_ctx);
7024
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007025 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007026
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007027 ret = hdd_context_init(hdd_ctx);
7028
7029 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007030 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007031
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007032
Yuanyuan Liu7a97b8f2017-01-27 10:42:52 -08007033 pld_set_fw_log_mode(hdd_ctx->parent_dev,
7034 hdd_ctx->config->enable_fw_log);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007035
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007036
7037 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307038 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007039
Anurag Chouhan6d760662016-02-20 16:05:43 +05307040 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007041 goto skip_multicast_logging;
7042
7043 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7044
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007045 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7046 if (ret)
7047 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307048
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007049 ret = hdd_logging_sock_activate_svc(hdd_ctx);
7050 if (ret)
Nirav Shahed34b212016-04-25 10:59:16 +05307051 goto err_free_histogram;
7052
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007053skip_multicast_logging:
7054 hdd_set_trace_level_for_each(hdd_ctx);
7055
7056 return hdd_ctx;
7057
Nirav Shahed34b212016-04-25 10:59:16 +05307058err_free_histogram:
7059 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7060
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007061err_deinit_hdd_context:
7062 hdd_context_deinit(hdd_ctx);
7063
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007064err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307065 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007066
7067err_free_hdd_context:
7068 wiphy_free(hdd_ctx->wiphy);
7069
7070err_out:
7071 return ERR_PTR(ret);
7072}
7073
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007074#ifdef WLAN_OPEN_P2P_INTERFACE
7075/**
7076 * hdd_open_p2p_interface - Open P2P interface
7077 * @hdd_ctx: HDD context
7078 * @rtnl_held: True if RTNL lock held
7079 *
7080 * Open P2P interface during probe. This function called to open the P2P
7081 * interface at probe along with STA interface.
7082 *
7083 * Return: 0 on success and errno on failure
7084 */
7085static int hdd_open_p2p_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7086{
7087 hdd_adapter_t *adapter;
7088 uint8_t *p2p_dev_addr;
7089
7090 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7091 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307092 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007093 hdd_ctx->config->intfMacAddr[0].bytes,
7094 sizeof(tSirMacAddr));
7095
7096 /*
7097 * Generate the P2P Device Address. This consists of
7098 * the device's primary MAC address with the locally
7099 * administered bit set.
7100 */
7101 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7102 } else {
7103 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7104 if (p2p_dev_addr == NULL) {
7105 hdd_alert("Failed to allocate mac_address for p2p_device");
7106 return -ENOSPC;
7107 }
7108
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307109 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307110 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007111 }
7112
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007113 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007114 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007115 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007116
7117 if (NULL == adapter) {
7118 hdd_alert("Failed to do hdd_open_adapter for P2P Device Interface");
7119 return -ENOSPC;
7120 }
7121
7122 return 0;
7123}
7124#else
Manishekar Chandrasekaranc81ba242016-07-18 17:44:44 +05307125static inline int hdd_open_p2p_interface(hdd_context_t *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007126 bool rtnl_held)
7127{
7128 return 0;
7129}
7130#endif
7131
Jeff Johnson957bc272017-02-02 08:54:48 -08007132static int hdd_open_ocb_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7133{
7134 hdd_adapter_t *adapter;
7135 int ret = 0;
7136
7137 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7138 wlan_hdd_get_intf_addr(hdd_ctx),
7139 NET_NAME_UNKNOWN, rtnl_held);
7140 if (adapter == NULL) {
7141 hdd_err("Failed to open 802.11p interface");
7142 ret = -ENOSPC;
7143 }
7144
7145 return ret;
7146}
7147
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007148/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307149 * hdd_start_station_adapter()- Start the Station Adapter
7150 * @adapter: HDD adapter
7151 *
7152 * This function initializes the adapter for the station mode.
7153 *
7154 * Return: 0 on success or errno on failure.
7155 */
7156int hdd_start_station_adapter(hdd_adapter_t *adapter)
7157{
7158 QDF_STATUS status;
7159
7160 ENTER_DEV(adapter->dev);
7161
7162 status = hdd_init_station_mode(adapter);
7163
7164 if (QDF_STATUS_SUCCESS != status) {
7165 hdd_err("Error Initializing station mode: %d", status);
7166 return qdf_status_to_os_return(status);
7167 }
7168
Arun Khandavallifae92942016-08-01 13:31:08 +05307169 hdd_register_tx_flow_control(adapter,
7170 hdd_tx_resume_timer_expired_handler,
7171 hdd_tx_resume_cb);
7172
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307173 EXIT();
7174 return 0;
7175}
7176
7177/**
7178 * hdd_start_ap_adapter()- Start AP Adapter
7179 * @adapter: HDD adapter
7180 *
7181 * This function initializes the adapter for the AP mode.
7182 *
7183 * Return: 0 on success errno on failure.
7184 */
7185int hdd_start_ap_adapter(hdd_adapter_t *adapter)
7186{
7187 QDF_STATUS status;
7188
7189 ENTER();
7190
Arun Khandavallicc544b32017-01-30 19:52:16 +05307191 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307192
7193 if (QDF_STATUS_SUCCESS != status) {
7194 hdd_err("Error Initializing the AP mode: %d", status);
7195 return qdf_status_to_os_return(status);
7196 }
7197
Arun Khandavallifae92942016-08-01 13:31:08 +05307198 hdd_register_tx_flow_control(adapter,
7199 hdd_softap_tx_resume_timer_expired_handler,
7200 hdd_softap_tx_resume_cb);
7201
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307202 EXIT();
7203 return 0;
7204}
7205
7206/**
7207 * hdd_start_ftm_adapter()- Start FTM adapter
7208 * @adapter: HDD adapter
7209 *
7210 * This function initializes the adapter for the FTM mode.
7211 *
7212 * Return: 0 on success or errno on failure.
7213 */
7214int hdd_start_ftm_adapter(hdd_adapter_t *adapter)
7215{
7216 QDF_STATUS qdf_status;
7217
7218 ENTER_DEV(adapter->dev);
7219
7220 qdf_status = hdd_init_tx_rx(adapter);
7221
7222 if (QDF_STATUS_SUCCESS != qdf_status) {
7223 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7224 return qdf_status_to_os_return(qdf_status);
7225 }
7226
7227 return 0;
7228 EXIT();
7229}
7230
7231/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007232 * hdd_open_interfaces - Open all required interfaces
7233 * hdd_ctx: HDD context
7234 * rtnl_held: True if RTNL lock is held
7235 *
7236 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7237 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007238 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007239 */
Jeff Johnson957bc272017-02-02 08:54:48 -08007240static int hdd_open_interfaces(hdd_context_t *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007241{
Jeff Johnson957bc272017-02-02 08:54:48 -08007242 hdd_adapter_t *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007243 int ret;
7244
Jeff Johnson957bc272017-02-02 08:54:48 -08007245 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05307246 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08007247 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007248
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007249 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007250 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08007251 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007252
7253 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08007254 return -ENOSPC;
7255
Deepak Dhamdherea2785822016-11-17 01:17:45 -08007256 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
7257 adapter->fast_roaming_allowed = true;
7258
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007259 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
7260 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08007261 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007262
7263 /* Open 802.11p Interface */
7264 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08007265 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
7266 if (ret)
7267 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007268 }
7269
Jeff Johnson957bc272017-02-02 08:54:48 -08007270 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007271
Jeff Johnson957bc272017-02-02 08:54:48 -08007272err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007273 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08007274 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007275}
7276
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007277/**
7278 * hdd_update_country_code - Update country code
7279 * @hdd_ctx: HDD context
7280 * @adapter: Primary adapter context
7281 *
7282 * Update country code based on module parameter country_code at SME and wait
7283 * for the settings to take effect.
7284 *
7285 * Return: 0 on success and errno on failure
7286 */
7287static int hdd_update_country_code(hdd_context_t *hdd_ctx,
7288 hdd_adapter_t *adapter)
7289{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307290 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007291 int ret = 0;
7292 unsigned long rc;
7293
7294 if (country_code == NULL)
7295 return 0;
7296
7297 INIT_COMPLETION(adapter->change_country_code);
7298
7299 status = sme_change_country_code(hdd_ctx->hHal,
7300 wlan_hdd_change_country_code_callback,
7301 country_code, adapter,
7302 hdd_ctx->pcds_context, eSIR_TRUE,
7303 eSIR_TRUE);
7304
7305
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307306 if (!QDF_IS_STATUS_SUCCESS(status)) {
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007307 hdd_err("SME Change Country code from module param fail ret=%d",
7308 ret);
7309 return -EINVAL;
7310 }
7311
7312 rc = wait_for_completion_timeout(&adapter->change_country_code,
7313 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
7314 if (!rc) {
7315 hdd_err("SME while setting country code timed out");
7316 ret = -ETIMEDOUT;
7317 }
7318
7319 return ret;
7320}
7321
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307322#ifdef QCA_LL_TX_FLOW_CONTROL_V2
7323/**
7324 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
7325 * @cds_cfg: CDS Configuration
7326 * @hdd_ctx: Pointer to hdd context
7327 *
7328 * Return: none
7329 */
7330static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7331 *cds_cfg,
7332 hdd_context_t *hdd_ctx)
7333{
7334 cds_cfg->tx_flow_stop_queue_th =
7335 hdd_ctx->config->TxFlowStopQueueThreshold;
7336 cds_cfg->tx_flow_start_queue_offset =
7337 hdd_ctx->config->TxFlowStartQueueOffset;
7338}
7339#else
7340static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7341 *cds_cfg,
7342 hdd_context_t *hdd_ctx)
7343{
7344}
7345#endif
7346
7347#ifdef FEATURE_WLAN_RA_FILTERING
7348/**
7349 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
7350 * @cds_cfg: CDS Configuration
7351 * @hdd_ctx: Pointer to hdd context
7352 *
7353 * Return: none
7354 */
Anand Kumar3b92a912016-12-05 12:01:26 +05307355static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307356 hdd_context_t *hdd_ctx)
7357{
7358 cds_cfg->ra_ratelimit_interval =
7359 hdd_ctx->config->RArateLimitInterval;
7360 cds_cfg->is_ra_ratelimit_enabled =
7361 hdd_ctx->config->IsRArateLimitEnabled;
7362}
7363#else
Anand Kumar3b92a912016-12-05 12:01:26 +05307364static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307365 hdd_context_t *hdd_ctx)
7366{
7367}
7368#endif
7369
7370/**
7371 * hdd_update_cds_config() - API to update cds configuration parameters
7372 * @hdd_ctx: HDD Context
7373 *
7374 * Return: 0 for Success, errno on failure
7375 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007376static int hdd_update_cds_config(hdd_context_t *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307377{
7378 struct cds_config_info *cds_cfg;
7379
7380 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
7381 if (!cds_cfg) {
7382 hdd_err("failed to allocate cds config");
7383 return -ENOMEM;
7384 }
7385
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307386 cds_cfg->driver_type = DRIVER_TYPE_PRODUCTION;
7387 cds_cfg->powersave_offload_enabled =
7388 hdd_ctx->config->enablePowersaveOffload;
7389 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
7390 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
7391 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
7392 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
7393 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
7394
7395 /* Here ol_ini_info is used to store ini status of arp offload
7396 * ns offload and others. Currently 1st bit is used for arp
7397 * off load and 2nd bit for ns offload currently, rest bits are unused
7398 */
7399 if (hdd_ctx->config->fhostArpOffload)
7400 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
7401 if (hdd_ctx->config->fhostNSOffload)
7402 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
7403
7404 /*
7405 * Copy the DFS Phyerr Filtering Offload status.
7406 * This parameter reflects the value of the
7407 * dfs_phyerr_filter_offload flag as set in the ini.
7408 */
7409 cds_cfg->dfs_phyerr_filter_offload =
7410 hdd_ctx->config->fDfsPhyerrFilterOffload;
7411 if (hdd_ctx->config->ssdp)
7412 cds_cfg->ssdp = hdd_ctx->config->ssdp;
7413
7414 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
7415 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
7416
7417 cds_cfg->ap_maxoffload_reorderbuffs =
7418 hdd_ctx->config->apMaxOffloadReorderBuffs;
7419
7420 cds_cfg->ap_disable_intrabss_fwd =
7421 hdd_ctx->config->apDisableIntraBssFwd;
7422
7423 cds_cfg->dfs_pri_multiplier =
7424 hdd_ctx->config->dfsRadarPriMultiplier;
7425 cds_cfg->reorder_offload =
7426 hdd_ctx->config->reorderOffloadSupport;
7427
7428 /* IPA micro controller data path offload resource config item */
7429 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07007430 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
7431 /* IpaUcTxBufCount should be power of 2 */
7432 hdd_err("Round down IpaUcTxBufCount %d to nearest power of 2",
7433 hdd_ctx->config->IpaUcTxBufCount);
7434 hdd_ctx->config->IpaUcTxBufCount =
7435 rounddown_pow_of_two(
7436 hdd_ctx->config->IpaUcTxBufCount);
7437 if (!hdd_ctx->config->IpaUcTxBufCount) {
7438 hdd_err("Failed to round down IpaUcTxBufCount");
7439 return -EINVAL;
7440 }
7441 hdd_err("IpaUcTxBufCount rounded down to %d",
7442 hdd_ctx->config->IpaUcTxBufCount);
7443 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307444 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
7445 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07007446 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
7447 /* IpaUcRxIndRingCount should be power of 2 */
7448 hdd_err("Round down IpaUcRxIndRingCount %d to nearest power of 2",
7449 hdd_ctx->config->IpaUcRxIndRingCount);
7450 hdd_ctx->config->IpaUcRxIndRingCount =
7451 rounddown_pow_of_two(
7452 hdd_ctx->config->IpaUcRxIndRingCount);
7453 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
7454 hdd_err("Failed to round down IpaUcRxIndRingCount");
7455 return -EINVAL;
7456 }
7457 hdd_err("IpaUcRxIndRingCount rounded down to %d",
7458 hdd_ctx->config->IpaUcRxIndRingCount);
7459 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307460 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07007461 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307462 cds_cfg->uc_tx_partition_base =
7463 hdd_ctx->config->IpaUcTxPartitionBase;
7464 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
7465
7466 cds_cfg->ip_tcp_udp_checksum_offload =
7467 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05307468 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307469 cds_cfg->ce_classify_enabled =
7470 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07007471 cds_cfg->bpf_packet_filter_enable =
7472 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307473 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
7474 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
7475 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07007476 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07007477 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07007478 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07007479 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307480
7481 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
7482 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
7483 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07007484 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307485 cds_init_ini_config(cds_cfg);
7486 return 0;
7487}
7488
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007489/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08007490 * hdd_update_user_config() - API to update user configuration
7491 * parameters to obj mgr which are used by multiple components
7492 * @hdd_ctx: HDD Context
7493 *
7494 * Return: 0 for Success, errno on failure
7495 */
7496static int hdd_update_user_config(hdd_context_t *hdd_ctx)
7497{
7498 struct wlan_objmgr_psoc_user_config *user_config;
7499
7500 user_config = qdf_mem_malloc(sizeof(*user_config));
7501 if (user_config == NULL) {
7502 hdd_alert("Failed to alloc memory for user_config!");
7503 return -ENOMEM;
7504 }
7505
7506 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
7507 user_config->dual_mac_feature_disable =
7508 hdd_ctx->config->dual_mac_feature_disable;
7509 user_config->indoor_channel_support =
7510 hdd_ctx->config->indoor_channel_support;
7511 user_config->is_11d_support_enabled =
7512 hdd_ctx->config->Is11dSupportEnabled;
7513 user_config->is_11h_support_enabled =
7514 hdd_ctx->config->Is11hSupportEnabled;
7515 user_config->optimize_chan_avoid_event =
7516 hdd_ctx->config->goptimize_chan_avoid_event;
7517 user_config->skip_dfs_chnl_in_p2p_search =
7518 hdd_ctx->config->skipDfsChnlInP2pSearch;
7519
7520 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
7521
7522 qdf_mem_free(user_config);
7523 return 0;
7524}
7525
7526/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007527 * hdd_init_thermal_info - Initialize thermal level
7528 * @hdd_ctx: HDD context
7529 *
7530 * Initialize thermal level at SME layer and set the thermal level callback
7531 * which would be called when a configured thermal threshold is hit.
7532 *
7533 * Return: 0 on success and errno on failure
7534 */
7535static int hdd_init_thermal_info(hdd_context_t *hdd_ctx)
7536{
7537 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307538 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007539
7540 thermal_param.smeThermalMgmtEnabled =
7541 hdd_ctx->config->thermalMitigationEnable;
7542 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
7543
Poddar, Siddarth83905022016-04-16 17:56:08 -07007544 thermal_param.sme_throttle_duty_cycle_tbl[0] =
7545 hdd_ctx->config->throttle_dutycycle_level0;
7546 thermal_param.sme_throttle_duty_cycle_tbl[1] =
7547 hdd_ctx->config->throttle_dutycycle_level1;
7548 thermal_param.sme_throttle_duty_cycle_tbl[2] =
7549 hdd_ctx->config->throttle_dutycycle_level2;
7550 thermal_param.sme_throttle_duty_cycle_tbl[3] =
7551 hdd_ctx->config->throttle_dutycycle_level3;
7552
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007553 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
7554 hdd_ctx->config->thermalTempMinLevel0;
7555 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
7556 hdd_ctx->config->thermalTempMaxLevel0;
7557 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
7558 hdd_ctx->config->thermalTempMinLevel1;
7559 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
7560 hdd_ctx->config->thermalTempMaxLevel1;
7561 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
7562 hdd_ctx->config->thermalTempMinLevel2;
7563 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
7564 hdd_ctx->config->thermalTempMaxLevel2;
7565 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
7566 hdd_ctx->config->thermalTempMinLevel3;
7567 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
7568 hdd_ctx->config->thermalTempMaxLevel3;
7569
7570 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
7571
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307572 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05307573 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007574
7575 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
7576 hdd_set_thermal_level_cb);
7577
7578 return 0;
7579
7580}
7581
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007582#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
7583/**
7584 * hdd_hold_rtnl_lock - Hold RTNL lock
7585 *
7586 * Hold RTNL lock
7587 *
7588 * Return: True if held and false otherwise
7589 */
7590static inline bool hdd_hold_rtnl_lock(void)
7591{
7592 rtnl_lock();
7593 return true;
7594}
7595
7596/**
7597 * hdd_release_rtnl_lock - Release RTNL lock
7598 *
7599 * Release RTNL lock
7600 *
7601 * Return: None
7602 */
7603static inline void hdd_release_rtnl_lock(void)
7604{
7605 rtnl_unlock();
7606}
7607#else
7608static inline bool hdd_hold_rtnl_lock(void) { return false; }
7609static inline void hdd_release_rtnl_lock(void) { }
7610#endif
7611
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007612#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007613
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307614/* MAX iwpriv command support */
7615#define PKTLOG_SET_BUFF_SIZE 3
7616#define MAX_PKTLOG_SIZE 16
7617
7618/**
7619 * hdd_pktlog_set_buff_size() - set pktlog buffer size
7620 * @hdd_ctx: hdd context
7621 * @set_value2: pktlog buffer size value
7622 *
7623 *
7624 * Return: 0 for success or error.
7625 */
7626static int hdd_pktlog_set_buff_size(hdd_context_t *hdd_ctx, int set_value2)
7627{
7628 struct sir_wifi_start_log start_log = { 0 };
7629 QDF_STATUS status;
7630
7631 start_log.ring_id = RING_ID_PER_PACKET_STATS;
7632 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
7633 start_log.ini_triggered = cds_is_packet_log_enabled();
7634 start_log.user_triggered = 1;
7635 start_log.size = set_value2;
7636
7637 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
7638 if (!QDF_IS_STATUS_SUCCESS(status)) {
7639 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
7640 EXIT();
7641 return -EINVAL;
7642 }
7643
7644 return 0;
7645}
7646
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007647/**
7648 * hdd_process_pktlog_command() - process pktlog command
7649 * @hdd_ctx: hdd context
7650 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307651 * @set_value2: pktlog buffer size value
7652 *
7653 * This function process pktlog command.
7654 * set_value2 only matters when set_value is 3 (set buff size)
7655 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007656 *
7657 * Return: 0 for success or error.
7658 */
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307659int hdd_process_pktlog_command(hdd_context_t *hdd_ctx, uint32_t set_value,
7660 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007661{
7662 int ret;
7663 bool enable;
7664 uint8_t user_triggered = 0;
7665
7666 ret = wlan_hdd_validate_context(hdd_ctx);
7667 if (0 != ret)
7668 return ret;
7669
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307670 hdd_info("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007671
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307672 if (set_value > PKTLOG_SET_BUFF_SIZE) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007673 hdd_err("invalid pktlog value %d", set_value);
7674 return -EINVAL;
7675 }
7676
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307677 if (set_value == PKTLOG_SET_BUFF_SIZE) {
7678 if (set_value2 <= 0) {
7679 hdd_err("invalid pktlog size %d", set_value2);
7680 return -EINVAL;
7681 } else if (set_value2 > MAX_PKTLOG_SIZE) {
7682 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
7683 return -EINVAL;
7684 }
7685 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
7686 }
7687
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007688 /*
7689 * set_value = 0 then disable packetlog
7690 * set_value = 1 enable packetlog forcefully
7691 * set_vlaue = 2 then disable packetlog if disabled through ini or
7692 * enable packetlog with AUTO type.
7693 */
7694 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
7695 true : false;
7696
7697 if (1 == set_value) {
7698 enable = true;
7699 user_triggered = 1;
7700 }
7701
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307702 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007703}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007704/**
7705 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
7706 * @hdd_ctx: HDD context
7707 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307708 * @user_triggered: triggered through iwpriv
7709 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007710 *
7711 * Return: 0 on success; error number otherwise
7712 */
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007713int hdd_pktlog_enable_disable(hdd_context_t *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307714 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007715{
7716 struct sir_wifi_start_log start_log;
7717 QDF_STATUS status;
7718
7719 start_log.ring_id = RING_ID_PER_PACKET_STATS;
7720 start_log.verbose_level =
7721 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007722 start_log.ini_triggered = cds_is_packet_log_enabled();
7723 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307724 start_log.size = size;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05307725 /*
7726 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
7727 * commands. Host uses this flag to decide whether to send pktlog
7728 * disable command to fw without sending pktlog enable command
7729 * previously. For eg, If vendor sends pktlog disable command without
7730 * sending pktlog enable command, then host discards the packet
7731 * but for iwpriv command, host will send it to fw.
7732 */
7733 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007734 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
7735 if (!QDF_IS_STATUS_SUCCESS(status)) {
7736 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
7737 EXIT();
7738 return -EINVAL;
7739 }
7740
7741 return 0;
7742}
7743#endif /* REMOVE_PKT_LOG */
7744
7745
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05307746#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
7747/**
7748 * hdd_register_for_sap_restart_with_channel_switch() - Register for SAP channel
7749 * switch without restart
7750 *
7751 * Registers callback function to change the operating channel of SAP by using
7752 * channel switch announcements instead of restarting SAP.
7753 *
7754 * Return: QDF_STATUS
7755 */
7756QDF_STATUS hdd_register_for_sap_restart_with_channel_switch(void)
7757{
7758 QDF_STATUS status;
7759
7760 status = cds_register_sap_restart_channel_switch_cb(
7761 (void *)hdd_sap_restart_with_channel_switch);
7762 if (!QDF_IS_STATUS_SUCCESS(status))
7763 hdd_err("restart cb registration failed");
7764
7765 return status;
7766}
7767#endif
7768
Komal Seelam92fff912016-03-24 11:51:41 +05307769/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007770 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
7771 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05307772 * @dev: Device Pointer
7773 * @num: Number of Valid Mac address
7774 *
7775 * Return: Pointer to MAC address buffer
7776 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007777static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
7778 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05307779{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007780 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05307781}
Komal Seelam92fff912016-03-24 11:51:41 +05307782
7783/**
7784 * hdd_populate_random_mac_addr() - API to populate random mac addresses
7785 * @hdd_ctx: HDD Context
7786 * @num: Number of random mac addresses needed
7787 *
7788 * Generate random addresses using bit manipulation on the base mac address
7789 *
7790 * Return: None
7791 */
7792static void hdd_populate_random_mac_addr(hdd_context_t *hdd_ctx, uint32_t num)
7793{
7794 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
7795 uint32_t iter;
7796 struct hdd_config *ini = hdd_ctx->config;
7797 uint8_t *buf = NULL;
7798 uint8_t macaddr_b3, tmp_br3;
7799 uint8_t *src = ini->intfMacAddr[0].bytes;
7800
7801 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
7802 buf = ini->intfMacAddr[iter].bytes;
7803 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
7804 macaddr_b3 = buf[3];
7805 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
7806 INTF_MACADDR_MASK;
7807 macaddr_b3 += tmp_br3;
7808 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
7809 buf[0] |= 0x02;
7810 buf[3] = macaddr_b3;
Jeff Johnson34c88b72016-08-15 14:27:11 -07007811 hdd_info(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05307812 }
7813}
7814
7815/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007816 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05307817 * @hdd_ctx: HDD Context
7818 *
7819 * API to get mac addresses from platform driver and update the driver
7820 * structures and configure FW with the base mac address.
7821 * Return: int
7822 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007823static int hdd_platform_wlan_mac(hdd_context_t *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05307824{
7825 uint32_t no_of_mac_addr, iter;
7826 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
7827 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
7828 uint8_t *addr, *buf;
7829 struct device *dev = hdd_ctx->parent_dev;
7830 struct hdd_config *ini = hdd_ctx->config;
7831 tSirMacAddr mac_addr;
7832 QDF_STATUS status;
7833
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007834 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05307835
7836 if (no_of_mac_addr == 0 || !addr) {
7837 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
7838 return -EINVAL;
7839 }
7840
7841 if (no_of_mac_addr > max_mac_addr)
7842 no_of_mac_addr = max_mac_addr;
7843
7844 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
7845
7846 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
7847 buf = ini->intfMacAddr[iter].bytes;
7848 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Jeff Johnson34c88b72016-08-15 14:27:11 -07007849 hdd_info(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05307850 }
7851
7852 status = sme_set_custom_mac_addr(mac_addr);
7853
7854 if (!QDF_IS_STATUS_SUCCESS(status))
7855 return -EAGAIN;
7856 if (no_of_mac_addr < max_mac_addr)
7857 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
7858 no_of_mac_addr);
7859 return 0;
7860}
7861
7862/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07007863 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
7864 * @hdd_ctx: HDD Context
7865 *
7866 * Update MAC address to FW. If MAC address passed by FW is invalid, host
7867 * will generate its own MAC and update it to FW.
7868 *
7869 * Return: 0 for success
7870 * Non-zero error code for failure
7871 */
7872static int hdd_update_mac_addr_to_fw(hdd_context_t *hdd_ctx)
7873{
7874 tSirMacAddr customMacAddr;
7875 QDF_STATUS status;
7876
7877 qdf_mem_copy(&customMacAddr,
7878 &hdd_ctx->config->intfMacAddr[0].bytes[0],
7879 sizeof(tSirMacAddr));
7880 status = sme_set_custom_mac_addr(customMacAddr);
7881 if (!QDF_IS_STATUS_SUCCESS(status))
7882 return -EAGAIN;
7883 return 0;
7884}
7885
7886/**
Komal Seelam92fff912016-03-24 11:51:41 +05307887 * hdd_initialize_mac_address() - API to get wlan mac addresses
7888 * @hdd_ctx: HDD Context
7889 *
7890 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
7891 * is provisioned with mac addresses, driver uses it, else it will use
7892 * wlan_mac.bin to update HW MAC addresses.
7893 *
7894 * Return: None
7895 */
7896static void hdd_initialize_mac_address(hdd_context_t *hdd_ctx)
7897{
7898 QDF_STATUS status;
7899 int ret;
7900
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007901 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05307902 if (ret == 0)
7903 return;
7904
7905 hdd_warn("Can't update mac config via platform driver ret:%d", ret);
7906
7907 status = hdd_update_mac_config(hdd_ctx);
7908
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07007909 if (QDF_IS_STATUS_SUCCESS(status))
7910 return;
7911
7912 hdd_warn("can't update mac config via wlan_mac.bin, using MAC from ini file or auto-gen");
7913
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08007914 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07007915 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08007916 if (ret != 0) {
7917 hdd_err("MAC address out-of-sync, ret:%d", ret);
7918 QDF_ASSERT(ret);
7919 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07007920 }
Komal Seelam92fff912016-03-24 11:51:41 +05307921}
7922
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007923/**
Jeff Johnson89c66ff2016-04-22 15:21:37 -07007924 * hdd_tsf_init() - Initialize the TSF synchronization interface
7925 * @hdd_ctx: HDD global context
7926 *
7927 * When TSF synchronization via GPIO is supported by the driver and
7928 * has been enabled in the configuration file, this function plumbs
7929 * the GPIO value down to firmware via SME.
7930 *
7931 * Return: None
7932 */
7933#ifdef WLAN_FEATURE_TSF
7934static void hdd_tsf_init(hdd_context_t *hdd_ctx)
7935{
7936 QDF_STATUS status;
7937
7938 if (hdd_ctx->config->tsf_gpio_pin == TSF_GPIO_PIN_INVALID)
7939 return;
7940
7941 status = sme_set_tsf_gpio(hdd_ctx->hHal,
7942 hdd_ctx->config->tsf_gpio_pin);
7943 if (!QDF_IS_STATUS_SUCCESS(status))
7944 hdd_err("Set tsf GPIO failed, status: %d", status);
7945}
7946#else
7947static void hdd_tsf_init(hdd_context_t *hdd_ctx)
7948{
7949}
7950#endif
7951
Jeff Johnsona89e25d2017-02-24 12:25:07 -08007952static int hdd_set_smart_chainmask_enabled(hdd_context_t *hdd_ctx)
7953{
7954 int vdev_id = 0;
7955 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
7956 int value = hdd_ctx->config->smart_chainmask_enabled;
7957 int vpdev = PDEV_CMD;
7958 int ret;
7959
7960 ret = wma_cli_set_command(vdev_id, param_id, value, vpdev);
7961 if (ret)
7962 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
7963
7964 return ret;
7965}
7966
7967static int hdd_set_alternative_chainmask_enabled(hdd_context_t *hdd_ctx)
7968{
7969 int vdev_id = 0;
7970 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
7971 int value = hdd_ctx->config->alternative_chainmask_enabled;
7972 int vpdev = PDEV_CMD;
7973 int ret;
7974
7975 ret = wma_cli_set_command(vdev_id, param_id, value, vpdev);
7976 if (ret)
7977 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
7978 ret);
7979
7980 return ret;
7981}
7982
Jeff Johnson89c66ff2016-04-22 15:21:37 -07007983/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07007984 * hdd_pre_enable_configure() - Configurations prior to cds_enable
7985 * @hdd_ctx: HDD context
7986 *
7987 * Pre configurations to be done at lower layer before calling cds enable.
7988 *
7989 * Return: 0 on success and errno on failure.
7990 */
7991static int hdd_pre_enable_configure(hdd_context_t *hdd_ctx)
7992{
7993 int ret;
7994 QDF_STATUS status;
7995 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07007996 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07007997
Leo Changfdb45c32016-10-28 11:09:23 -07007998 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07007999 /*
8000 * Set 802.11p config
8001 * TODO-OCB: This has been temporarily added here to ensure this
8002 * parameter is set in CSR when we init the channel list. This should
8003 * be removed once the 5.9 GHz channels are added to the regulatory
8004 * domain.
8005 */
8006 hdd_set_dot11p_config(hdd_ctx);
8007
8008 /*
8009 * Note that the cds_pre_enable() sequence triggers the cfg download.
8010 * The cfg download must occur before we update the SME config
8011 * since the SME config operation must access the cfg database
8012 */
8013 status = hdd_set_sme_config(hdd_ctx);
8014
8015 if (QDF_STATUS_SUCCESS != status) {
8016 hdd_alert("Failed hdd_set_sme_config: %d", status);
8017 ret = qdf_status_to_os_return(status);
8018 goto out;
8019 }
8020
8021 ret = wma_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
8022 hdd_ctx->config->tx_chain_mask_1ss,
8023 PDEV_CMD);
8024 if (0 != ret) {
8025 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8026 goto out;
8027 }
8028
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008029 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8030 if (ret)
8031 goto out;
8032
8033 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8034 if (ret)
8035 goto out;
8036
Prashanth Bhatta07998752016-04-28 12:35:33 -07008037 hdd_program_country_code(hdd_ctx);
8038
8039 status = hdd_set_sme_chan_list(hdd_ctx);
8040 if (status != QDF_STATUS_SUCCESS) {
8041 hdd_alert("Failed to init channel list: %d", status);
8042 ret = qdf_status_to_os_return(status);
8043 goto out;
8044 }
8045
8046 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008047 if (!hdd_update_config_cfg(hdd_ctx)) {
Prashanth Bhatta07998752016-04-28 12:35:33 -07008048 hdd_alert("config update failed");
8049 ret = -EINVAL;
8050 goto out;
8051 }
8052
Prashanth Bhatta07998752016-04-28 12:35:33 -07008053 /*
8054 * Set the MAC Address Currently this is used by HAL to add self sta.
8055 * Remove this once self sta is added as part of session open.
8056 */
8057 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8058 hdd_ctx->config->intfMacAddr[0].bytes,
8059 sizeof(hdd_ctx->config->intfMacAddr[0]));
8060
8061 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8062 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8063 hal_status, hal_status);
8064 ret = -EINVAL;
8065 goto out;
8066 }
8067
8068 hdd_init_channel_avoidance(hdd_ctx);
8069
8070out:
8071 return ret;
8072}
8073
8074/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008075 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8076 * @context_ptr - hdd context pointer
8077 * @event_ptr - event structure pointer
8078 *
8079 * This is the p2p listen offload stop event handler, it sends vendor
8080 * event back to supplicant to notify the stop reason.
8081 *
8082 * Return: None
8083 */
8084static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8085 void *event_ptr)
8086{
8087 hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr;
8088 struct sir_p2p_lo_event *evt = event_ptr;
8089 struct sk_buff *vendor_event;
8090
8091 ENTER();
8092
8093 if (hdd_ctx == NULL) {
8094 hdd_err("Invalid HDD context pointer");
8095 return;
8096 }
8097
8098 vendor_event =
8099 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
8100 NULL, sizeof(uint32_t) + NLMSG_HDRLEN,
8101 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8102 GFP_KERNEL);
8103
8104 if (!vendor_event) {
8105 hdd_err("cfg80211_vendor_event_alloc failed");
8106 return;
8107 }
8108
8109 if (nla_put_u32(vendor_event,
8110 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8111 evt->reason_code)) {
8112 hdd_err("nla put failed");
8113 kfree_skb(vendor_event);
8114 return;
8115 }
8116
8117 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
8118}
8119
8120/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308121 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8122 * @hdd_ctx: HDD context
8123 *
8124 * This function sends the adaptive dwell time config configuration to the
8125 * firmware via WMA
8126 *
8127 * Return: 0 - success, < 0 - failure
8128 */
8129static int hdd_adaptive_dwelltime_init(hdd_context_t *hdd_ctx)
8130{
8131 QDF_STATUS status;
8132 struct adaptive_dwelltime_params dwelltime_params;
8133
8134 dwelltime_params.is_enabled =
8135 hdd_ctx->config->adaptive_dwell_mode_enabled;
8136 dwelltime_params.dwelltime_mode =
8137 hdd_ctx->config->global_adapt_dwelltime_mode;
8138 dwelltime_params.lpf_weight =
8139 hdd_ctx->config->adapt_dwell_lpf_weight;
8140 dwelltime_params.passive_mon_intval =
8141 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8142 dwelltime_params.wifi_act_threshold =
8143 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8144
8145 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8146 &dwelltime_params);
8147
8148 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8149 if (!QDF_IS_STATUS_SUCCESS(status)) {
8150 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8151 return -EAGAIN;
8152 }
8153 return 0;
8154}
8155
Arun Khandavallid4349a92016-07-25 11:10:43 +05308156#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8157/**
8158 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
8159 * @hdd_ctx: HDD context
8160 *
8161 * Set auto shutdown callback to get indications from firmware to indicate
8162 * userspace to shutdown WLAN after a configured amount of inactivity.
8163 *
8164 * Return: 0 on success and errno on failure.
8165 */
8166static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8167{
8168 QDF_STATUS status;
8169
8170 if (!hdd_ctx->config->WlanAutoShutdown)
8171 return 0;
8172
8173 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
8174 wlan_hdd_auto_shutdown_cb);
8175 if (status != QDF_STATUS_SUCCESS)
8176 hdd_err("Auto shutdown feature could not be enabled: %d",
8177 status);
8178
8179 return qdf_status_to_os_return(status);
8180}
8181#else
8182static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8183{
8184 return 0;
8185}
8186#endif
8187
8188/**
8189 * hdd_features_init() - Init features
8190 * @hdd_ctx: HDD context
8191 * @adapter: Primary adapter context
8192 *
8193 * Initialize features and their feature context after WLAN firmware is up.
8194 *
8195 * Return: 0 on success and errno on failure.
8196 */
8197static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8198{
8199 tSirTxPowerLimit hddtxlimit;
8200 QDF_STATUS status;
8201 int ret;
8202
8203 ENTER();
8204
8205 ret = hdd_update_country_code(hdd_ctx, adapter);
8206 if (ret) {
8207 hdd_err("Failed to update country code: %d", ret);
8208 goto out;
8209 }
8210
8211 /* FW capabilities received, Set the Dot11 mode */
8212 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07008213 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
8214 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308215
Arun Khandavallid4349a92016-07-25 11:10:43 +05308216
8217 if (hdd_ctx->config->fIsImpsEnabled)
8218 hdd_set_idle_ps_config(hdd_ctx, true);
8219 else
8220 hdd_set_idle_ps_config(hdd_ctx, false);
8221
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308222 if (hdd_ctx->config->enable_go_cts2self_for_sta)
8223 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
8224
Arun Khandavallid4349a92016-07-25 11:10:43 +05308225 if (hdd_lro_init(hdd_ctx))
8226 hdd_err("Unable to initialize LRO in fw");
8227
8228 if (hdd_adaptive_dwelltime_init(hdd_ctx))
8229 hdd_err("Unable to send adaptive dwelltime setting to FW");
8230
8231 ret = hdd_init_thermal_info(hdd_ctx);
8232 if (ret) {
8233 hdd_err("Error while initializing thermal information");
8234 goto deregister_frames;
8235 }
8236
Poddar, Siddarth66a46592017-02-22 11:44:44 +05308237 if (cds_is_packet_log_enabled())
8238 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
8239
Arun Khandavallid4349a92016-07-25 11:10:43 +05308240 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
8241 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
8242 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
8243 if (!QDF_IS_STATUS_SUCCESS(status))
8244 hdd_err("Error setting txlimit in sme: %d", status);
8245
8246 hdd_tsf_init(hdd_ctx);
8247
Arun Khandavallid4349a92016-07-25 11:10:43 +05308248 ret = hdd_register_cb(hdd_ctx);
8249 if (ret) {
8250 hdd_err("Failed to register HDD callbacks!");
8251 goto deregister_frames;
8252 }
8253
8254 if (hdd_ctx->config->dual_mac_feature_disable) {
8255 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
8256 if (status != QDF_STATUS_SUCCESS) {
8257 hdd_err("Failed to disable dual mac features");
8258 goto deregister_cb;
8259 }
8260 }
8261
8262 /* register P2P Listen Offload event callback */
8263 if (wma_is_p2p_lo_capable())
8264 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
8265 wlan_hdd_p2p_lo_event_callback);
8266
8267 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
8268
8269 if (ret)
8270 goto deregister_cb;
8271
8272 EXIT();
8273 return 0;
8274
8275deregister_cb:
8276 hdd_deregister_cb(hdd_ctx);
8277deregister_frames:
8278 wlan_hdd_cfg80211_deregister_frames(adapter);
8279out:
8280 return -EINVAL;
8281
8282}
8283
Abhishek Singh6092fbb2017-01-25 18:10:31 +05308284#ifdef NAPIER_SCAN
8285/**
8286 *
8287 * hdd_post_cds_enable_config() - HDD post cds start config helper
8288 * @adapter - Pointer to the HDD
8289 *
8290 * Return: None
8291 */
8292static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
8293{
8294 QDF_STATUS status;
8295
8296 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
8297 wlan_cfg80211_inform_bss_frame,
8298 SCAN_CB_TYPE_INFORM_BCN);
8299 if (!QDF_IS_STATUS_SUCCESS(status)) {
8300 hdd_err("failed with status code %08d [x%08x]",
8301 status, status);
8302 return status;
8303 }
8304
8305 return QDF_STATUS_SUCCESS;
8306}
8307#else
8308static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
8309{
8310 return QDF_STATUS_SUCCESS;
8311}
8312
8313#endif
Arun Khandavallid4349a92016-07-25 11:10:43 +05308314
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308315/**
Arun Khandavallifae92942016-08-01 13:31:08 +05308316 * hdd_configure_cds() - Configure cds modules
8317 * @hdd_ctx: HDD context
8318 * @adapter: Primary adapter context
8319 *
8320 * Enable Cds modules after WLAN firmware is up.
8321 *
8322 * Return: 0 on success and errno on failure.
8323 */
8324int hdd_configure_cds(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8325{
8326 int ret;
8327 QDF_STATUS status;
8328 /* structure of function pointers to be used by CDS */
8329 struct cds_sme_cbacks sme_cbacks;
8330
8331 ret = hdd_pre_enable_configure(hdd_ctx);
8332 if (ret) {
8333 hdd_err("Failed to pre-configure cds");
8334 goto out;
8335 }
8336
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08008337 /* Always get latest IPA resources allocated from cds_open and configure
8338 * IPA module before configuring them to FW. Sequence required as crash
8339 * observed otherwise.
8340 */
8341 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
8342 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
8343 hdd_err("Failed to setup pipes");
8344 goto out;
8345 }
8346 }
8347
Arun Khandavallifae92942016-08-01 13:31:08 +05308348 /*
8349 * Start CDS which starts up the SME/MAC/HAL modules and everything
8350 * else
8351 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308352 status = cds_enable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308353
8354 if (!QDF_IS_STATUS_SUCCESS(status)) {
8355 hdd_alert("cds_enable failed");
8356 goto out;
8357 }
8358
8359 status = hdd_post_cds_enable_config(hdd_ctx);
8360 if (!QDF_IS_STATUS_SUCCESS(status)) {
8361 hdd_alert("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008362 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05308363 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05308364 status = hdd_register_bcn_cb(hdd_ctx);
8365 if (!QDF_IS_STATUS_SUCCESS(status)) {
8366 hdd_alert("hdd_post_cds_enable_config failed");
8367 goto cds_disable;
8368 }
Arun Khandavallifae92942016-08-01 13:31:08 +05308369
8370 ret = hdd_features_init(hdd_ctx, adapter);
8371 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008372 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05308373
8374 sme_cbacks.sme_get_valid_channels = sme_get_cfg_valid_channels;
8375 sme_cbacks.sme_get_nss_for_vdev = sme_get_vdev_type_nss;
8376 status = cds_init_policy_mgr(&sme_cbacks);
8377 if (!QDF_IS_STATUS_SUCCESS(status)) {
8378 hdd_err("Policy manager initialization failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008379 goto hdd_features_deinit;
Arun Khandavallifae92942016-08-01 13:31:08 +05308380 }
8381
8382 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008383
8384hdd_features_deinit:
8385 hdd_deregister_cb(hdd_ctx);
8386 wlan_hdd_cfg80211_deregister_frames(adapter);
8387cds_disable:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308388 cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008389
Arun Khandavallifae92942016-08-01 13:31:08 +05308390out:
8391 return -EINVAL;
8392}
8393
8394/**
8395 * hdd_deconfigure_cds() -De-Configure cds
8396 * @hdd_ctx: HDD context
8397 *
8398 * Deconfigure Cds modules before WLAN firmware is down.
8399 *
8400 * Return: 0 on success and errno on failure.
8401 */
Jeff Johnson590e2012016-10-05 16:16:24 -07008402static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05308403{
8404 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07008405 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05308406
8407 ENTER();
8408 /* De-register the SME callbacks */
8409 hdd_deregister_cb(hdd_ctx);
8410
8411 /* De-init Policy Manager */
8412 if (!QDF_IS_STATUS_SUCCESS(cds_deinit_policy_mgr())) {
8413 hdd_err("Failed to deinit policy manager");
8414 /* Proceed and complete the clean up */
Houston Hoffman6640cf32016-10-10 16:44:29 -07008415 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308416 }
8417
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308418 qdf_status = cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308419 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8420 hdd_err("Failed to Disable the CDS Modules! :%d",
8421 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07008422 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308423 }
8424
8425 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07008426 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05308427}
8428
8429
8430/**
8431 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
8432 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05308433 *
8434 * This function maintains the driver state machine it will be invoked from
8435 * exit, shutdown and con_mode change handler. Depending on the driver state
8436 * shall perform the stopping/closing of the modules.
8437 *
8438 * Return: 0 for success; non-zero for failure
8439 */
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07008440int hdd_wlan_stop_modules(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05308441{
8442 void *hif_ctx;
8443 qdf_device_t qdf_ctx;
8444 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308445 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05308446 p_cds_sched_context cds_sched_context = NULL;
8447
8448 ENTER();
8449
8450 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
8451 if (!qdf_ctx) {
8452 hdd_err("QDF device context NULL");
8453 return -EINVAL;
8454 }
8455
8456 cds_sched_context = get_cds_sched_ctxt();
8457 if (!cds_sched_context) {
8458 hdd_err("cds scheduler context NULL");
8459 return -EINVAL;
8460 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308461 mutex_lock(&hdd_ctx->iface_change_lock);
8462 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05308463
8464 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
8465
8466 switch (hdd_ctx->driver_status) {
8467 case DRIVER_MODULES_UNINITIALIZED:
8468 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308469 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308470 case DRIVER_MODULES_CLOSED:
8471 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308472 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308473 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05308474 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05308475 if (hdd_deconfigure_cds(hdd_ctx)) {
8476 hdd_alert("Failed to de-configure CDS");
8477 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308478 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308479 }
8480 hdd_info("successfully Disabled the CDS modules!");
8481 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
8482 break;
8483 case DRIVER_MODULES_OPENED:
8484 hdd_info("Closing CDS modules!");
8485 break;
8486 default:
8487 hdd_err("Trying to stop wlan in a wrong state: %d",
8488 hdd_ctx->driver_status);
8489 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308490 ret = -EINVAL;
8491 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308492 }
8493
Govind Singhb048e872016-09-27 22:07:43 +05308494 qdf_status = cds_post_disable(hdd_ctx->pcds_context);
8495 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8496 hdd_err("Failed to process post CDS disable Modules! :%d",
8497 qdf_status);
8498 ret = -EINVAL;
8499 QDF_ASSERT(0);
8500 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308501 qdf_status = cds_close(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308502 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8503 hdd_warn("Failed to stop CDS:%d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05308504 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308505 QDF_ASSERT(0);
8506 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07008507
Rajeev Kumarecf87ff2017-01-13 15:46:07 -08008508 ret = hdd_release_and_destroy_pdev(hdd_ctx);
8509 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308510 hdd_err("Pdev delete failed");
8511
Rajeev Kumar99e4cf62017-01-13 15:31:19 -08008512 ret = hdd_release_and_destroy_psoc(hdd_ctx);
8513 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308514 hdd_err("Psoc delete failed");
8515
Arun Khandavallifae92942016-08-01 13:31:08 +05308516 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
8517 if (!hif_ctx) {
8518 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308519 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308520 }
8521
8522 hdd_hif_close(hif_ctx);
8523
8524 ol_cds_free();
8525
Arunk Khandavalli649c0092016-11-22 21:20:43 +05308526 if (!cds_is_driver_recovering() && !cds_is_driver_unloading()) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308527 ret = pld_power_off(qdf_ctx->dev);
8528 if (ret)
8529 hdd_err("CNSS power down failed put device into Low power mode:%d",
8530 ret);
8531 }
8532 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
8533
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308534done:
8535 hdd_ctx->stop_modules_in_progress = false;
8536 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05308537 EXIT();
8538
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308539 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05308540
8541}
8542
8543/**
8544 * hdd_iface_change_callback() - Function invoked when stop modules expires
8545 * @priv: pointer to hdd context
8546 *
8547 * This function is invoked when the timer waiting for the interface change
8548 * expires, it shall cut-down the power to wlan and stop all the modules.
8549 *
8550 * Return: void
8551 */
8552static void hdd_iface_change_callback(void *priv)
8553{
8554 hdd_context_t *hdd_ctx = (hdd_context_t *) priv;
8555 int ret;
8556 int status = wlan_hdd_validate_context(hdd_ctx);
8557
8558 if (status)
8559 return;
8560
8561 ENTER();
8562 hdd_info("Interface change timer expired close the modules!");
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07008563 ret = hdd_wlan_stop_modules(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05308564 if (ret)
8565 hdd_alert("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05308566 EXIT();
8567}
8568
8569/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05308570 * hdd_state_info_dump() - prints state information of hdd layer
8571 * @buf: buffer pointer
8572 * @size: size of buffer to be filled
8573 *
8574 * This function is used to dump state information of hdd layer
8575 *
8576 * Return: None
8577 */
8578static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
8579{
8580 hdd_context_t *hdd_ctx;
8581 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
8582 QDF_STATUS status;
8583 hdd_station_ctx_t *hdd_sta_ctx;
8584 hdd_adapter_t *adapter;
8585 uint16_t len = 0;
8586 char *buf = *buf_ptr;
8587
8588 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8589 if (!hdd_ctx) {
8590 hdd_err("Failed to get hdd context ");
8591 return;
8592 }
8593
8594 hdd_notice("size of buffer: %d", *size);
8595
8596 len += scnprintf(buf + len, *size - len,
8597 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
8598 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08008599 "\n is_scheduler_suspended %d",
8600 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05308601
8602 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
8603
8604 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
8605 adapter = adapter_node->pAdapter;
8606 if (adapter->dev)
8607 len += scnprintf(buf + len, *size - len,
8608 "\n device name: %s", adapter->dev->name);
8609 len += scnprintf(buf + len, *size - len,
8610 "\n device_mode: %d", adapter->device_mode);
8611 switch (adapter->device_mode) {
8612 case QDF_STA_MODE:
8613 case QDF_P2P_CLIENT_MODE:
8614 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
8615 len += scnprintf(buf + len, *size - len,
8616 "\n connState: %d",
8617 hdd_sta_ctx->conn_info.connState);
8618 break;
8619
8620 default:
8621 break;
8622 }
8623 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
8624 adapter_node = next;
8625 }
8626
8627 *size -= len;
8628 *buf_ptr += len;
8629}
8630
8631/**
8632 * hdd_register_debug_callback() - registration function for hdd layer
8633 * to print hdd state information
8634 *
8635 * Return: None
8636 */
8637static void hdd_register_debug_callback(void)
8638{
8639 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
8640}
8641
8642/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008643 * hdd_wlan_startup() - HDD init function
8644 * @dev: Pointer to the underlying device
8645 *
8646 * This is the driver startup code executed once a WLAN device has been detected
8647 *
8648 * Return: 0 for success, < 0 for failure
8649 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308650int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008651{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308652 QDF_STATUS status;
Jeff Johnson957bc272017-02-02 08:54:48 -08008653 hdd_context_t *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008654 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008655 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05308656 int set_value;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008657
8658 ENTER();
8659
Arun Khandavallifae92942016-08-01 13:31:08 +05308660 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008661
8662 if (IS_ERR(hdd_ctx))
8663 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008664
Arun Khandavallifae92942016-08-01 13:31:08 +05308665 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
8666 hdd_iface_change_callback, (void *)hdd_ctx);
8667
8668 mutex_init(&hdd_ctx->iface_change_lock);
8669
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008670 ret = hdd_init_netlink_services(hdd_ctx);
8671 if (ret)
8672 goto err_hdd_free_context;
8673
Jeff Johnsonce0032c2017-01-20 07:18:27 -08008674 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07008675 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05308676
Jeff Johnson957bc272017-02-02 08:54:48 -08008677 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05308678 if (ret) {
8679 hdd_alert("Failed to start modules: %d", ret);
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008680 goto err_exit_nl_srv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008681 }
8682
Yingying Tang80e15f32016-09-27 18:23:01 +08008683 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008684
Yingying Tang95409972016-10-20 15:16:15 +08008685 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
8686 hdd_notice("Failed to set wow pulse");
8687
Anurag Chouhan6d760662016-02-20 16:05:43 +05308688 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008689
8690 if (NULL == hdd_ctx->hHal) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07008691 hdd_alert("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05308692 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008693 }
8694
Prashanth Bhatta07998752016-04-28 12:35:33 -07008695 ret = hdd_wiphy_init(hdd_ctx);
8696 if (ret) {
8697 hdd_alert("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05308698 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008699 }
8700
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05308701 if (hdd_ctx->config->enable_dp_trace)
8702 qdf_dp_trace_init();
8703
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308704 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008705 goto err_wiphy_unregister;
8706
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05308707 wlan_hdd_init_chan_info(hdd_ctx);
8708
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07008709 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08008710
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008711 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008712
Jeff Johnson957bc272017-02-02 08:54:48 -08008713 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
8714 if (ret) {
8715 hdd_alert("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08008716 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008717 }
8718
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008719 hdd_release_rtnl_lock();
8720 rtnl_held = false;
8721
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08008722 wlan_hdd_update_11n_mode(hdd_ctx->config);
8723
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008724#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05308725 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05308726 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008727 hdd_skip_acs_scan_timer_handler,
8728 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308729 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07008730 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04008731 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008732#endif
8733
Nitesh Shah61c10d92016-10-19 19:29:15 +05308734 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
8735 QDF_TIMER_TYPE_SW,
8736 wlan_hdd_change_tdls_mode,
8737 hdd_ctx);
8738
Prashanth Bhattaab004382016-10-11 16:08:11 -07008739 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008740
Jeff Johnson9afc5012016-09-23 13:56:27 -07008741 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008742
Nirav Shahbd36b062016-07-18 11:12:59 +05308743 if (hdd_ctx->rps)
8744 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07008745
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07008746 ret = hdd_register_notifiers(hdd_ctx);
8747 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008748 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05308749
8750 status = wlansap_global_init();
8751 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08008752 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07008753
Komal Seelam8634b772016-09-29 12:12:24 +05308754 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08008755 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05308756 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08008757
bings612b9c42016-11-07 10:52:03 +08008758 if (hdd_enable_egap(hdd_ctx))
8759 hdd_err("enhance green ap is not enabled");
8760
Arun Khandavallifae92942016-08-01 13:31:08 +05308761 if (hdd_ctx->config->fIsImpsEnabled)
8762 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308763
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05308764 if (hdd_ctx->config->sifs_burst_duration) {
8765 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
8766 hdd_ctx->config->sifs_burst_duration;
8767
8768 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
8769 wma_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
8770 set_value, PDEV_CMD);
8771 }
8772
Arun Khandavallifae92942016-08-01 13:31:08 +05308773 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
8774 hdd_ctx->config->iface_change_wait_time * 5000);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05308775
8776 if (hdd_ctx->config->goptimize_chan_avoid_event) {
8777 status = sme_enable_disable_chanavoidind_event(
8778 hdd_ctx->hHal, 0);
8779 if (!QDF_IS_STATUS_SUCCESS(status))
8780 hdd_err("Failed to disable Chan Avoidance Indication");
8781 }
Arun Khandavalli13cb5da2017-01-19 15:43:52 +05308782 complete(&wlan_start_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008783 goto success;
8784
Jeff Johnson957bc272017-02-02 08:54:48 -08008785err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08008786 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008787
Jeff Johnson46bde382017-02-01 15:31:16 -08008788err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05308789 if (rtnl_held)
8790 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008791
Anurag Chouhance6a4052016-09-14 18:20:42 +05308792 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08008793
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008794err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008795 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008796
Arun Khandavallifae92942016-08-01 13:31:08 +05308797err_stop_modules:
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07008798 hdd_wlan_stop_modules(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05308799
8800
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008801 status = cds_sched_close(hdd_ctx->pcds_context);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308802 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07008803 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05308804 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008805 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008806
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008807err_exit_nl_srv:
Houston Hoffman47a4a052016-11-14 23:22:44 -08008808 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08008809 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008810 hdd_exit_netlink_services(hdd_ctx);
8811
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308812 cds_deinit_ini_config();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008813err_hdd_free_context:
Arun Khandavallifae92942016-08-01 13:31:08 +05308814 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
8815 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008816 hdd_context_destroy(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05308817 QDF_BUG(1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008819 return -EIO;
8820
8821success:
8822 EXIT();
8823 return 0;
8824}
8825
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008826/**
Arun Khandavallifae92942016-08-01 13:31:08 +05308827 * hdd_wlan_update_target_info() - update target type info
8828 * @hdd_ctx: HDD context
8829 * @context: hif context
8830 *
8831 * Update target info received from firmware in hdd context
8832 * Return:None
8833 */
8834
8835void hdd_wlan_update_target_info(hdd_context_t *hdd_ctx, void *context)
8836{
8837 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
8838
8839 if (!tgt_info) {
8840 hdd_err("Target info is Null");
8841 return;
8842 }
8843
8844 hdd_ctx->target_type = tgt_info->target_type;
8845}
8846
8847/**
8848 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308849 * @hdd_ctx: HDD context
8850 *
8851 * Register the HDD callbacks to CDS/SME.
8852 *
8853 * Return: 0 for success or Error code for failure
8854 */
8855int hdd_register_cb(hdd_context_t *hdd_ctx)
8856{
8857 QDF_STATUS status;
8858 int ret = 0;
8859
8860 ENTER();
8861
8862 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
8863
8864 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
8865 hdd_send_oem_data_rsp_msg);
8866
8867 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
8868 wlan_hdd_cfg80211_fw_mem_dump_cb);
8869 if (!QDF_IS_STATUS_SUCCESS(status)) {
8870 hdd_err("Failed to register memdump callback");
8871 ret = -EINVAL;
8872 return ret;
8873 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05308874 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
8875 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308876 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
8877 sme_nan_register_callback(hdd_ctx->hHal,
8878 wlan_hdd_cfg80211_nan_callback);
8879 sme_stats_ext_register_callback(hdd_ctx->hHal,
8880 wlan_hdd_cfg80211_stats_ext_callback);
8881
8882 sme_ext_scan_register_callback(hdd_ctx->hHal,
8883 wlan_hdd_cfg80211_extscan_callback);
8884
8885 status = cds_register_sap_restart_channel_switch_cb(
8886 (void *)hdd_sap_restart_with_channel_switch);
8887 if (!QDF_IS_STATUS_SUCCESS(status)) {
8888 hdd_err("restart cb registration failed");
8889 ret = -EINVAL;
8890 return ret;
8891 }
8892
8893 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
8894 hdd_rssi_threshold_breached);
8895
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308896 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
8897 wlan_hdd_cfg80211_link_layer_stats_callback);
8898
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05308899 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
8900 hdd_lost_link_info_cb);
8901 /* print error and not block the startup process */
8902 if (!QDF_IS_STATUS_SUCCESS(status))
8903 hdd_err("set lost link info callback failed");
8904
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308905 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
8906
8907 EXIT();
8908
8909 return ret;
8910}
8911
8912/**
8913 * hdd_deregister_cb() - De-Register HDD callbacks.
8914 * @hdd_ctx: HDD context
8915 *
8916 * De-Register the HDD callbacks to CDS/SME.
8917 *
8918 * Return: void
8919 */
8920void hdd_deregister_cb(hdd_context_t *hdd_ctx)
8921{
8922 QDF_STATUS status;
8923
8924 ENTER();
8925
8926 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
8927 if (!QDF_IS_STATUS_SUCCESS(status))
8928 hdd_err("De-register of dcc stats callback failed: %d",
8929 status);
8930
8931 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308932 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
8933
8934 status = cds_deregister_sap_restart_channel_switch_cb();
8935 if (!QDF_IS_STATUS_SUCCESS(status))
8936 hdd_err("De-register restart cb registration failed: %d",
8937 status);
8938
8939 sme_stats_ext_register_callback(hdd_ctx->hHal,
8940 wlan_hdd_cfg80211_stats_ext_callback);
8941
8942 sme_nan_deregister_callback(hdd_ctx->hHal);
8943 status = sme_reset_tsfcb(hdd_ctx->hHal);
8944 if (!QDF_IS_STATUS_SUCCESS(status))
8945 hdd_err("Failed to de-register tsfcb the callback:%d",
8946 status);
8947 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
8948 if (!QDF_IS_STATUS_SUCCESS(status))
8949 hdd_err("Failed to de-register the fw mem dump callback: %d",
8950 status);
8951
8952 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
8953 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
8954
8955 EXIT();
8956}
8957
8958/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008959 * hdd_softap_sta_deauth() - handle deauth req from HDD
8960 * @adapter: Pointer to the HDD
8961 * @enable: bool value
8962 *
8963 * This to take counter measure to handle deauth req from HDD
8964 *
8965 * Return: None
8966 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308967QDF_STATUS hdd_softap_sta_deauth(hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008968 struct tagCsrDelStaParams *pDelStaParams)
8969{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308970 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008971
8972 ENTER();
8973
Jeff Johnson34c88b72016-08-15 14:27:11 -07008974 hdd_notice("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008975 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
8976
8977 /* Ignore request to deauth bcmc station */
8978 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308979 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008980
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308981 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008982 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8983 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008984
8985 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308986 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008987}
8988
8989/**
8990 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
8991 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05308992 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008993 *
8994 * This to take counter measure to handle deauth req from HDD
8995 *
8996 * Return: None
8997 */
8998void hdd_softap_sta_disassoc(hdd_adapter_t *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05308999 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009000{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009001 ENTER();
9002
Jeff Johnson34c88b72016-08-15 14:27:11 -07009003 hdd_err("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009004 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9005
9006 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309007 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009008 return;
9009
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009010 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309011 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009012}
9013
9014void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *adapter,
9015 bool enable)
9016{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009017 ENTER();
9018
Jeff Johnson34c88b72016-08-15 14:27:11 -07009019 hdd_err("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009020 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9021
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009022 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9023 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009024}
9025
9026/**
9027 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
9028 * @hdd_ctx: HDD Context
9029 *
9030 * API to find if there is any STA or P2P-Client is connected
9031 *
9032 * Return: true if connected; false otherwise
9033 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309034QDF_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009035{
9036 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
9037}
9038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009039/**
9040 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
9041 * @adapter: HDD adapter pointer
9042 *
9043 * This function loop through each adapter and disable roaming on each STA
9044 * device mode except the input adapter.
9045 *
9046 * Note: On the input adapter roaming is not enabled yet hence no need to
9047 * disable.
9048 *
9049 * Return: None
9050 */
9051void wlan_hdd_disable_roaming(hdd_adapter_t *adapter)
9052{
9053 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9054 hdd_adapter_t *adapterIdx = NULL;
9055 hdd_adapter_list_node_t *adapterNode = NULL;
9056 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309057 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009058
9059 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
9060 hdd_ctx->config->isRoamOffloadScanEnabled &&
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009061 QDF_STA_MODE == adapter->device_mode &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009062 cds_is_sta_active_connection_exists()) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009063 hdd_notice("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009064 adapter->sessionId);
9065 /*
9066 * Loop through adapter and disable roaming for each STA device
9067 * mode except the input adapter.
9068 */
9069 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9070
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309071 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009072 adapterIdx = adapterNode->pAdapter;
9073
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009074 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009075 && adapter->sessionId != adapterIdx->sessionId) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009076 hdd_notice("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009077 adapterIdx->sessionId);
9078 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
9079 (adapterIdx),
9080 adapterIdx->sessionId, 0);
9081 }
9082
9083 status = hdd_get_next_adapter(hdd_ctx,
9084 adapterNode,
9085 &pNext);
9086 adapterNode = pNext;
9087 }
9088 }
9089}
9090
9091/**
9092 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
9093 * @adapter: HDD adapter pointer
9094 *
9095 * This function loop through each adapter and enable roaming on each STA
9096 * device mode except the input adapter.
9097 * Note: On the input adapter no need to enable roaming because link got
9098 * disconnected on this.
9099 *
9100 * Return: None
9101 */
9102void wlan_hdd_enable_roaming(hdd_adapter_t *adapter)
9103{
9104 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9105 hdd_adapter_t *adapterIdx = NULL;
9106 hdd_adapter_list_node_t *adapterNode = NULL;
9107 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309108 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009109
9110 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
9111 hdd_ctx->config->isRoamOffloadScanEnabled &&
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009112 QDF_STA_MODE == adapter->device_mode &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009113 cds_is_sta_active_connection_exists()) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009114 hdd_notice("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009115 adapter->sessionId);
9116 /*
9117 * Loop through adapter and enable roaming for each STA device
9118 * mode except the input adapter.
9119 */
9120 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9121
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309122 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009123 adapterIdx = adapterNode->pAdapter;
9124
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009125 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009126 && adapter->sessionId != adapterIdx->sessionId) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009127 hdd_notice("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009128 adapterIdx->sessionId);
9129 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
9130 (adapterIdx),
9131 adapterIdx->sessionId,
9132 REASON_CONNECT);
9133 }
9134
9135 status = hdd_get_next_adapter(hdd_ctx,
9136 adapterNode,
9137 &pNext);
9138 adapterNode = pNext;
9139 }
9140 }
9141}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009142
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309143void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009144{
9145 struct sk_buff *skb;
9146 struct nlmsghdr *nlh;
9147 tAniMsgHdr *ani_hdr;
9148 void *nl_data = NULL;
9149 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309150 struct radio_index_tlv *radio_info;
9151 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009152
9153 if (in_interrupt() || irqs_disabled() || in_atomic())
9154 flags = GFP_ATOMIC;
9155
9156 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
9157
9158 if (skb == NULL) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009159 hdd_err("alloc_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009160 return;
9161 }
9162
9163 nlh = (struct nlmsghdr *)skb->data;
9164 nlh->nlmsg_pid = 0; /* from kernel */
9165 nlh->nlmsg_flags = 0;
9166 nlh->nlmsg_seq = 0;
9167 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
9168
9169 ani_hdr = NLMSG_DATA(nlh);
9170 ani_hdr->type = type;
9171
9172 switch (type) {
9173 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +05309174 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009175 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009176 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -07009177 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009178 ani_hdr->length = 0;
9179 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009180 break;
9181 case WLAN_SVC_WLAN_STATUS_IND:
9182 case WLAN_SVC_WLAN_VERSION_IND:
9183 case WLAN_SVC_DFS_CAC_START_IND:
9184 case WLAN_SVC_DFS_CAC_END_IND:
9185 case WLAN_SVC_DFS_RADAR_DETECT_IND:
9186 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
9187 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -08009188 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +05309189 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009190 ani_hdr->length = len;
9191 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
9192 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
9193 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009194 break;
9195
9196 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -07009197 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009198 type);
9199 kfree_skb(skb);
9200 return;
9201 }
9202
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309203 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08009204 * Add radio index at the end of the svc event in TLV format
9205 * to maintain the backward compatibility with userspace
9206 * applications.
9207 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309208
9209 tlv_len = 0;
9210
9211 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
9212 < WLAN_NL_MAX_PAYLOAD) {
9213 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
9214 sizeof(*ani_hdr) + len);
9215 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
9216 radio_info->length = (unsigned short) sizeof(radio_info->radio);
9217 radio_info->radio = radio;
9218 tlv_len = sizeof(*radio_info);
9219 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
9220 "Added radio index tlv - radio index %d",
9221 radio_info->radio);
9222 }
9223
9224 nlh->nlmsg_len += tlv_len;
9225 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
9226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009227 nl_srv_bcast(skb);
9228
9229 return;
9230}
9231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009232#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9233void wlan_hdd_auto_shutdown_cb(void)
9234{
Mahesh Kumar Kalikot Veetild214d552016-09-14 15:15:49 -07009235 hdd_context_t *hdd_ctx = cds_get_global_context();
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309236
9237 if (!hdd_ctx)
9238 return;
9239
Jeff Johnson28f8a772016-08-15 15:30:36 -07009240 hdd_err("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309241 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
9242 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009243}
9244
9245void wlan_hdd_auto_shutdown_enable(hdd_context_t *hdd_ctx, bool enable)
9246{
9247 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309248 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009249 hdd_adapter_t *adapter;
9250 bool ap_connected = false, sta_connected = false;
9251 tHalHandle hal_handle;
9252
9253 hal_handle = hdd_ctx->hHal;
9254 if (hal_handle == NULL)
9255 return;
9256
9257 if (hdd_ctx->config->WlanAutoShutdown == 0)
9258 return;
9259
9260 if (enable == false) {
9261 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309262 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009263 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009264 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309265 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -07009266 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009267 return;
9268 }
9269
9270 /* To enable shutdown timer check conncurrency */
9271 if (cds_concurrent_open_sessions_running()) {
9272 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9273
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309274 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009275 adapter = adapterNode->pAdapter;
9276 if (adapter
9277 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009278 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009279 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
9280 conn_info.connState ==
9281 eConnectionState_Associated) {
9282 sta_connected = true;
9283 break;
9284 }
9285 }
9286 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009287 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009288 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
9289 bApActive == true) {
9290 ap_connected = true;
9291 break;
9292 }
9293 }
9294 status = hdd_get_next_adapter(hdd_ctx,
9295 adapterNode,
9296 &pNext);
9297 adapterNode = pNext;
9298 }
9299 }
9300
9301 if (ap_connected == true || sta_connected == true) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009302 hdd_notice("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009303 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009304 }
Jeff Johnson68755312017-02-10 11:46:55 -08009305
9306 if (sme_set_auto_shutdown_timer(hal_handle,
9307 hdd_ctx->config->WlanAutoShutdown)
9308 != QDF_STATUS_SUCCESS)
9309 hdd_err("Failed to start wlan auto shutdown timer");
9310 else
9311 hdd_notice("Auto Shutdown timer for %d seconds enabled",
9312 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009313}
9314#endif
9315
9316hdd_adapter_t *hdd_get_con_sap_adapter(hdd_adapter_t *this_sap_adapter,
9317 bool check_start_bss)
9318{
9319 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
9320 hdd_adapter_t *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309321 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009322 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
9323
9324 con_sap_adapter = NULL;
9325
9326 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309327 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009328 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009329 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
9330 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009331 adapter != this_sap_adapter) {
9332 if (check_start_bss) {
9333 if (test_bit(SOFTAP_BSS_STARTED,
9334 &adapter->event_flags)) {
9335 con_sap_adapter = adapter;
9336 break;
9337 }
9338 } else {
9339 con_sap_adapter = adapter;
9340 break;
9341 }
9342 }
9343 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
9344 adapterNode = pNext;
9345 }
9346
9347 return con_sap_adapter;
9348}
9349
9350#ifdef MSM_PLATFORM
9351void hdd_start_bus_bw_compute_timer(hdd_adapter_t *adapter)
9352{
9353 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9354
Dustin Brownfce08d12017-01-17 16:29:38 -08009355 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
9356 if (!hdd_ctx->bus_bw_timer_running) {
9357 hdd_ctx->bus_bw_timer_running = true;
9358 qdf_timer_start(&hdd_ctx->bus_bw_timer,
9359 hdd_ctx->config->busBandwidthComputeInterval);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009360
Dustin Brownfce08d12017-01-17 16:29:38 -08009361 }
9362 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
9363
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009364}
9365
9366void hdd_stop_bus_bw_compute_timer(hdd_adapter_t *adapter)
9367{
9368 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309369 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009370 bool can_stop = true;
9371 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9372
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309373 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brownfce08d12017-01-17 16:29:38 -08009374 if (!hdd_ctx->bus_bw_timer_running) {
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309375 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009376 /* trying to stop timer, when not running is not good */
Srinivas Girigowda0ee96442016-08-17 19:10:56 -07009377 hdd_info("bus band width compute timer is not running");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009378 return;
9379 }
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309380 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009381
9382 if (cds_concurrent_open_sessions_running()) {
9383 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9384
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309385 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009386 adapter = adapterNode->pAdapter;
9387 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009388 && (adapter->device_mode == QDF_STA_MODE
9389 || adapter->device_mode == QDF_P2P_CLIENT_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009390 && WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
9391 conn_info.connState ==
9392 eConnectionState_Associated) {
9393 can_stop = false;
9394 break;
9395 }
9396 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009397 && (adapter->device_mode == QDF_SAP_MODE
9398 || adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009399 && WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive ==
9400 true) {
9401 can_stop = false;
9402 break;
9403 }
9404 status = hdd_get_next_adapter(hdd_ctx,
9405 adapterNode,
9406 &pNext);
9407 adapterNode = pNext;
9408 }
9409 }
9410
Ravi Joshib89e7f72016-09-07 13:43:15 -07009411 if (can_stop == true) {
Chris Guoc0c95bf2016-11-10 14:28:25 +08009412 /* reset the ipa perf level */
9413 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
Dustin Brownfce08d12017-01-17 16:29:38 -08009414 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05309415 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08009416 hdd_ctx->bus_bw_timer_running = false;
9417 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Ravi Joshib89e7f72016-09-07 13:43:15 -07009418 hdd_reset_tcp_delack(hdd_ctx);
9419 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009420}
9421#endif
9422
9423/**
9424 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
9425 * and sta's operating channel.
9426 * @sta_adapter: Describe the first argument to foobar.
9427 * @ap_adapter: Describe the second argument to foobar.
9428 * @roam_profile: Roam profile of AP to which STA wants to connect.
9429 * @concurrent_chnl_same: If both SAP and STA channels are same then
9430 * set this flag to true else false.
9431 *
9432 * This function checks the sap's operating channel and sta's operating channel.
9433 * if both are same then it will return false else it will restart the sap in
9434 * sta's channel and return true.
9435 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309436 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009437 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309438QDF_STATUS wlan_hdd_check_custom_con_channel_rules(hdd_adapter_t *sta_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009439 hdd_adapter_t *ap_adapter,
9440 tCsrRoamProfile *roam_profile,
9441 tScanResultHandle *scan_cache,
9442 bool *concurrent_chnl_same)
9443{
9444 hdd_ap_ctx_t *hdd_ap_ctx;
9445 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309446 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009447 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009448 *concurrent_chnl_same = true;
9449
9450 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
9451 status =
9452 sme_get_ap_channel_from_scan_cache(WLAN_HDD_GET_HAL_CTX(sta_adapter),
9453 roam_profile,
9454 scan_cache,
9455 &channel_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309456 if ((QDF_STATUS_SUCCESS == status)) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009457 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009458 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
9459 if (hdd_ap_ctx->operatingChannel != channel_id) {
9460 *concurrent_chnl_same = false;
Jeff Johnson28f8a772016-08-15 15:30:36 -07009461 hdd_info("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009462 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009463 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009464 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
9465 if (hdd_ap_ctx->operatingChannel != channel_id) {
9466 *concurrent_chnl_same = false;
Jeff Johnson28f8a772016-08-15 15:30:36 -07009467 hdd_info("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009468 }
9469 }
9470 } else {
9471 /*
9472 * Lets handle worst case scenario here, Scan cache lookup is
9473 * failed so we have to stop the SAP to avoid any channel
9474 * discrepancy between SAP's channel and STA's channel.
9475 * Return the status as failure so caller function could know
9476 * that scan look up is failed.
9477 */
Jeff Johnson28f8a772016-08-15 15:30:36 -07009478 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309479 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009480 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309481 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009482}
9483
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009484/**
9485 * wlan_hdd_stop_sap() - This function stops bss of SAP.
9486 * @ap_adapter: SAP adapter
9487 *
9488 * This function will process the stopping of sap adapter.
9489 *
9490 * Return: None
9491 */
9492void wlan_hdd_stop_sap(hdd_adapter_t *ap_adapter)
9493{
9494 hdd_ap_ctx_t *hdd_ap_ctx;
9495 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +05309496 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009497 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009498
9499 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009500 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009501 return;
9502 }
9503
9504 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
9505 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05309506 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009507 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05309508
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009509 mutex_lock(&hdd_ctx->sap_lock);
9510 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -08009511 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009512 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
9513 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnson28f8a772016-08-15 15:30:36 -07009514 hdd_info("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309515 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309516 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009517 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +05309518 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08009519 qdf_stop_bss_event,
9520 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +05309521 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009522 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -07009523 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009524 return;
9525 }
9526 }
9527 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyya4adb3682016-01-07 15:07:12 -08009528 cds_decr_session_set_pcl(ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009529 ap_adapter->sessionId);
Jeff Johnson28f8a772016-08-15 15:30:36 -07009530 hdd_info("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009531 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009532 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009533 }
9534 mutex_unlock(&hdd_ctx->sap_lock);
9535 return;
9536}
9537
9538/**
9539 * wlan_hdd_start_sap() - this function starts bss of SAP.
9540 * @ap_adapter: SAP adapter
9541 *
9542 * This function will process the starting of sap adapter.
9543 *
9544 * Return: None
9545 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05309546void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009547{
9548 hdd_ap_ctx_t *hdd_ap_ctx;
9549 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +05309550 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009551 hdd_context_t *hdd_ctx;
9552 tsap_Config_t *sap_config;
9553
9554 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009555 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009556 return;
9557 }
9558
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009559 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -07009560 hdd_err("SoftAp role has not been enabled");
9561 return;
9562 }
9563
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009564 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
9565 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
9566 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
9567 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
9568
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009569 mutex_lock(&hdd_ctx->sap_lock);
9570 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
9571 goto end;
9572
9573 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009574 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009575 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
9576 goto end;
9577 }
9578
Wei Song2f76f642016-11-18 16:32:53 +08009579 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009580 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
9581 &hdd_ap_ctx->sapConfig,
9582 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309583 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009584 goto end;
9585
Jeff Johnson28f8a772016-08-15 15:30:36 -07009586 hdd_info("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309587 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08009588 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +05309589 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009590 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009591 goto end;
9592 }
Jeff Johnson28f8a772016-08-15 15:30:36 -07009593 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009594 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -08009595 if (hostapd_state->bssState == BSS_START)
9596 cds_incr_active_session(ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009597 ap_adapter->sessionId);
9598 hostapd_state->bCommit = true;
9599
9600end:
9601 mutex_unlock(&hdd_ctx->sap_lock);
9602 return;
9603}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009604
9605/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -08009606 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
9607 * mac scan config
9608 * @status: Status of set antenna mode
9609 *
9610 * Callback on setting the dual mac configuration
9611 *
9612 * Return: None
9613 */
9614void wlan_hdd_soc_set_antenna_mode_cb(
9615 enum set_antenna_mode_status status)
9616{
9617 hdd_context_t *hdd_ctx;
9618
9619 hdd_info("Status: %d", status);
9620
9621 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9622 if (0 != wlan_hdd_validate_context(hdd_ctx))
9623 return;
9624
9625 /* Signal the completion of set dual mac config */
9626 complete(&hdd_ctx->set_antenna_mode_cmpl);
9627}
9628
9629/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009630 * hdd_get_fw_version() - Get FW version
9631 * @hdd_ctx: pointer to HDD context.
9632 * @major_spid: FW version - major spid.
9633 * @minor_spid: FW version - minor spid
9634 * @ssid: FW version - ssid
9635 * @crmid: FW version - crmid
9636 *
9637 * This function is called to get the firmware build version stored
9638 * as part of the HDD context
9639 *
9640 * Return: None
9641 */
9642void hdd_get_fw_version(hdd_context_t *hdd_ctx,
9643 uint32_t *major_spid, uint32_t *minor_spid,
9644 uint32_t *siid, uint32_t *crmid)
9645{
9646 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
9647 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
9648 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
9649 *crmid = hdd_ctx->target_fw_version & 0x7fff;
9650}
9651
9652#ifdef QCA_CONFIG_SMP
9653/**
9654 * wlan_hdd_get_cpu() - get cpu_index
9655 *
9656 * Return: cpu_index
9657 */
9658int wlan_hdd_get_cpu(void)
9659{
9660 int cpu_index = get_cpu();
9661 put_cpu();
9662 return cpu_index;
9663}
9664#endif
9665
9666/**
9667 * hdd_get_fwpath() - get framework path
9668 *
9669 * This function is used to get the string written by
9670 * userspace to start the wlan driver
9671 *
9672 * Return: string
9673 */
9674const char *hdd_get_fwpath(void)
9675{
9676 return fwpath.string;
9677}
9678
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009679/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009680 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009681 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009682 * This function initilizes CDS global context with the help of cds_init. This
9683 * has to be the first function called after probe to get a valid global
9684 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009685 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009686 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009687 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009688int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009689{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009690 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009691 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009692
Houston Hoffman9e06e542016-12-12 12:06:26 -08009693 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009694#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9695 wlan_logging_sock_init_svc();
9696#endif
9697
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009698 if (p_cds_context == NULL) {
9699 hdd_alert("Failed to allocate CDS context");
9700 ret = -ENOMEM;
9701 goto err_out;
9702 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009703
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009704 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309705 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009706
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009707err_out:
9708 return ret;
9709}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009710
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009711/**
9712 * hdd_deinit() - Deinitialize Driver
9713 *
9714 * This function frees CDS global context with the help of cds_deinit. This
9715 * has to be the last function call in remove callback to free the global
9716 * context.
9717 */
9718void hdd_deinit(void)
9719{
9720 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009721
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009722#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9723 wlan_logging_sock_deinit_svc();
9724#endif
9725}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009726
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009727#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009728
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009729/**
9730 * __hdd_module_init - Module init helper
9731 *
9732 * Module init helper function used by both module and static driver.
9733 *
9734 * Return: 0 for success, errno on failure
9735 */
9736static int __hdd_module_init(void)
9737{
9738 int ret = 0;
Arun Khandavalli13cb5da2017-01-19 15:43:52 +05309739 unsigned long rc;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009740
Arun Khandavallifae92942016-08-01 13:31:08 +05309741 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009742 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009743
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -07009744 pld_init();
9745
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309746 ret = hdd_init();
9747 if (ret) {
9748 pr_err("hdd_init failed %x\n", ret);
9749 goto err_hdd_init;
9750 }
9751
Rajeev Kumar97767a02016-11-30 11:20:40 -08009752 dispatcher_init();
9753
Anurag Chouhana37b5b72016-02-21 14:53:42 +05309754 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009755
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009756 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009757
Arun Khandavalli13cb5da2017-01-19 15:43:52 +05309758 init_completion(&wlan_start_comp);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009759 ret = wlan_hdd_register_driver();
9760 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -07009761 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
9762 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009763 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009764 }
9765
Arun Khandavalli13cb5da2017-01-19 15:43:52 +05309766 rc = wait_for_completion_timeout(&wlan_start_comp,
9767 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
9768
9769 if (!rc) {
9770 hdd_alert("Timed-out waiting for wlan_hdd_register_driver");
9771 QDF_BUG(0);
9772 goto out;
9773 }
9774
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309775 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009776
9777 return 0;
9778out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05309779 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -08009780 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309781 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -08009782
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309783err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -07009784 pld_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -08009785
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009786 return ret;
9787}
9788
9789/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +05309790 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
9791 *
9792 * Block the unloading of the driver until the cds recovery is completed
9793 *
9794 * Return: None
9795 */
9796static void hdd_wait_for_recovery_completion(void)
9797{
9798 int retry = 0;
9799
9800 /* Wait for recovery to complete */
9801 while (cds_is_driver_recovering()) {
9802 hdd_alert("Recovery in progress; wait here!!!");
9803 msleep(1000);
9804 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
9805 hdd_alert("SSR never completed, fatal error");
9806 QDF_BUG(0);
9807 }
9808 }
9809}
9810
9811/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009812 * __hdd_module_exit - Module exit helper
9813 *
9814 * Module exit helper function used by both module and static driver.
9815 */
9816static void __hdd_module_exit(void)
9817{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05309818 int qdf_print_idx = -1;
9819
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009820 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
9821 QWLAN_VERSIONSTR);
9822
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +05309823 hdd_wait_for_recovery_completion();
9824
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009825 wlan_hdd_unregister_driver();
9826
Anurag Chouhana37b5b72016-02-21 14:53:42 +05309827 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009828
Rajeev Kumar97767a02016-11-30 11:20:40 -08009829 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309830 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -07009831 pld_deinit();
9832
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05309833 qdf_print_idx = qdf_get_pidx();
9834 qdf_print_ctrl_cleanup(qdf_print_idx);
9835
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009836 return;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009837}
9838
Arun Khandavallifae92942016-08-01 13:31:08 +05309839#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009840/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309841 * wlan_boot_cb() - Wlan boot callback
9842 * @kobj: object whose directory we're creating the link in.
9843 * @attr: attribute the user is interacting with
9844 * @buff: the buffer containing the user data
9845 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009846 *
Arun Khandavallifae92942016-08-01 13:31:08 +05309847 * This callback is invoked when the fs is ready to start the
9848 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009849 *
Arun Khandavallifae92942016-08-01 13:31:08 +05309850 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009851 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309852static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009853 struct kobj_attribute *attr,
9854 const char *buf,
9855 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009856{
Arun Khandavallifae92942016-08-01 13:31:08 +05309857
Arun Khandavallifae92942016-08-01 13:31:08 +05309858 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009859 pr_err("%s: wlan driver already initialized\n", __func__);
9860 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +05309861 }
9862
Arun Khandavallifae92942016-08-01 13:31:08 +05309863 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009864 pr_err("%s: wlan driver initialization failed\n", __func__);
9865 return -EIO;
9866 }
9867
9868 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +05309869
9870 return count;
9871
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009872}
Arun Khandavallifae92942016-08-01 13:31:08 +05309873
9874/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009875 * hdd_sysfs_cleanup() - cleanup sysfs
9876 *
9877 * Return: None
9878 *
9879 */
9880static void hdd_sysfs_cleanup(void)
9881{
9882
9883 /* remove from group */
9884 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
9885 sysfs_remove_group(wlan_loader->boot_wlan_obj,
9886 wlan_loader->attr_group);
9887
9888 /* unlink the object from parent */
9889 kobject_del(wlan_loader->boot_wlan_obj);
9890
9891 /* free the object */
9892 kobject_put(wlan_loader->boot_wlan_obj);
9893
9894 kfree(wlan_loader->attr_group);
9895 kfree(wlan_loader);
9896
9897 wlan_loader = NULL;
9898}
9899
9900/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309901 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
9902 * ready
9903 *
9904 * This is creates the syfs entry boot_wlan. Which shall be invoked
9905 * when the filesystem is ready.
9906 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009907 * QDF API cannot be used here since this function is called even before
9908 * initializing WLAN driver.
9909 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -07009910 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +05309911 */
9912static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009913{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009914 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +05309915
9916 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
9917 if (!wlan_loader) {
9918 pr_err("%s: memory alloc failed\n", __func__);
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009919 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +05309920 }
9921
9922 wlan_loader->boot_wlan_obj = NULL;
9923 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
9924 GFP_KERNEL);
9925 if (!wlan_loader->attr_group) {
9926 pr_err("%s: malloc attr_group failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +05309927 goto error_return;
9928 }
9929
9930 wlan_loader->loaded_state = 0;
9931 wlan_loader->attr_group->attrs = attrs;
9932
9933 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
9934 kernel_kobj);
9935 if (!wlan_loader->boot_wlan_obj) {
9936 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +05309937 goto error_return;
9938 }
9939
9940 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
9941 wlan_loader->attr_group);
9942 if (ret) {
9943 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
9944 goto error_return;
9945 }
9946
9947 return 0;
9948
9949error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009950 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +05309951
9952 return ret;
9953}
9954
9955/**
9956 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
9957 *
9958 * Return: 0 on success or errno on failure
9959 */
9960static int wlan_deinit_sysfs(void)
9961{
Arun Khandavallifae92942016-08-01 13:31:08 +05309962 if (!wlan_loader) {
9963 hdd_alert("wlan loader context is Null!");
9964 return -EINVAL;
9965 }
9966
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009967 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009968 return 0;
9969}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009970
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -07009971#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +05309972
9973#ifdef MODULE
9974/**
9975 * __hdd_module_init - Module init helper
9976 *
9977 * Module init helper function used by both module and static driver.
9978 *
9979 * Return: 0 for success, errno on failure
9980 */
9981static int hdd_module_init(void)
9982{
9983 int ret = 0;
9984
9985 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
9986 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
9987
9988 if (__hdd_module_init()) {
9989 pr_err("%s: Failed to register handler\n", __func__);
9990 ret = -EINVAL;
9991 }
9992
9993 return ret;
9994}
9995#else
9996static int __init hdd_module_init(void)
9997{
9998 int ret = -EINVAL;
9999
10000 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070010001 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053010002 pr_err("Failed to create sysfs entry for loading wlan");
10003
10004 return ret;
10005}
10006#endif
10007
10008
10009#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010010/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010011 * hdd_module_exit() - Exit function
10012 *
10013 * This is the driver exit point (invoked when module is unloaded using rmmod)
10014 *
10015 * Return: None
10016 */
10017static void __exit hdd_module_exit(void)
10018{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010019 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010020}
Arun Khandavallifae92942016-08-01 13:31:08 +053010021#else
10022static void __exit hdd_module_exit(void)
10023{
10024 __hdd_module_exit();
10025 wlan_deinit_sysfs();
10026}
10027#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010028
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010029static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
10030{
10031 return param_set_copystring(kmessage, kp);
10032}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010033
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010034/**
10035 * is_con_mode_valid() check con mode is valid or not
10036 * @mode: global con mode
10037 *
10038 * Return: TRUE on success FALSE on failure
10039 */
10040static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
10041{
10042 switch (mode) {
10043 case QDF_GLOBAL_MONITOR_MODE:
10044 case QDF_GLOBAL_FTM_MODE:
10045 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010046 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010047 return true;
10048 default:
10049 return false;
10050 }
10051}
10052
10053/**
10054 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
10055 * @mode: global con mode
10056 *
10057 * Return: adapter mode
10058 */
10059static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
10060 enum tQDF_GLOBAL_CON_MODE mode)
10061{
10062
10063 switch (mode) {
10064 case QDF_GLOBAL_MISSION_MODE:
10065 return QDF_STA_MODE;
10066 case QDF_GLOBAL_MONITOR_MODE:
10067 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010068 case QDF_GLOBAL_EPPING_MODE:
10069 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010070 case QDF_GLOBAL_FTM_MODE:
10071 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010072 case QDF_GLOBAL_QVIT_MODE:
10073 return QDF_QVIT_MODE;
10074 default:
10075 return QDF_MAX_NO_OF_MODE;
10076 }
10077}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010078
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010079static void hdd_cleanup_present_mode(hdd_context_t *hdd_ctx,
10080 enum tQDF_GLOBAL_CON_MODE curr_mode)
10081{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053010082 int driver_status;
10083
10084 driver_status = hdd_ctx->driver_status;
10085
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010086 switch (curr_mode) {
10087 case QDF_GLOBAL_MISSION_MODE:
10088 case QDF_GLOBAL_MONITOR_MODE:
10089 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053010090 if (driver_status != DRIVER_MODULES_CLOSED) {
10091 hdd_abort_mac_scan_all_adapters(hdd_ctx);
10092 hdd_stop_all_adapters(hdd_ctx);
10093 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010094 hdd_deinit_all_adapters(hdd_ctx, false);
10095 hdd_close_all_adapters(hdd_ctx, false);
10096 break;
10097 case QDF_GLOBAL_EPPING_MODE:
10098 epping_disable();
10099 epping_close();
10100 break;
10101 default:
10102 return;
10103 }
10104}
10105
10106static int hdd_register_req_mode(hdd_context_t *hdd_ctx,
10107 enum tQDF_GLOBAL_CON_MODE mode)
10108{
10109 hdd_adapter_t *adapter;
10110 int ret = 0;
10111 bool rtnl_held;
10112 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10113 QDF_STATUS status;
10114
10115 if (!qdf_dev) {
10116 hdd_err("qdf device context is Null return!");
10117 return -EINVAL;
10118 }
10119
10120 rtnl_held = hdd_hold_rtnl_lock();
10121 switch (mode) {
10122 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080010123 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10124 if (ret)
10125 hdd_alert("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010126 break;
10127 case QDF_GLOBAL_FTM_MODE:
10128 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
10129 wlan_hdd_get_intf_addr(hdd_ctx),
10130 NET_NAME_UNKNOWN, rtnl_held);
10131 if (adapter == NULL)
10132 ret = -EINVAL;
10133 break;
10134 case QDF_GLOBAL_MONITOR_MODE:
10135 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
10136 wlan_hdd_get_intf_addr(hdd_ctx),
10137 NET_NAME_UNKNOWN, rtnl_held);
10138 if (adapter == NULL)
10139 ret = -EINVAL;
10140 break;
10141 case QDF_GLOBAL_EPPING_MODE:
10142 status = epping_open();
10143 if (status != QDF_STATUS_SUCCESS) {
10144 hdd_err("Failed to open in eeping mode: %d", status);
10145 ret = -EINVAL;
10146 break;
10147 }
10148 ret = epping_enable(qdf_dev->dev);
10149 if (ret) {
10150 hdd_err("Failed to enable in epping mode : %d", ret);
10151 epping_close();
10152 }
10153 break;
10154 default:
10155 hdd_info("Mode not supported");
10156 ret = -ENOTSUPP;
10157 break;
10158 }
10159 hdd_release_rtnl_lock();
10160 rtnl_held = false;
10161 return ret;
10162}
10163
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010164/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010165 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010166 * @kmessage: con mode name on which driver to be bring up
10167 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010168 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010169 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010170 * This function is invoked when user updates con mode using sys entry,
10171 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010172 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010173 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010174 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010175static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
10176 hdd_context_t *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010177{
10178 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010179 hdd_adapter_t *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010180 enum tQDF_GLOBAL_CON_MODE curr_mode;
10181 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010182
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010183 ret = wlan_hdd_validate_context(hdd_ctx);
10184 if (ret)
10185 return ret;
10186
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010187 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010188
Arun Khandavallifae92942016-08-01 13:31:08 +053010189 hdd_info("con_mode handler: %s", kmessage);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010190 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053010191
Arun Khandavallifae92942016-08-01 13:31:08 +053010192
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010193
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010194 if (!(is_con_mode_valid(con_mode))) {
10195 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010196 ret = -EINVAL;
10197 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010198 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010199
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010200 curr_mode = hdd_get_conparam();
10201 if (curr_mode == con_mode) {
10202 hdd_err("curr mode: %d is same as user triggered mode %d",
10203 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010204 ret = 0;
10205 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010206 }
10207
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010208 /* Cleanup present mode before switching to new mode */
10209 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +053010210
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -070010211 ret = hdd_wlan_stop_modules(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010212 if (ret) {
10213 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010214 goto reset_flags;
10215 }
10216
10217 hdd_set_conparam(con_mode);
10218
10219 /* Register for new con_mode & then kick_start modules again */
10220 ret = hdd_register_req_mode(hdd_ctx, con_mode);
10221 if (ret) {
10222 hdd_err("Failed to register for new mode");
10223 goto reset_flags;
10224 }
10225
10226 adapter_mode = hdd_get_adpter_mode(con_mode);
10227 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
10228 hdd_err("invalid adapter");
10229 ret = -EINVAL;
10230 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010231 }
10232
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010233 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053010234 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010235 hdd_err("Failed to get adapter:%d", adapter_mode);
10236 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010237 }
10238
10239 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
10240 if (ret) {
10241 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010242 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010243 }
10244
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010245 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
10246 con_mode == QDF_GLOBAL_FTM_MODE) {
10247 if (hdd_start_adapter(adapter)) {
10248 hdd_err("Failed to start %s adapter", kmessage);
10249 ret = -EINVAL;
10250 goto reset_flags;
10251 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010252 }
10253
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010254 hdd_info("Mode successfully changed to %s", kmessage);
10255 ret = 0;
10256
10257reset_flags:
10258 cds_set_load_in_progress(false);
10259 return ret;
10260}
10261
10262
10263static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
10264{
10265 int ret;
10266 hdd_context_t *hdd_ctx;
10267
10268 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10269 ret = wlan_hdd_validate_context(hdd_ctx);
10270 if (ret)
10271 return ret;
10272
10273 cds_ssr_protect(__func__);
10274 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
10275 cds_ssr_unprotect(__func__);
10276
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010277 return ret;
10278}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010279
10280/**
10281 * hdd_get_conparam() - driver exit point
10282 *
10283 * This is the driver exit point (invoked when module is unloaded using rmmod)
10284 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053010285 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010286 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053010287enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010288{
Anurag Chouhan6d760662016-02-20 16:05:43 +053010289 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010290}
10291
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080010292void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010293{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080010294 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010295}
10296
Komal Seelamc11bb222016-01-27 18:57:10 +053010297/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053010298 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
10299 * @hdd_ctx: HDD context
10300 *
10301 * Cleans up the pre cac interface, if it exists
10302 *
10303 * Return: None
10304 */
10305void hdd_clean_up_pre_cac_interface(hdd_context_t *hdd_ctx)
10306{
10307 uint8_t session_id;
10308 QDF_STATUS status;
10309 struct hdd_adapter_s *precac_adapter;
10310
10311 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
10312 if (QDF_IS_STATUS_ERROR(status)) {
10313 hdd_err("failed to get pre cac vdev id");
10314 return;
10315 }
10316
10317 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
10318 if (!precac_adapter) {
10319 hdd_err("invalid pre cac adapater");
10320 return;
10321 }
10322
10323 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
10324 wlan_hdd_sap_pre_cac_failure,
10325 (void *)precac_adapter);
10326 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
10327
10328}
10329
10330/**
Komal Seelamec702b02016-02-24 18:42:16 +053010331 * hdd_update_ol_config - API to update ol configuration parameters
10332 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053010333 *
Komal Seelamc11bb222016-01-27 18:57:10 +053010334 * Return: void
10335 */
Komal Seelamec702b02016-02-24 18:42:16 +053010336static void hdd_update_ol_config(hdd_context_t *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053010337{
Komal Seelamec702b02016-02-24 18:42:16 +053010338 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053010339 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053010340
Komal Seelamec702b02016-02-24 18:42:16 +053010341 if (!ol_ctx)
10342 return;
10343
10344 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
10345 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
10346 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
10347 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070010348 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053010349
10350 ol_init_ini_config(ol_ctx, &cfg);
10351}
10352
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070010353#ifdef FEATURE_RUNTIME_PM
10354/**
10355 * hdd_populate_runtime_cfg() - populate runtime configuration
10356 * @hdd_ctx: hdd context
10357 * @cfg: pointer to the configuration memory being populated
10358 *
10359 * Return: void
10360 */
10361static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
10362 struct hif_config_info *cfg)
10363{
10364 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
10365 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
10366}
10367#else
10368static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
10369 struct hif_config_info *cfg)
10370{
10371}
10372#endif
10373
Komal Seelamec702b02016-02-24 18:42:16 +053010374/**
10375 * hdd_update_hif_config - API to update HIF configuration parameters
10376 * @hdd_ctx: HDD Context
10377 *
10378 * Return: void
10379 */
10380static void hdd_update_hif_config(hdd_context_t *hdd_ctx)
10381{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053010382 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053010383 struct hif_config_info cfg;
10384
10385 if (!scn)
10386 return;
10387
10388 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070010389 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053010390 hif_init_ini_config(scn, &cfg);
10391}
10392
10393/**
10394 * hdd_update_config() - Initialize driver per module ini parameters
10395 * @hdd_ctx: HDD Context
10396 *
10397 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010398 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053010399 */
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010400int hdd_update_config(hdd_context_t *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053010401{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010402 int ret;
10403
Komal Seelamec702b02016-02-24 18:42:16 +053010404 hdd_update_ol_config(hdd_ctx);
10405 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010406 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
10407 ret = hdd_update_cds_config_ftm(hdd_ctx);
10408 else
10409 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080010410 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010411
10412 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053010413}
10414
Mukul Sharma9d797a02017-01-05 20:26:03 +053010415#ifdef FEATURE_WLAN_RA_FILTERING
10416/**
10417 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
10418 * @psoc_cfg: pmo psoc Configuration
10419 * @hdd_ctx: Pointer to hdd context
10420 *
10421 * Return: none
10422 */
10423static inline void hdd_ra_populate_pmo_config(
10424 struct pmo_psoc_cfg *psoc_cfg,
10425 hdd_context_t *hdd_ctx)
10426{
10427 psoc_cfg->ra_ratelimit_interval =
10428 hdd_ctx->config->RArateLimitInterval;
10429 psoc_cfg->ra_ratelimit_enable =
10430 hdd_ctx->config->IsRArateLimitEnabled;
10431}
10432#else
10433static inline void hdd_ra_populate_pmo_config(
10434 struct cds_config_info *cds_cfg,
10435 hdd_context_t *hdd_ctx)
10436{
10437}
10438#endif
10439/**
10440 * hdd_update_pmo_config - API to update pmo configuration parameters
10441 * @hdd_ctx: HDD context
10442 *
10443 * Return: void
10444 */
10445static int hdd_update_pmo_config(hdd_context_t *hdd_ctx)
10446{
10447 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
10448 struct pmo_psoc_cfg psoc_cfg;
10449 QDF_STATUS status;
10450
10451 /*
10452 * Value of hdd_ctx->wowEnable can be,
10453 * 0 - Disable both magic pattern match and pattern byte match.
10454 * 1 - Enable magic pattern match on all interfaces.
10455 * 2 - Enable pattern byte match on all interfaces.
10456 * 3 - Enable both magic patter and pattern byte match on
10457 * all interfaces.
10458 */
10459 psoc_cfg.magic_ptrn_enable =
10460 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
10461 psoc_cfg.ptrn_match_enable_all_vdev =
10462 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
10463 psoc_cfg.bpf_enable =
10464 hdd_ctx->config->bpf_packet_filter_enable;
10465 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
10466 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
10467 if (hdd_ctx->config->fhostNSOffload)
10468 psoc_cfg.ns_offload_enable_dynamic = true;
10469 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
10470 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
10471 psoc_cfg.active_mode_offload =
10472 hdd_ctx->config->active_mode_offload;
10473 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
10474 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
10475
10476 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
10477 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
10478 if (status != QDF_STATUS_SUCCESS) {
10479 hdd_err("failed pmo psoc configuration");
10480 return -EINVAL;
10481 }
10482
10483 return 0;
10484}
10485
10486int hdd_update_components_config(hdd_context_t *hdd_ctx)
10487{
10488 int ret;
10489
10490 ret = hdd_update_pmo_config(hdd_ctx);
10491
10492 return ret;
10493}
10494
Agrawal Ashish65634612016-08-18 13:24:32 +053010495/**
10496 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
10497 * @mode : cfg80211 DFS mode
10498 *
10499 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
10500 */
10501enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
10502{
10503 switch (mode) {
10504 case DFS_MODE_ENABLE:
10505 return ACS_DFS_MODE_ENABLE;
10506 break;
10507 case DFS_MODE_DISABLE:
10508 return ACS_DFS_MODE_DISABLE;
10509 break;
10510 case DFS_MODE_DEPRIORITIZE:
10511 return ACS_DFS_MODE_DEPRIORITIZE;
10512 break;
10513 default:
10514 hdd_err("ACS dfs mode is NONE");
10515 return ACS_DFS_MODE_NONE;
10516 }
10517}
10518
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010519/**
10520 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
10521 * @hddctx: pointer to hdd context
10522 * @set_value: enable/disable
10523 *
10524 * When Host sends vendor command enable, FW will send *ONE* CA ind to
10525 * Host(even though it is duplicate). When Host send vendor command
10526 * disable,FW doesn't perform any action. Whenever any change in
10527 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
10528 *
10529 * return - 0 on success, appropriate error values on failure.
10530 */
10531int hdd_enable_disable_ca_event(hdd_context_t *hddctx, uint8_t set_value)
10532{
10533 QDF_STATUS status;
10534
10535 if (0 != wlan_hdd_validate_context(hddctx)) {
10536 return -EAGAIN;
10537 }
10538
10539 if (!hddctx->config->goptimize_chan_avoid_event) {
10540 hdd_warn("goptimize_chan_avoid_event ini param disabled");
10541 return -EINVAL;
10542 }
10543
10544 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
10545 if (!QDF_IS_STATUS_SUCCESS(status)) {
10546 hdd_err("Failed to send chan avoid command to SME");
10547 return -EINVAL;
10548 }
10549 return 0;
10550}
Agrawal Ashish65634612016-08-18 13:24:32 +053010551
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010552/**
10553 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
10554 * @value: value to set
10555 *
10556 * This function will set the passed value to roaming in progress flag.
10557 *
10558 * Return: None
10559 */
10560void hdd_set_roaming_in_progress(bool value)
10561{
10562 hdd_context_t *hdd_ctx;
10563
10564 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10565 if (!hdd_ctx) {
10566 hdd_err("HDD context is NULL");
10567 return;
10568 }
10569
10570 hdd_ctx->roaming_in_progress = value;
10571 hdd_info("Roaming in Progress set to %d", value);
10572}
10573
10574/**
10575 * hdd_is_roaming_in_progress() - check if roaming is in progress
10576 * @hdd_ctx - HDD context
10577 *
10578 * Return: true if roaming is in progress else false
10579 */
10580bool hdd_is_roaming_in_progress(void)
10581{
10582 hdd_context_t *hdd_ctx;
10583
10584 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10585 if (!hdd_ctx) {
10586 hdd_err("HDD context is NULL");
10587 return false;
10588 }
10589 return hdd_ctx->roaming_in_progress;
10590}
10591
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010592/* Register the module init/exit functions */
10593module_init(hdd_module_init);
10594module_exit(hdd_module_exit);
10595
10596MODULE_LICENSE("Dual BSD/GPL");
10597MODULE_AUTHOR("Qualcomm Atheros, Inc.");
10598MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
10599
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010600module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
10601 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010602
10603module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
10604 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
10605
10606module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
10607
10608module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
10609
10610module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);