blob: 22cdb6934f6140bb8b84553322bb5f9f46d68b19 [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"
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -070096#include "wlan_hdd_he.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097
98#include <wlan_hdd_ipa.h>
99#include "hif.h"
100#include "wma.h"
101#include "cds_concurrency.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700102#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530104#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700105#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700106#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530107#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700108#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530109#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800110#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800111#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530112#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800113#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800114#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530115#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530116#include "sir_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800117
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530118#ifdef CNSS_GENL
119#include <net/cnss_nl.h>
120#endif
121
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800122#ifdef MODULE
123#define WLAN_MODULE_NAME module_name(THIS_MODULE)
124#else
125#define WLAN_MODULE_NAME "wlan"
126#endif
127
128#ifdef TIMER_MANAGER
129#define TIMER_MANAGER_STR " +TIMER_MANAGER"
130#else
131#define TIMER_MANAGER_STR ""
132#endif
133
134#ifdef MEMORY_DEBUG
135#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
136#else
137#define MEMORY_DEBUG_STR ""
138#endif
139
Arun Khandavallifae92942016-08-01 13:31:08 +0530140#ifndef MODULE
141static struct gwlan_loader *wlan_loader;
142static ssize_t wlan_boot_cb(struct kobject *kobj,
143 struct kobj_attribute *attr,
144 const char *buf, size_t count);
145struct gwlan_loader {
146 bool loaded_state;
147 struct kobject *boot_wlan_obj;
148 struct attribute_group *attr_group;
149};
150
151static struct kobj_attribute wlan_boot_attribute =
152 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
153
154static struct attribute *attrs[] = {
155 &wlan_boot_attribute.attr,
156 NULL,
157};
158
159#define MODULE_INITIALIZED 1
160#endif
161
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800162/* the Android framework expects this param even though we don't use it */
163#define BUF_LEN 20
164static char fwpath_buffer[BUF_LEN];
165static struct kparam_string fwpath = {
166 .string = fwpath_buffer,
167 .maxlen = BUF_LEN,
168};
169
170static char *country_code;
171static int enable_11d = -1;
172static int enable_dfs_chan_scan = -1;
173
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800174/*
175 * spinlock for synchronizing asynchronous request/response
176 * (full description of use in wlan_hdd_main.h)
177 */
178DEFINE_SPINLOCK(hdd_context_lock);
179
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800180#define WLAN_NLINK_CESIUM 30
181
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530182static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800183
184#define WOW_MAX_FILTER_LISTS 1
185#define WOW_MAX_FILTERS_PER_LIST 4
186#define WOW_MIN_PATTERN_SIZE 6
187#define WOW_MAX_PATTERN_SIZE 64
188
189#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
190static const struct wiphy_wowlan_support wowlan_support_reg_init = {
191 .flags = WIPHY_WOWLAN_ANY |
192 WIPHY_WOWLAN_MAGIC_PKT |
193 WIPHY_WOWLAN_DISCONNECT |
194 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
195 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
196 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
197 WIPHY_WOWLAN_4WAY_HANDSHAKE |
198 WIPHY_WOWLAN_RFKILL_RELEASE,
199 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
200 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
201 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
202};
203#endif
204
205/* internal function declaration */
206
207struct sock *cesium_nl_srv_sock;
Arun Khandavalli13cb5da2017-01-19 15:43:52 +0530208struct completion wlan_start_comp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800209#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
210void wlan_hdd_auto_shutdown_cb(void);
211#endif
212
213/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530214 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
215 * @hdd_ctx: pointer to hdd_context_t
216 *
217 * Return: none
218 */
Jeff Johnson590e2012016-10-05 16:16:24 -0700219static void hdd_set_rps_cpu_mask(hdd_context_t *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530220{
221 hdd_adapter_t *adapter;
222 hdd_adapter_list_node_t *adapter_node, *next;
223 QDF_STATUS status = QDF_STATUS_SUCCESS;
224
225 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
226 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
227 adapter = adapter_node->pAdapter;
228 if (NULL != adapter)
229 hdd_send_rps_ind(adapter);
230 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
231 adapter_node = next;
232 }
233}
234
235/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800236 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
237 * @vdev_id: vdev_id
238 * @action: action type
239 * @reason: reason type
240 *
241 * Return: none
242 */
243void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
244 enum netif_action_type action, enum netif_reason_type reason)
245{
Anurag Chouhan6d760662016-02-20 16:05:43 +0530246 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 hdd_adapter_t *adapter;
248
249 if (!hdd_ctx) {
250 hdd_err("hdd ctx is NULL");
251 return;
252 }
253 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
254
255 wlan_hdd_netif_queue_control(adapter, action, reason);
256 return;
257}
258
259/*
260 * Store WLAN driver version info in a global variable such that crash debugger
261 * can extract it from driver debug symbol and crashdump for post processing
262 */
263uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
264
265/**
266 * hdd_device_mode_to_string() - return string conversion of device mode
267 * @device_mode: device mode
268 *
269 * This utility function helps log string conversion of device mode.
270 *
271 * Return: string conversion of device mode, if match found;
272 * "Unknown" otherwise.
273 */
274const char *hdd_device_mode_to_string(uint8_t device_mode)
275{
276 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800277 CASE_RETURN_STRING(QDF_STA_MODE);
278 CASE_RETURN_STRING(QDF_SAP_MODE);
279 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
280 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
281 CASE_RETURN_STRING(QDF_FTM_MODE);
282 CASE_RETURN_STRING(QDF_IBSS_MODE);
283 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
284 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700285 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800286 default:
287 return "Unknown";
288 }
289}
290
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530291/**
292 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
293 * @adapter: HDD adapter
294 * @chan_number: Channel number
295 * @chan_bw: Bandwidth
296 *
297 * Checks if the given bandwidth is valid for the given channel number.
298 *
299 * Return: 0 for success, non-zero for failure
300 */
301int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
302 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800303 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530304{
305 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
306 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
307 bool found = false;
308 tHalHandle hal;
309
310 hal = WLAN_HDD_GET_HAL_CTX(adapter);
311 if (!hal) {
312 hdd_err("Invalid HAL context");
313 return -EINVAL;
314 }
315
316 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
317 hdd_err("No valid channel list");
318 return -EOPNOTSUPP;
319 }
320
321 for (i = 0; i < len; i++) {
322 if (chan[i] == chan_number) {
323 found = true;
324 break;
325 }
326 }
327
328 if (found == false) {
329 hdd_err("Channel not in driver's valid channel list");
330 return -EOPNOTSUPP;
331 }
332
333 if ((!CDS_IS_CHANNEL_24GHZ(chan_number)) &&
334 (!CDS_IS_CHANNEL_5GHZ(chan_number))) {
335 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
336 return -EINVAL;
337 }
338
339 if (CDS_IS_CHANNEL_24GHZ(chan_number)) {
340 if (chan_bw == CH_WIDTH_80MHZ) {
341 hdd_err("BW80 not possible in 2.4GHz band");
342 return -EINVAL;
343 }
344 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
345 (chan_bw != CH_WIDTH_MAX)) {
346 hdd_err("Only BW20 possible on channel 14");
347 return -EINVAL;
348 }
349 }
350
351 if (CDS_IS_CHANNEL_5GHZ(chan_number)) {
352 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
353 (chan_bw != CH_WIDTH_MAX)) {
354 hdd_err("Only BW20 possible on channel 165");
355 return -EINVAL;
356 }
357 }
358
359 return 0;
360}
361
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800362static int __hdd_netdev_notifier_call(struct notifier_block *nb,
363 unsigned long state, void *data)
364{
365#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
366 struct netdev_notifier_info *dev_notif_info = data;
367 struct net_device *dev = dev_notif_info->dev;
368#else
369 struct net_device *dev = data;
370#endif
371 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
372 hdd_context_t *hdd_ctx;
373
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800374 ENTER_DEV(dev);
375
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800376 /* Make sure that this callback corresponds to our device. */
377 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
378 return NOTIFY_DONE;
379
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530380 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800381 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700382 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 return NOTIFY_DONE;
384 }
385
386 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700387 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800388 return NOTIFY_DONE;
389 }
390
391 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
392 if (NULL == hdd_ctx) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700393 hdd_alert("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530394 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800395 return NOTIFY_DONE;
396 }
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800397 if (cds_is_driver_recovering())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800398 return NOTIFY_DONE;
399
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700400 hdd_notice("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800401 dev->name, state);
402
403 switch (state) {
404 case NETDEV_REGISTER:
405 break;
406
407 case NETDEV_UNREGISTER:
408 break;
409
410 case NETDEV_UP:
411 sme_ch_avoid_update_req(hdd_ctx->hHal);
412 break;
413
414 case NETDEV_DOWN:
415 break;
416
417 case NETDEV_CHANGE:
418 if (true == adapter->isLinkUpSvcNeeded)
419 complete(&adapter->linkup_event_var);
420 break;
421
422 case NETDEV_GOING_DOWN:
423 if (adapter->scan_info.mScanPending != false) {
424 unsigned long rc;
425 INIT_COMPLETION(adapter->scan_info.
426 abortscan_event_var);
427 hdd_abort_mac_scan(adapter->pHddCtx,
428 adapter->sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530429 INVALID_SCAN_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800430 eCSR_SCAN_ABORT_DEFAULT);
431 rc = wait_for_completion_timeout(
432 &adapter->scan_info.abortscan_event_var,
433 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
434 if (!rc) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700435 hdd_err("Timeout occurred while waiting for abortscan");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800436 }
437 } else {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700438 hdd_notice("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800439 }
440 break;
441
442 default:
443 break;
444 }
445
446 return NOTIFY_DONE;
447}
448
449/**
450 * hdd_netdev_notifier_call() - netdev notifier callback function
451 * @nb: pointer to notifier block
452 * @state: state
453 * @ndev: ndev pointer
454 *
455 * Return: 0 on success, error number otherwise.
456 */
457static int hdd_netdev_notifier_call(struct notifier_block *nb,
458 unsigned long state,
459 void *ndev)
460{
461 int ret;
462
463 cds_ssr_protect(__func__);
464 ret = __hdd_netdev_notifier_call(nb, state, ndev);
465 cds_ssr_unprotect(__func__);
466
467 return ret;
468}
469
470struct notifier_block hdd_netdev_notifier = {
471 .notifier_call = hdd_netdev_notifier_call,
472};
473
474/* variable to hold the insmod parameters */
475static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800476
477/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530480/**
481 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
482 * @ch_width: NL channel width
483 *
484 * Converts the NL channel width to the driver's internal representation
485 *
486 * Return: Converted channel width. In case of non matching NL channel width,
487 * CH_WIDTH_MAX will be returned.
488 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800489enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530490{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800491 uint8_t fw_ch_bw;
492 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530493 switch (ch_width) {
494 case NL80211_CHAN_WIDTH_20_NOHT:
495 case NL80211_CHAN_WIDTH_20:
496 return CH_WIDTH_20MHZ;
497 case NL80211_CHAN_WIDTH_40:
498 return CH_WIDTH_40MHZ;
499 break;
500 case NL80211_CHAN_WIDTH_80:
501 return CH_WIDTH_80MHZ;
502 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800503 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
504 return CH_WIDTH_80P80MHZ;
505 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
506 return CH_WIDTH_160MHZ;
507 else
508 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530509 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800510 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
511 return CH_WIDTH_160MHZ;
512 else
513 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530514 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800515 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530516 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800517 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530518 default:
519 hdd_err("Invalid channel width %d, setting to default",
520 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800521 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530522 }
523}
524
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530525/* wlan_hdd_find_opclass() - Find operating class for a channel
526 * @hal: handler to HAL
527 * @channel: channel id
528 * @bw_offset: bandwidth offset
529 *
530 * Function invokes sme api to find the operating class
531 *
532 * Return: operating class
533 */
534uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
535 uint8_t bw_offset)
536{
537 uint8_t opclass = 0;
538
539 sme_get_opclass(hal, channel, bw_offset, &opclass);
540 return opclass;
541}
542
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530544 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530545 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800546 * @bitmask: Bitmask of log levels to be enabled
547 *
548 * Called immediately after the cfg.ini is read in order to configure
549 * the desired trace levels.
550 *
551 * Return: None
552 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530553int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800554{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530555 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530556 int qdf_print_idx = -1;
557 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558 /*
559 * if the bitmask is the default value, then a bitmask was not
560 * specified in cfg.ini, so leave the logging level alone (it
561 * will remain at the "compiled in" default value)
562 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530563 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask) {
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530564 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800565 }
566
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530567 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800568
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530569 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530570 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530571 QDF_TRACE_LEVEL_NONE, 0);
572
573 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530574 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800575 /* now cycle through the bitmask until all "set" bits are serviced */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530576 level = QDF_TRACE_LEVEL_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800577 while (0 != bitmask) {
578 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530579 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530580 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530581 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530582 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583 }
584 level++;
585 bitmask >>= 1;
586 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530587 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800588}
589
590/**
591 * wlan_hdd_validate_context() - check the HDD context
592 * @hdd_ctx: HDD context pointer
593 *
594 * Return: 0 if the context is valid. Error code otherwise
595 */
596int wlan_hdd_validate_context(hdd_context_t *hdd_ctx)
597{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800598 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530599 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 return -ENODEV;
601 }
602
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800603 if (cds_is_driver_recovering()) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530604 hdd_err("%pS Recovery in Progress. State: 0x%x Ignore!!!",
605 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606 return -EAGAIN;
607 }
608
Rajeev Kumarfec3dbe2016-01-19 15:23:52 -0800609 if (cds_is_load_or_unload_in_progress()) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530610 hdd_err("%pS Unloading/Loading in Progress. Ignore!!!: 0x%x",
611 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800612 return -EAGAIN;
613 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530614
615 if (hdd_ctx->start_modules_in_progress ||
616 hdd_ctx->stop_modules_in_progress) {
617 hdd_err("%pS Start/Stop Modules in progress. Ignore!!!",
618 (void *)_RET_IP_);
619 return -EAGAIN;
620 }
621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800622 return 0;
623}
624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800625/**
626 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
627 * @hdd_adapter_t Hdd adapter.
628 *
629 * This function sets the IBSS power save config parameters to WMA
630 * which will send it to firmware if FW supports IBSS power save
631 * before vdev start.
632 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530633 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800634 * on failure.
635 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530636QDF_STATUS hdd_set_ibss_power_save_params(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800637{
638 int ret;
639 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
640
641 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700642 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530643 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800644 }
645
646 ret = wma_cli_set_command(adapter->sessionId,
647 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
648 hdd_ctx->config->ibssATIMWinSize,
649 VDEV_CMD);
650 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700651 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530652 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800653 }
654
655 ret = wma_cli_set_command(adapter->sessionId,
656 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
657 hdd_ctx->config->isIbssPowerSaveAllowed,
658 VDEV_CMD);
659 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700660 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
661 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530662 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663 }
664
665 ret = wma_cli_set_command(adapter->sessionId,
666 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
667 hdd_ctx->config->
668 isIbssPowerCollapseAllowed, VDEV_CMD);
669 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700670 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
671 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530672 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673 }
674
675 ret = wma_cli_set_command(adapter->sessionId,
676 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
677 hdd_ctx->config->isIbssAwakeOnTxRx,
678 VDEV_CMD);
679 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700680 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530681 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800682 }
683
684 ret = wma_cli_set_command(adapter->sessionId,
685 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
686 hdd_ctx->config->ibssInactivityCount,
687 VDEV_CMD);
688 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700689 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530690 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 }
692
693 ret = wma_cli_set_command(adapter->sessionId,
694 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
695 hdd_ctx->config->ibssTxSpEndInactivityTime,
696 VDEV_CMD);
697 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700698 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
699 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530700 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800701 }
702
703 ret = wma_cli_set_command(adapter->sessionId,
704 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
705 hdd_ctx->config->ibssPsWarmupTime,
706 VDEV_CMD);
707 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700708 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
709 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530710 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800711 }
712
713 ret = wma_cli_set_command(adapter->sessionId,
714 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
715 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
716 VDEV_CMD);
717 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700718 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
719 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530720 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800721 }
722
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530723 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724}
725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726#define INTF_MACADDR_MASK 0x7
727
728/**
729 * hdd_update_macaddr() - update mac address
730 * @config: hdd configuration
731 * @hw_macaddr: mac address
732 *
733 * Mac address for multiple virtual interface is found as following
734 * i) The mac address of the first interface is just the actual hw mac address.
735 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
736 * define the mac address for the remaining interfaces and locally
737 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
738 * supported virtual interfaces, right now this is 0x07 (meaning 8
739 * interface).
740 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
741 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
742 *
743 * Return: None
744 */
745void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530746 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747{
748 int8_t i;
749 uint8_t macaddr_b3, tmp_br3;
750
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530751 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530752 QDF_MAC_ADDR_SIZE);
753 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530754 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530755 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756 macaddr_b3 = config->intfMacAddr[i].bytes[3];
757 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
758 INTF_MACADDR_MASK;
759 macaddr_b3 += tmp_br3;
760
761 /* XOR-ing bit-24 of the mac address. This will give enough
762 * mac address range before collision
763 */
764 macaddr_b3 ^= (1 << 7);
765
766 /* Set locally administered bit */
767 config->intfMacAddr[i].bytes[0] |= 0x02;
768 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700769 hdd_notice("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770 MAC_ADDRESS_STR, i,
771 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
772 }
773}
774
775static void hdd_update_tgt_services(hdd_context_t *hdd_ctx,
776 struct wma_tgt_services *cfg)
777{
778 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800779
780 /* Set up UAPSD */
781 config->apUapsdEnabled &= cfg->uapsd;
782
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783 /* 11AC mode support */
784 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
785 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
786 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787
788 /* ARP offload: override user setting if invalid */
789 config->fhostArpOffload &= cfg->arp_offload;
790
791#ifdef FEATURE_WLAN_SCAN_PNO
792 /* PNO offload */
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700793 hdd_info("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794 if (cfg->pno_offload)
795 config->PnoOffload = true;
796#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800797#ifdef FEATURE_WLAN_TDLS
798 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530799 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
800 cfg->en_tdls_offchan;
801 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
802 cfg->en_tdls_uapsd_buf_sta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta) {
804 config->fEnableTDLSSleepSta = true;
805 } else {
806 config->fEnableTDLSSleepSta = false;
807 }
808#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809#ifdef WLAN_FEATURE_ROAM_OFFLOAD
810 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
811#endif
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700812 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813
814}
815
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700816/**
817 * hdd_update_vdev_nss() - sets the vdev nss
818 * @hdd_ctx: HDD context
819 *
820 * Sets the Nss per vdev type based on INI
821 *
822 * Return: None
823 */
824static void hdd_update_vdev_nss(hdd_context_t *hdd_ctx)
825{
826 struct hdd_config *cfg_ini = hdd_ctx->config;
827 uint8_t max_supp_nss = 1;
828
Naveen Rawat10b1c152017-01-18 11:16:06 -0800829 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700830 max_supp_nss = 2;
831
832 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
833 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
834
835 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
836 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
837}
838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839static void hdd_update_tgt_ht_cap(hdd_context_t *hdd_ctx,
840 struct wma_tgt_ht_cap *cfg)
841{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530842 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843 uint32_t value, val32;
844 uint16_t val16;
845 struct hdd_config *pconfig = hdd_ctx->config;
846 tSirMacHTCapabilityInfo *phtCapInfo;
847 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
848 uint8_t enable_tx_stbc;
849
850 /* check and update RX STBC */
851 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
852 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
853
854 /* get the MPDU density */
855 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
856
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530857 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700858 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 value = 0;
860 }
861
862 /*
863 * MPDU density:
864 * override user's setting if value is larger
865 * than the one supported by target
866 */
867 if (value > cfg->mpdu_density) {
868 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
869 cfg->mpdu_density);
870
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530871 if (status == QDF_STATUS_E_FAILURE)
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700872 hdd_alert("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 }
874
875 /* get the HT capability info */
876 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530877 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700878 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 return;
880 }
881 val16 = (uint16_t) val32;
882 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
883
884 /* Set the LDPC capability */
885 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
886
887 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
888 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
889
890 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
891 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
892
893 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
894 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
895
896 enable_tx_stbc = pconfig->enableTxSTBC;
897
898 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
899 pconfig->enable2x2 = 1;
900 } else {
901 pconfig->enable2x2 = 0;
902 enable_tx_stbc = 0;
903
904 /* 1x1 */
905 /* Update Rx Highest Long GI data Rate */
906 if (sme_cfg_set_int(hdd_ctx->hHal,
907 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700908 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530909 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700910 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 }
912
913 /* Update Tx Highest Long GI data Rate */
914 if (sme_cfg_set_int
915 (hdd_ctx->hHal,
916 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700917 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530918 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700919 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 }
921 }
922 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
923 enable_tx_stbc = 0;
924 phtCapInfo->txSTBC = enable_tx_stbc;
925
926 val32 = val16;
927 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530928 if (status != QDF_STATUS_SUCCESS)
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700929 hdd_alert("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
931 value = SIZE_OF_SUPPORTED_MCS_SET;
932 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530933 &value) == QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700934 hdd_notice("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935
936 if (pconfig->enable2x2) {
937 for (value = 0; value < cfg->num_rf_chains; value++)
938 mcs_set[value] =
939 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
940
941 status =
942 sme_cfg_set_str(hdd_ctx->hHal,
943 WNI_CFG_SUPPORTED_MCS_SET,
944 mcs_set,
945 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530946 if (status == QDF_STATUS_E_FAILURE)
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700947 hdd_alert("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948 }
949 }
950#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
951}
952
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953static void hdd_update_tgt_vht_cap(hdd_context_t *hdd_ctx,
954 struct wma_tgt_vht_cap *cfg)
955{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530956 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 uint32_t value = 0;
958 struct hdd_config *pconfig = hdd_ctx->config;
959 struct wiphy *wiphy = hdd_ctx->wiphy;
960 struct ieee80211_supported_band *band_5g =
Dustin Browna30892e2016-10-12 17:28:36 -0700961 wiphy->bands[NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700962 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800963 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964
Dustin Brown5e06bd32016-10-04 12:49:10 -0700965 if (!band_5g) {
966 hdd_info("5GHz band disabled, skipping capability population");
967 return;
968 }
969
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800970 /* Get the current MPDU length */
971 status =
972 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
973 &value);
974
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530975 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700976 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 value = 0;
978 }
979
980 /*
981 * VHT max MPDU length:
982 * override if user configured value is too high
983 * that the target cannot support
984 */
985 if (value > cfg->vht_max_mpdu) {
986 status = sme_cfg_set_int(hdd_ctx->hHal,
987 WNI_CFG_VHT_MAX_MPDU_LENGTH,
988 cfg->vht_max_mpdu);
989
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530990 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700991 hdd_alert("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992 }
993 }
994
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700995 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
996 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
997
998 if (pconfig->enable2x2)
999 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1000
1001 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1002 QDF_STATUS_E_FAILURE) {
1003 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1004 }
1005
1006 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1007 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1008 if (pconfig->enable2x2)
1009 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1010
1011 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1012 QDF_STATUS_E_FAILURE) {
1013 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1014 }
1015
1016 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1017 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1018 if (pconfig->enable2x2)
1019 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1020
1021 hdd_info("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
1022 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1023
1024 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1025 QDF_STATUS_E_FAILURE) {
1026 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1027 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001029 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001030 &value);
1031
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301032 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001033 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 value = 0;
1035 }
1036
1037 /* Set the LDPC capability */
1038 if (value && !cfg->vht_rx_ldpc) {
1039 status = sme_cfg_set_int(hdd_ctx->hHal,
1040 WNI_CFG_VHT_LDPC_CODING_CAP,
1041 cfg->vht_rx_ldpc);
1042
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301043 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001044 hdd_alert("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045 }
1046 }
1047
1048 /* Get current GI 80 value */
1049 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1050 &value);
1051
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301052 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001053 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 value = 0;
1055 }
1056
1057 /* set the Guard interval 80MHz */
1058 if (value && !cfg->vht_short_gi_80) {
1059 status = sme_cfg_set_int(hdd_ctx->hHal,
1060 WNI_CFG_VHT_SHORT_GI_80MHZ,
1061 cfg->vht_short_gi_80);
1062
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301063 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001064 hdd_alert("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 }
1066 }
1067
1068 /* Get current GI 160 value */
1069 status = sme_cfg_get_int(hdd_ctx->hHal,
1070 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1071 &value);
1072
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301073 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001074 hdd_err("could not get SHORT GI 80 & 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075 value = 0;
1076 }
1077
1078 /* Get VHT TX STBC cap */
1079 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1080
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301081 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001082 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 value = 0;
1084 }
1085
1086 /* VHT TX STBC cap */
1087 if (value && !cfg->vht_tx_stbc) {
1088 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1089 cfg->vht_tx_stbc);
1090
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301091 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001092 hdd_alert("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 }
1094 }
1095
1096 /* Get VHT RX STBC cap */
1097 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1098
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301099 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001100 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101 value = 0;
1102 }
1103
1104 /* VHT RX STBC cap */
1105 if (value && !cfg->vht_rx_stbc) {
1106 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1107 cfg->vht_rx_stbc);
1108
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301109 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001110 hdd_alert("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 }
1112 }
1113
1114 /* Get VHT SU Beamformer cap */
1115 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1116 &value);
1117
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301118 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001119 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001120 value = 0;
1121 }
1122
1123 /* set VHT SU Beamformer cap */
1124 if (value && !cfg->vht_su_bformer) {
1125 status = sme_cfg_set_int(hdd_ctx->hHal,
1126 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1127 cfg->vht_su_bformer);
1128
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301129 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001130 hdd_alert("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 }
1132 }
1133
1134 /* check and update SU BEAMFORMEE capabality */
1135 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1136 pconfig->enableTxBF = cfg->vht_su_bformee;
1137
1138 status = sme_cfg_set_int(hdd_ctx->hHal,
1139 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1140 pconfig->enableTxBF);
1141
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301142 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001143 hdd_alert("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 }
1145
1146 /* Get VHT MU Beamformer cap */
1147 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1148 &value);
1149
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301150 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001151 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001152 value = 0;
1153 }
1154
1155 /* set VHT MU Beamformer cap */
1156 if (value && !cfg->vht_mu_bformer) {
1157 status = sme_cfg_set_int(hdd_ctx->hHal,
1158 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1159 cfg->vht_mu_bformer);
1160
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301161 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001162 hdd_alert("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 }
1164 }
1165
1166 /* Get VHT MU Beamformee cap */
1167 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1168 &value);
1169
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301170 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001171 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172 value = 0;
1173 }
1174
1175 /* set VHT MU Beamformee cap */
1176 if (value && !cfg->vht_mu_bformee) {
1177 status = sme_cfg_set_int(hdd_ctx->hHal,
1178 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1179 cfg->vht_mu_bformee);
1180
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301181 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001182 hdd_alert("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001183 }
1184 }
1185
1186 /* Get VHT MAX AMPDU Len exp */
1187 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1188 &value);
1189
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301190 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001191 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 value = 0;
1193 }
1194
1195 /*
1196 * VHT max AMPDU len exp:
1197 * override if user configured value is too high
1198 * that the target cannot support.
1199 * Even though Rome publish ampdu_len=7, it can
1200 * only support 4 because of some h/w bug.
1201 */
1202
1203 if (value > cfg->vht_max_ampdu_len_exp) {
1204 status = sme_cfg_set_int(hdd_ctx->hHal,
1205 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1206 cfg->vht_max_ampdu_len_exp);
1207
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301208 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001209 hdd_alert("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001210 }
1211 }
1212
1213 /* Get VHT TXOP PS CAP */
1214 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1215
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301216 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001217 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001218 value = 0;
1219 }
1220
1221 /* set VHT TXOP PS cap */
1222 if (value && !cfg->vht_txop_ps) {
1223 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1224 cfg->vht_txop_ps);
1225
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301226 if (status == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001227 hdd_alert("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001228 }
1229 }
1230
1231 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1232 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1233 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1234 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1235 else
1236 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1237
1238
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001239 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1240 status = sme_cfg_set_int(hdd_ctx->hHal,
1241 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1242 VHT_CAP_160_AND_80P80_SUPP);
1243 if (status == QDF_STATUS_E_FAILURE)
1244 hdd_alert("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 band_5g->vht_cap.cap |=
1246 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001247 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1248 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1249 status = sme_cfg_set_int(hdd_ctx->hHal,
1250 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1251 VHT_CAP_160_SUPP);
1252 if (status == QDF_STATUS_E_FAILURE)
1253 hdd_alert("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254 band_5g->vht_cap.cap |=
1255 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001256 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1257 }
1258 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1259 ch_width);
1260 /* Get the current supported chan width */
1261 status = sme_cfg_get_int(hdd_ctx->hHal,
1262 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1263 &value);
1264 if (status != QDF_STATUS_SUCCESS) {
1265 hdd_err("could not get CH BW");
1266 value = 0;
1267 }
1268 /* set the Guard interval 80MHz */
1269 if (value) {
1270 status = sme_cfg_set_int(hdd_ctx->hHal,
1271 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1272 cfg->vht_short_gi_160);
1273
1274 if (status == QDF_STATUS_E_FAILURE)
1275 hdd_alert("failed to set SHORT GI 80MHZ");
1276 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277
1278 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1279 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1280
1281 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1282 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1283 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1284 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1285
1286 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1287 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1288
1289 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1290 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1291 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1292 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1293 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1294 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1295
1296 band_5g->vht_cap.cap |=
1297 (cfg->vht_max_ampdu_len_exp <<
1298 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1299
1300 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1301 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1302 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1303 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1304 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1305 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1306 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1307 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1308
1309 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1310 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1311
1312}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001314/**
1315 * hdd_generate_macaddr_auto() - Auto-generate mac address
1316 * @hdd_ctx: Pointer to the HDD context
1317 *
1318 * Auto-generate mac address using device serial number.
1319 * Keep the first 3 bytes of OUI as before and replace
1320 * the last 3 bytes with the lower 3 bytes of serial number.
1321 *
1322 * Return: 0 for success
1323 * Non zero failure code for errors
1324 */
1325static int hdd_generate_macaddr_auto(hdd_context_t *hdd_ctx)
1326{
1327 unsigned int serialno = 0;
1328 struct qdf_mac_addr mac_addr = {
1329 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1330 };
1331
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001332 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001333 if (serialno == 0)
1334 return -EINVAL;
1335
1336 serialno &= 0x00ffffff;
1337
1338 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1339 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1340 mac_addr.bytes[5] = serialno & 0xff;
1341
1342 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1343 return 0;
1344}
1345
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301346/**
1347 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1348 * configuration to cfg_ini in HDD
1349 * @hdd_ctx: Pointer to hdd_ctx
1350 * @cfg: target configuration
1351 *
1352 * Return: None
1353 */
1354#ifdef FEATURE_WLAN_RA_FILTERING
1355static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1356 struct wma_tgt_cfg *cfg)
1357{
1358 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1359}
1360#else
1361static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1362 struct wma_tgt_cfg *cfg)
1363{
1364}
1365#endif
1366
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367void hdd_update_tgt_cfg(void *context, void *param)
1368{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001369 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1371 struct wma_tgt_cfg *cfg = param;
1372 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001373 struct cds_config_info *cds_cfg = cds_get_ini_config();
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301374
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001375 ret = hdd_create_and_store_pdev(hdd_ctx);
1376 if (ret) {
1377 hdd_err("pdev creation fails!");
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301378 QDF_BUG(0);
1379 }
Naveen Rawat64e477e2016-05-20 10:34:56 -07001380
1381 if (cds_cfg) {
1382 if (hdd_ctx->config->enable_sub_20_channel_width !=
1383 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1384 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1385 cds_cfg->sub_20_channel_width =
1386 WLAN_SUB_20_CH_WIDTH_NONE;
1387 } else {
1388 cds_cfg->sub_20_channel_width =
1389 hdd_ctx->config->enable_sub_20_channel_width;
1390 }
1391 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392
1393 /* first store the INI band capability */
1394 temp_band_cap = hdd_ctx->config->nBandCapability;
1395
1396 hdd_ctx->config->nBandCapability = cfg->band_cap;
1397
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001398 /*
1399 * now overwrite the target band capability with INI
1400 * setting if INI setting is a subset
1401 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402
1403 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1404 (temp_band_cap != eCSR_BAND_ALL))
1405 hdd_ctx->config->nBandCapability = temp_band_cap;
1406 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1407 (temp_band_cap != eCSR_BAND_ALL) &&
1408 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001409 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001410 }
1411
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001412 if (!cds_is_driver_recovering()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1414 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1415 }
1416
1417 /* This can be extended to other configurations like ht, vht cap... */
1418
Anurag Chouhanc5548422016-02-24 18:33:27 +05301419 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001421 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001422 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001423 static struct qdf_mac_addr default_mac_addr = {
1424 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1425 };
1426 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1427 &default_mac_addr)) {
1428 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1429 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1430 MAC_ADDRESS_STR,
1431 MAC_ADDR_ARRAY(hdd_ctx->config->
1432 intfMacAddr[0].bytes));
1433 } else {
1434 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1435 MAC_ADDRESS_STR,
1436 MAC_ADDR_ARRAY(hdd_ctx->config->
1437 intfMacAddr[0].bytes));
1438 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001439 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 }
1441
1442 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001443 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001444
1445 hdd_ctx->max_intf_count = cfg->max_intf_count;
1446
Jeff Johnsonc875e242016-09-23 18:12:34 -07001447 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001448 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001449
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1451 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1452
1453 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1454
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001456 if (cfg->services.en_11ax) {
1457 hdd_info("11AX: 11ax is enabled - update HDD config");
1458 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1459 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001460
1461 hdd_update_vdev_nss(hdd_ctx);
1462
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001463 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001464 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001465 hdd_info("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001466 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001467
1468 hdd_ctx->current_antenna_mode =
1469 (hdd_ctx->config->enable2x2 == 0x01) ?
1470 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1471 hdd_info("Init current antenna mode: %d",
1472 hdd_ctx->current_antenna_mode);
1473
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001474 hdd_info("Target BPF %d Host BPF %d",
1475 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable);
1476 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1477 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301478 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301479
Arun Khandavallid454d422016-08-17 12:47:05 +05301480 /*
1481 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1482 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1483 * configure the STA mode wow pattern.
1484 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301485 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301486 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301487
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301488 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1489
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001490 /* Configure NAN datapath features */
1491 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001492}
1493
1494/**
1495 * hdd_dfs_indicate_radar() - handle radar detection on current SAP channel
1496 * @context: HDD context pointer
1497 * @param: HDD radar indication pointer
1498 *
Sandeep Puligillaa8d4eec2016-06-30 15:13:11 -07001499 * This function is invoked in atomic context when a radar
1500 * is found on the SAP current operating channel and Data Tx
1501 * from netif has to be stopped to honor the DFS regulations.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001502 * Actions: Stop the netif Tx queues,Indicate Radar present
1503 * in HDD context for future usage.
1504 *
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301505 * Return: true to allow radar indication to host else false
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001506 */
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301507bool hdd_dfs_indicate_radar(void *context, void *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001508{
1509 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1510 struct wma_dfs_radar_ind *hdd_radar_event =
1511 (struct wma_dfs_radar_ind *)param;
1512 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1513 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301514 QDF_STATUS status;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301515 hdd_ap_ctx_t *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301517 if (!hdd_ctx || !hdd_radar_event ||
1518 hdd_ctx->config->disableDFSChSwitch)
1519 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520
1521 if (true == hdd_radar_event->dfs_radar_status) {
Arif Hussain2a7c1f32016-07-18 14:24:36 -07001522 if (qdf_atomic_inc_return(&hdd_ctx->dfs_radar_found) > 1) {
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301523 /*
1524 * Application already triggered channel switch
1525 * on current channel, so return here.
1526 */
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301527 return false;
1528 }
1529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301531 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 adapter = adapterNode->pAdapter;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301533 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1534 if ((QDF_SAP_MODE == adapter->device_mode ||
1535 QDF_P2P_GO_MODE == adapter->device_mode) &&
1536 (CHANNEL_STATE_DFS ==
1537 cds_get_channel_state(ap_ctx->operatingChannel))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001538 WLAN_HDD_GET_AP_CTX_PTR(adapter)->
1539 dfs_cac_block_tx = true;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301540 hdd_info("tx blocked for session:%d",
1541 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 }
1543
1544 status = hdd_get_next_adapter(hdd_ctx,
1545 adapterNode,
1546 &pNext);
1547 adapterNode = pNext;
1548 }
1549 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301550
1551 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553
1554/**
1555 * hdd_is_valid_mac_address() - validate MAC address
1556 * @pMacAddr: Pointer to the input MAC address
1557 *
1558 * This function validates whether the given MAC address is valid or not
1559 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1560 * where X is the hexa decimal digit character and separated by ':'
1561 * This algorithm works even if MAC address is not separated by ':'
1562 *
1563 * This code checks given input string mac contains exactly 12 hexadecimal
1564 * digits and a separator colon : appears in the input string only after
1565 * an even number of hex digits.
1566 *
1567 * Return: 1 for valid and 0 for invalid
1568 */
1569bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1570{
1571 int xdigit = 0;
1572 int separator = 0;
1573 while (*pMacAddr) {
1574 if (isxdigit(*pMacAddr)) {
1575 xdigit++;
1576 } else if (':' == *pMacAddr) {
1577 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1578 break;
1579
1580 ++separator;
1581 } else {
1582 /* Invalid MAC found */
1583 return 0;
1584 }
1585 ++pMacAddr;
1586 }
1587 return xdigit == 12 && (separator == 5 || separator == 0);
1588}
1589
1590/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301591 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1592 * @dev: Handle to struct net_device to be updated.
1593 *
1594 * Return: None
1595 */
1596static void hdd_mon_mode_ether_setup(struct net_device *dev)
1597{
1598 dev->header_ops = NULL;
1599 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1600 dev->hard_header_len = ETH_HLEN;
1601 dev->mtu = ETH_DATA_LEN;
1602 dev->addr_len = ETH_ALEN;
1603 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1604 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1605 dev->priv_flags |= IFF_TX_SKB_SHARING;
1606
1607 memset(dev->broadcast, 0xFF, ETH_ALEN);
1608}
1609
1610/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001611 * __hdd__mon_open() - HDD Open function
1612 * @dev: Pointer to net_device structure
1613 *
1614 * This is called in response to ifconfig up
1615 *
1616 * Return: 0 for success; non-zero for failure
1617 */
1618static int __hdd_mon_open(struct net_device *dev)
1619{
1620 int ret;
1621
1622 ENTER_DEV(dev);
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301623 hdd_mon_mode_ether_setup(dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001624 ret = hdd_set_mon_rx_cb(dev);
1625 return ret;
1626}
1627
1628/**
1629 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1630 * @dev: Pointer to net_device structure
1631 *
1632 * This is called in response to ifconfig up
1633 *
1634 * Return: 0 for success; non-zero for failure
1635 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001636static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001637{
1638 int ret;
1639
1640 cds_ssr_protect(__func__);
1641 ret = __hdd_mon_open(dev);
1642 cds_ssr_unprotect(__func__);
1643
1644 return ret;
1645}
1646
1647/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301648 * hdd_start_adapter() - Wrapper function for device specific adapter
1649 * @adapter: pointer to HDD adapter
1650 *
1651 * This function is called to start the device specific adapter for
1652 * the mode passed in the adapter's device_mode.
1653 *
1654 * Return: 0 for success; non-zero for failure
1655 */
1656int hdd_start_adapter(hdd_adapter_t *adapter)
1657{
1658
1659 int ret;
1660 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1661
1662 ENTER_DEV(adapter->dev);
1663 hdd_info("Start_adapter for mode : %d", adapter->device_mode);
1664
1665 switch (device_mode) {
1666 case QDF_P2P_CLIENT_MODE:
1667 case QDF_P2P_DEVICE_MODE:
1668 case QDF_OCB_MODE:
1669 case QDF_STA_MODE:
1670 case QDF_MONITOR_MODE:
1671 ret = hdd_start_station_adapter(adapter);
1672 if (ret)
1673 goto err_start_adapter;
1674 break;
1675 case QDF_P2P_GO_MODE:
1676 case QDF_SAP_MODE:
1677 ret = hdd_start_ap_adapter(adapter);
1678 if (ret)
1679 goto err_start_adapter;
1680 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301681 case QDF_IBSS_MODE:
1682 /*
1683 * For IBSS interface is initialized as part of
1684 * hdd_init_station_mode()
1685 */
1686 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301687 case QDF_FTM_MODE:
1688 ret = hdd_start_ftm_adapter(adapter);
1689 if (ret)
1690 goto err_start_adapter;
1691 break;
1692 default:
1693 hdd_err("Invalid session type %d", device_mode);
1694 QDF_ASSERT(0);
1695 goto err_start_adapter;
1696 }
1697 if (hdd_set_fw_params(adapter))
1698 hdd_err("Failed to set the FW params for the adapter!");
1699
1700 /*
1701 * Action frame registered in one adapter which will
1702 * applicable to all interfaces
1703 */
1704 wlan_hdd_cfg80211_register_frames(adapter);
1705 EXIT();
1706 return 0;
1707err_start_adapter:
1708 return -EINVAL;
1709}
1710
1711/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301712 * hdd_enable_power_management() - API to Enable Power Management
1713 *
1714 * API invokes Bus Interface Layer power management functionality
1715 *
1716 * Return: None
1717 */
1718static void hdd_enable_power_management(void)
1719{
1720 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1721
1722 if (!hif_ctx) {
1723 hdd_err("Bus Interface Context is Invalid");
1724 return;
1725 }
1726
1727 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1728}
1729
1730/**
1731 * hdd_disable_power_management() - API to disable Power Management
1732 *
1733 * API disable Bus Interface Layer Power management functionality
1734 *
1735 * Return: None
1736 */
1737static void hdd_disable_power_management(void)
1738{
1739 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1740
1741 if (!hif_ctx) {
1742 hdd_err("Bus Interface Context is Invalid");
1743 return;
1744 }
1745
1746 hif_disable_power_management(hif_ctx);
1747}
1748
1749/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301750 * hdd_update_hw_sw_info() - API to update the HW/SW information
1751 *
1752 * API to update the HW and SW information in the driver
1753 *
1754 * Return: None
1755 */
1756static void hdd_update_hw_sw_info(hdd_context_t *hdd_ctx)
1757{
1758 void *hif_sc;
1759
1760 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1761 if (!hif_sc) {
1762 hdd_err("HIF context is NULL");
1763 return;
1764 }
1765
1766 /*
1767 * target hw version/revision would only be retrieved after firmware
1768 * download
1769 */
1770 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
1771 &hdd_ctx->target_hw_revision,
1772 &hdd_ctx->target_hw_name);
1773
1774 /* Get the wlan hw/fw version */
1775 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
1776
1777 return;
1778}
1779
1780/**
gbian62edd7e2017-03-07 13:12:13 +08001781 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
1782 * @hdd_ctx: Pointer to hdd context
1783 *
1784 * Return: none
1785 */
1786static void
1787hdd_update_cds_ac_specs_params(hdd_context_t *hdd_ctx)
1788{
1789 uint8_t num_entries = 0;
1790 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
1791 uint8_t *tx_sched_wrr_ac;
1792 int i;
1793 cds_context_type *cds_ctx;
1794
1795 if (NULL == hdd_ctx)
1796 return;
1797
1798 if (NULL == hdd_ctx->config) {
1799 /* Do nothing if hdd_ctx is invalid */
1800 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
1801 return;
1802 }
1803
1804 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1805
1806 if (!cds_ctx) {
1807 hdd_err("Invalid CDS Context");
1808 return;
1809 }
1810
1811 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
1812 switch (i) {
1813 case OL_TX_WMM_AC_BE:
1814 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
1815 break;
1816 case OL_TX_WMM_AC_BK:
1817 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
1818 break;
1819 case OL_TX_WMM_AC_VI:
1820 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
1821 break;
1822 case OL_TX_WMM_AC_VO:
1823 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
1824 break;
1825 default:
1826 tx_sched_wrr_ac = NULL;
1827 break;
1828 }
1829
1830 hdd_string_to_u8_array(tx_sched_wrr_ac,
1831 tx_sched_wrr_param,
1832 &num_entries,
1833 sizeof(tx_sched_wrr_param));
1834
1835 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
1836 cds_ctx->ac_specs[i].wrr_skip_weight =
1837 tx_sched_wrr_param[0];
1838 cds_ctx->ac_specs[i].credit_threshold =
1839 tx_sched_wrr_param[1];
1840 cds_ctx->ac_specs[i].send_limit =
1841 tx_sched_wrr_param[2];
1842 cds_ctx->ac_specs[i].credit_reserve =
1843 tx_sched_wrr_param[3];
1844 cds_ctx->ac_specs[i].discard_weight =
1845 tx_sched_wrr_param[4];
1846 }
1847
1848 num_entries = 0;
1849 }
1850}
1851
1852/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301853 * hdd_wlan_start_modules() - Single driver state machine for starting modules
1854 * @hdd_ctx: HDD context
1855 * @adapter: HDD adapter
1856 * @reinit: flag to indicate from SSR or normal path
1857 *
1858 * This function maintains the driver state machine it will be invoked from
1859 * startup, reinit and change interface. Depending on the driver state shall
1860 * perform the opening of the modules.
1861 *
1862 * Return: 0 for success; non-zero for failure
1863 */
1864int hdd_wlan_start_modules(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
1865 bool reinit)
1866{
1867 int ret;
1868 qdf_device_t qdf_dev;
1869 QDF_STATUS status;
1870 p_cds_contextType p_cds_context;
1871 bool unint = false;
1872 void *hif_ctx;
1873
1874 ENTER();
1875
1876 p_cds_context = cds_get_global_context();
1877 if (!p_cds_context) {
1878 hdd_err("Global Context is NULL");
1879 QDF_ASSERT(0);
1880 return -EINVAL;
1881 }
1882
1883 hdd_info("start modules called in state! :%d reinit: %d",
1884 hdd_ctx->driver_status, reinit);
1885
1886 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
1887 if (!qdf_dev) {
1888 hdd_err("QDF Device Context is Invalid return");
1889 return -EINVAL;
1890 }
1891
1892 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301893 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05301894
1895 if (QDF_TIMER_STATE_RUNNING ==
1896 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
1897
1898 hdd_set_idle_ps_config(hdd_ctx, false);
1899 hdd_info("Interface change Timer running Stop timer");
1900 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
1901 }
1902
1903 switch (hdd_ctx->driver_status) {
1904 case DRIVER_MODULES_UNINITIALIZED:
1905 unint = true;
1906 /* Fall through dont add break here */
1907 case DRIVER_MODULES_CLOSED:
1908 if (!reinit && !unint) {
1909 ret = pld_power_on(qdf_dev->dev);
1910 if (ret) {
1911 hdd_err("Failed to Powerup the device: %d", ret);
1912 goto release_lock;
1913 }
1914 }
1915 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
1916 qdf_dev->bus_type,
1917 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
1918 HIF_ENABLE_TYPE_PROBE);
1919 if (ret) {
1920 hdd_err("Failed to open hif: %d", ret);
1921 goto power_down;
1922 }
1923
1924 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05301925 if (!hif_ctx) {
1926 hdd_err("hif context is null!!");
1927 goto power_down;
1928 }
1929
Arun Khandavallifae92942016-08-01 13:31:08 +05301930 status = ol_cds_init(qdf_dev, hif_ctx);
1931 if (status != QDF_STATUS_SUCCESS) {
1932 hdd_err("No Memory to Create BMI Context :%d", status);
1933 goto hif_close;
1934 }
1935
Rajeev Kumar138ef912017-01-13 15:19:48 -08001936 ret = hdd_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
1937 if (ret) {
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301938 hdd_err("Psoc creation fails!");
1939 goto ol_cds_free;
1940 }
1941
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08001942 ret = hdd_update_config(hdd_ctx);
1943 if (ret) {
1944 hdd_err("Failed to update configuration :%d", ret);
1945 goto destroy_psoc_object;
1946 }
1947
gbian62edd7e2017-03-07 13:12:13 +08001948 hdd_update_cds_ac_specs_params(hdd_ctx);
1949
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301950 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05301951 if (!QDF_IS_STATUS_SUCCESS(status)) {
1952 hdd_err("Failed to Open CDS: %d", status);
Selvaraj, Sridhara7dc2382017-01-27 18:29:39 +05301953 goto destroy_psoc_object;
Arun Khandavallifae92942016-08-01 13:31:08 +05301954 }
1955
Mukul Sharma9d797a02017-01-05 20:26:03 +05301956 /* initalize components configurations after psoc open */
1957 ret = hdd_update_components_config(hdd_ctx);
1958 if (ret) {
1959 hdd_err("Failed to update components configs :%d",
1960 ret);
1961 goto close;
1962 }
1963
Arun Khandavallifae92942016-08-01 13:31:08 +05301964 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
1965
1966 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
1967
1968 status = cds_pre_enable(hdd_ctx->pcds_context);
1969 if (!QDF_IS_STATUS_SUCCESS(status)) {
1970 hdd_err("Failed to pre-enable CDS: %d", status);
1971 goto close;
1972 }
1973
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301974 hdd_update_hw_sw_info(hdd_ctx);
1975
Arun Khandavallifae92942016-08-01 13:31:08 +05301976 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
1977 sme_register_ftm_msg_processor(hdd_ctx->hHal,
1978 hdd_ftm_mc_process_msg);
1979 break;
1980 }
1981 if (unint) {
1982 hdd_info("In phase-1 initialization don't enable modules");
1983 break;
1984 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05301985
1986 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08001987 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
1988 hdd_err("HDD IPA UC reinit failed");
1989 goto close;
1990 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05301991 }
1992
Arun Khandavallifae92942016-08-01 13:31:08 +05301993 /* Fall through dont add break here */
1994 case DRIVER_MODULES_OPENED:
1995 if (!adapter) {
1996 hdd_alert("adapter is Null");
1997 goto close;
1998 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05301999 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2000 hdd_err("in ftm mode, no need to configure cds modules");
2001 break;
2002 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302003 if (hdd_configure_cds(hdd_ctx, adapter)) {
2004 hdd_err("Failed to Enable cds modules");
2005 goto close;
2006 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302007 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302008 hdd_info("Driver Modules Successfully Enabled");
2009 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2010 break;
2011 case DRIVER_MODULES_ENABLED:
2012 hdd_info("Driver modules already Enabled");
2013 break;
2014 default:
2015 hdd_err("WLAN start invoked in wrong state! :%d\n",
2016 hdd_ctx->driver_status);
2017 goto release_lock;
2018 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302019 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302020 mutex_unlock(&hdd_ctx->iface_change_lock);
2021 EXIT();
2022 return 0;
2023
2024close:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302025 cds_close(hdd_ctx->hdd_psoc, p_cds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05302026
Selvaraj, Sridhara7dc2382017-01-27 18:29:39 +05302027destroy_psoc_object:
2028 hdd_release_and_destroy_psoc(hdd_ctx);
2029
Arun Khandavallifae92942016-08-01 13:31:08 +05302030ol_cds_free:
2031 ol_cds_free();
2032
2033hif_close:
2034 hdd_hif_close(p_cds_context->pHIFContext);
2035power_down:
2036 if (!reinit && !unint)
2037 pld_power_off(qdf_dev->dev);
2038release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302039 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302040 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302041 EXIT();
Arun Khandavallifae92942016-08-01 13:31:08 +05302042 return -EINVAL;
2043}
2044
2045/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046 * __hdd_open() - HDD Open function
2047 * @dev: Pointer to net_device structure
2048 *
2049 * This is called in response to ifconfig up
2050 *
2051 * Return: 0 for success; non-zero for failure
2052 */
2053static int __hdd_open(struct net_device *dev)
2054{
2055 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2056 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2057 int ret;
2058
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002059 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302060 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302061 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062
2063 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302064 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302066
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002067
Arun Khandavallifae92942016-08-01 13:31:08 +05302068 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2069 if (ret) {
2070 hdd_err("Failed to start WLAN modules return");
2071 return -ret;
2072 }
2073
2074
2075 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2076 ret = hdd_start_adapter(adapter);
2077 if (ret) {
2078 hdd_err("Failed to start adapter :%d",
2079 adapter->device_mode);
2080 return ret;
2081 }
2082 }
2083
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002084 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2085 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Arun Khandavallifae92942016-08-01 13:31:08 +05302086 hdd_info("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002087 /* Enable TX queues only when we are connected */
2088 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302089 WLAN_START_ALL_NETIF_QUEUE,
2090 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002091 }
2092
Naveen Rawat286def52016-09-23 15:38:02 -07002093 /* Enable carrier and transmit queues for NDI */
2094 if (WLAN_HDD_IS_NDI(adapter)) {
2095 hdd_notice("Enabling Tx Queues");
2096 wlan_hdd_netif_queue_control(adapter,
2097 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2098 WLAN_CONTROL_PATH);
2099 }
2100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002101 return ret;
2102}
2103
Arun Khandavallifae92942016-08-01 13:31:08 +05302104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002105/**
2106 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2107 * @dev: Pointer to net_device structure
2108 *
2109 * This is called in response to ifconfig up
2110 *
2111 * Return: 0 for success; non-zero for failure
2112 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002113static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114{
2115 int ret;
2116
2117 cds_ssr_protect(__func__);
2118 ret = __hdd_open(dev);
2119 cds_ssr_unprotect(__func__);
2120
2121 return ret;
2122}
2123
2124/**
2125 * __hdd_stop() - HDD stop function
2126 * @dev: Pointer to net_device structure
2127 *
2128 * This is called in response to ifconfig down
2129 *
2130 * Return: 0 for success; non-zero for failure
2131 */
2132static int __hdd_stop(struct net_device *dev)
2133{
2134 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2135 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2136 int ret;
2137
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002138 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302140 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002141 adapter->sessionId, adapter->device_mode));
2142
2143 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302144 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002146
2147 /* Nothing to be done if the interface is not opened */
2148 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002149 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002150 return -ENODEV;
2151 }
2152
2153 /* Make sure the interface is marked as closed */
2154 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Jeff Johnson1346fab2016-08-15 13:09:42 -07002155 hdd_notice("Disabling OS Tx queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002156
2157 /*
2158 * Disable TX on the interface, after this hard_start_xmit() will not
2159 * be called on that interface
2160 */
Jeff Johnson1346fab2016-08-15 13:09:42 -07002161 hdd_notice("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002162 wlan_hdd_netif_queue_control(adapter, WLAN_NETIF_TX_DISABLE_N_CARRIER,
2163 WLAN_CONTROL_PATH);
2164
2165 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002166 * NAN data interface is different in some sense. The traffic on NDI is
2167 * bursty in nature and depends on the need to transfer. The service
2168 * layer may down the interface after the usage and up again when
2169 * required. In some sense, the NDI is expected to be available
2170 * (like SAP) iface until NDI delete request is issued by the service
2171 * layer. Skip BSS termination and adapter deletion for NAN Data
2172 * interface (NDI).
2173 */
2174 if (WLAN_HDD_IS_NDI(adapter))
2175 return 0;
2176
2177 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002178 * The interface is marked as down for outside world (aka kernel)
2179 * But the driver is pretty much alive inside. The driver needs to
2180 * tear down the existing connection on the netdev (session)
2181 * cleanup the data pipes and wait until the control plane is stabilized
2182 * for this interface. The call also needs to wait until the above
2183 * mentioned actions are completed before returning to the caller.
2184 * Notice that the hdd_stop_adapter is requested not to close the session
2185 * That is intentional to be able to scan if it is a STA/P2P interface
2186 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302187 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188
2189 /* DeInit the adapter. This ensures datapath cleanup as well */
2190 hdd_deinit_adapter(hdd_ctx, adapter, true);
2191
Arun Khandavallifae92942016-08-01 13:31:08 +05302192
2193 /*
2194 * Find if any iface is up. If any iface is up then can't put device to
2195 * sleep/power save mode
2196 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302197 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Arun Khandavallifae92942016-08-01 13:31:08 +05302198 hdd_info("Closing all modules from the hdd_stop");
2199 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
2200 hdd_ctx->config->iface_change_wait_time
2201 * 50000);
2202 }
2203
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002204 EXIT();
2205 return 0;
2206}
2207
2208/**
2209 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2210 * @dev: pointer to net_device structure
2211 *
2212 * This is called in response to ifconfig down
2213 *
2214 * Return: 0 for success and error number for failure
2215 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002216static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002217{
2218 int ret;
2219
2220 cds_ssr_protect(__func__);
2221 ret = __hdd_stop(dev);
2222 cds_ssr_unprotect(__func__);
2223
2224 return ret;
2225}
2226
2227/**
2228 * __hdd_uninit() - HDD uninit function
2229 * @dev: Pointer to net_device structure
2230 *
2231 * This is called during the netdev unregister to uninitialize all data
2232 * associated with the device
2233 *
2234 * Return: None
2235 */
2236static void __hdd_uninit(struct net_device *dev)
2237{
2238 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2239
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002240 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241
2242 do {
2243 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002244 hdd_alert("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002245 break;
2246 }
2247
2248 if (NULL == adapter->pHddCtx) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002249 hdd_alert("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250 break;
2251 }
2252
2253 if (dev != adapter->dev) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002254 hdd_alert("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002255 /*
2256 * we haven't validated all cases so let this go for
2257 * now
2258 */
2259 }
2260
2261 hdd_deinit_adapter(adapter->pHddCtx, adapter, true);
2262
2263 /* after uninit our adapter structure will no longer be valid */
2264 adapter->dev = NULL;
2265 adapter->magic = 0;
2266 } while (0);
2267
2268 EXIT();
2269}
2270
2271/**
2272 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2273 * @dev: pointer to net_device structure
2274 *
2275 * This is called during the netdev unregister to uninitialize all data
2276 * associated with the device
2277 *
2278 * Return: none
2279 */
2280static void hdd_uninit(struct net_device *dev)
2281{
2282 cds_ssr_protect(__func__);
2283 __hdd_uninit(dev);
2284 cds_ssr_unprotect(__func__);
2285}
2286
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002287static int hdd_open_cesium_nl_sock(void)
2288{
2289#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2290 struct netlink_kernel_cfg cfg = {
2291 .groups = WLAN_NLINK_MCAST_GRP_ID,
2292 .input = NULL
2293 };
2294#endif
2295 int ret = 0;
2296
2297#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2298 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2299#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2300 THIS_MODULE,
2301#endif
2302 &cfg);
2303#else
2304 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2305 WLAN_NLINK_MCAST_GRP_ID,
2306 NULL, NULL, THIS_MODULE);
2307#endif
2308
2309 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002310 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002311 ret = -ECONNREFUSED;
2312 }
2313
2314 return ret;
2315}
2316
2317static void hdd_close_cesium_nl_sock(void)
2318{
2319 if (NULL != cesium_nl_srv_sock) {
2320 netlink_kernel_release(cesium_nl_srv_sock);
2321 cesium_nl_srv_sock = NULL;
2322 }
2323}
2324
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002325/**
2326 * __hdd_set_mac_address() - set the user specified mac address
2327 * @dev: Pointer to the net device.
2328 * @addr: Pointer to the sockaddr.
2329 *
2330 * This function sets the user specified mac address using
2331 * the command ifconfig wlanX hw ether <mac adress>.
2332 *
2333 * Return: 0 for success, non zero for failure
2334 */
2335static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2336{
2337 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2338 hdd_context_t *hdd_ctx;
2339 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302340 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002341 int ret;
2342
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002343 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002344
2345 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2346 ret = wlan_hdd_validate_context(hdd_ctx);
2347 if (0 != ret)
2348 return ret;
2349
2350 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2351 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2352
2353 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302354 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002355}
2356
2357/**
2358 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2359 * function from SSR
2360 * @dev: pointer to net_device structure
2361 * @addr: Pointer to the sockaddr
2362 *
2363 * This function sets the user specified mac address using
2364 * the command ifconfig wlanX hw ether <mac adress>.
2365 *
2366 * Return: 0 for success.
2367 */
2368static int hdd_set_mac_address(struct net_device *dev, void *addr)
2369{
2370 int ret;
2371
2372 cds_ssr_protect(__func__);
2373 ret = __hdd_set_mac_address(dev, addr);
2374 cds_ssr_unprotect(__func__);
2375
2376 return ret;
2377}
2378
2379uint8_t *wlan_hdd_get_intf_addr(hdd_context_t *hdd_ctx)
2380{
2381 int i;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302382 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002383 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2384 break;
2385 }
2386
Anurag Chouhan6d760662016-02-20 16:05:43 +05302387 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002388 return NULL;
2389
2390 hdd_ctx->config->intfAddrMask |= (1 << i);
2391 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2392}
2393
2394void wlan_hdd_release_intf_addr(hdd_context_t *hdd_ctx, uint8_t *releaseAddr)
2395{
2396 int i;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302397 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002398 if (!memcmp(releaseAddr,
2399 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2400 6)) {
2401 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2402 break;
2403 }
2404 }
2405 return;
2406}
2407
2408#ifdef WLAN_FEATURE_PACKET_FILTERING
2409/**
2410 * __hdd_set_multicast_list() - set the multicast address list
2411 * @dev: Pointer to the WLAN device.
2412 * @skb: Pointer to OS packet (sk_buff).
2413 *
2414 * This funciton sets the multicast address list.
2415 *
2416 * Return: None
2417 */
2418static void __hdd_set_multicast_list(struct net_device *dev)
2419{
2420 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002421 int i = 0, status;
2422 struct netdev_hw_addr *ha;
2423 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302424 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2425 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2426 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002427
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002428 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302429 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302430 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002432 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302433 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302434 goto out;
2435
2436 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2437 if (!mc_list_request) {
2438 hdd_notice("Cannot allocate mc_list_request");
2439 goto out;
2440 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002441
2442 if (dev->flags & IFF_ALLMULTI) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002443 hdd_notice("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302444 hdd_disable_and_flush_mc_addr_list(adapter,
2445 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002446 } else {
2447 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302448 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Dustin Brown61269462016-09-19 13:25:45 -07002449 hdd_notice("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302450 pmo_ucfg_max_mc_addr_supported(psoc));
2451 hdd_disable_and_flush_mc_addr_list(adapter,
2452 pmo_mc_list_change_notify);
2453 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002454 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002455 netdev_for_each_mc_addr(ha, dev) {
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302456 hdd_notice("ha_addr[%d] "MAC_ADDRESS_STR,
2457 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002458 if (i == mc_count)
2459 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302460 memset(&(mc_list_request->mc_addr[i].bytes),
2461 0, ETH_ALEN);
2462 memcpy(&(mc_list_request->mc_addr[i].bytes),
2463 ha->addr, ETH_ALEN);
2464 hdd_info("mlist[%d] = %pM", i,
2465 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002466 i++;
2467 }
2468 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302469
2470 mc_list_request->psoc = psoc;
2471 mc_list_request->vdev_id = adapter->sessionId;
2472 mc_list_request->count = mc_count;
2473 status = hdd_cache_mc_addr_list(mc_list_request);
2474 if (status == 0) {
2475 hdd_enable_mc_addr_filtering(adapter,
2476 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002477 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302478 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002479 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302480out:
2481 if (mc_list_request)
2482 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302483 EXIT();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002485}
2486
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488/**
2489 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2490 * @dev: pointer to net_device
2491 *
2492 * Return: none
2493 */
2494static void hdd_set_multicast_list(struct net_device *dev)
2495{
2496 cds_ssr_protect(__func__);
2497 __hdd_set_multicast_list(dev);
2498 cds_ssr_unprotect(__func__);
2499}
2500#endif
2501
2502/**
2503 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2504 * @dev: Pointer to the WLAN device.
2505 * @skb: Pointer to OS packet (sk_buff).
2506 *
2507 * This function is registered with the Linux OS for network
2508 * core to decide which queue to use first.
2509 *
2510 * Return: ac, Queue Index/access category corresponding to UP in IP header
2511 */
2512static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2513#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2514 , void *accel_priv
2515#endif
2516#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2517 , select_queue_fallback_t fallback
2518#endif
2519)
2520{
2521 return hdd_wmm_select_queue(dev, skb);
2522}
2523
2524static struct net_device_ops wlan_drv_ops = {
2525 .ndo_open = hdd_open,
2526 .ndo_stop = hdd_stop,
2527 .ndo_uninit = hdd_uninit,
2528 .ndo_start_xmit = hdd_hard_start_xmit,
2529 .ndo_tx_timeout = hdd_tx_timeout,
2530 .ndo_get_stats = hdd_get_stats,
2531 .ndo_do_ioctl = hdd_ioctl,
2532 .ndo_set_mac_address = hdd_set_mac_address,
2533 .ndo_select_queue = hdd_select_queue,
2534#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002535 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002536#endif
2537};
2538
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002539/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
2540static struct net_device_ops wlan_mon_drv_ops = {
2541 .ndo_open = hdd_mon_open,
2542 .ndo_stop = hdd_stop,
2543 .ndo_get_stats = hdd_get_stats,
2544};
2545
2546/**
2547 * hdd_set_station_ops() - update net_device ops for monitor mode
2548 * @pWlanDev: Handle to struct net_device to be updated.
2549 * Return: None
2550 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002551void hdd_set_station_ops(struct net_device *pWlanDev)
2552{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002553 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2554 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2555 else
2556 pWlanDev->netdev_ops = &wlan_drv_ops;
2557}
2558
Komal Seelama89be8d2016-09-29 11:09:26 +05302559#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302560/**
2561 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2562 * @hdd_ctx: HDD context
2563 *
2564 * Return: None
2565 */
2566static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx)
2567{
2568 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2569
2570 ctx->scan = qdf_runtime_lock_init("scan");
Komal Seelamaa75f262016-09-29 12:32:13 +05302571 ctx->roc = qdf_runtime_lock_init("roc");
Komal Seelam81cb1662016-09-29 12:39:08 +05302572 ctx->dfs = qdf_runtime_lock_init("dfs");
Komal Seelam8634b772016-09-29 12:12:24 +05302573}
2574
2575/**
2576 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2577 * @hdd_ctx: HDD Context
2578 *
2579 * Return: None
2580 */
2581static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx)
2582{
2583 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2584
2585 qdf_runtime_lock_deinit(ctx->scan);
2586 ctx->scan = NULL;
Komal Seelamaa75f262016-09-29 12:32:13 +05302587 qdf_runtime_lock_deinit(ctx->roc);
2588 ctx->roc = NULL;
Komal Seelam81cb1662016-09-29 12:39:08 +05302589 qdf_runtime_lock_deinit(ctx->dfs);
2590 ctx->dfs = NULL;
Komal Seelam8634b772016-09-29 12:12:24 +05302591}
2592
Komal Seelama89be8d2016-09-29 11:09:26 +05302593static void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter)
2594{
2595 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2596
2597 ctx->connect = qdf_runtime_lock_init("connect");
2598}
2599
2600static void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter)
2601{
2602 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2603
2604 qdf_runtime_lock_deinit(ctx->connect);
2605 ctx->connect = NULL;
2606}
2607#else /* FEATURE_RUNTIME_PM */
Komal Seelam8634b772016-09-29 12:12:24 +05302608static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx) {}
2609static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302610static inline void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter) {}
2611static inline void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter) {}
2612#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002613/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002614 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2615 * @hdd_ctx: global hdd context
2616 * @macAddr: mac address to assign to the interface
2617 * @name: User-visible name of the interface
2618 *
2619 * hdd adapter pointer would point to the netdev->priv space, this function
2620 * would retrive the pointer, and setup the hdd adapter configuration.
2621 *
2622 * Return: the pointer to hdd adapter, otherwise NULL
2623 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002624static hdd_adapter_t *hdd_alloc_station_adapter(hdd_context_t *hdd_ctx,
2625 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002626 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002627 const char *name)
2628{
2629 struct net_device *pWlanDev = NULL;
2630 hdd_adapter_t *adapter = NULL;
2631 /*
2632 * cfg80211 initialization and registration....
2633 */
Ryan Hsu07495ea2016-01-21 15:25:39 -08002634 pWlanDev = alloc_netdev_mq(sizeof(hdd_adapter_t), name,
2635#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
2636 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002637#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002638 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
2639 hdd_mon_mode_ether_setup : ether_setup),
2640 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002641
2642 if (pWlanDev != NULL) {
2643
2644 /* Save the pointer to the net_device in the HDD adapter */
2645 adapter = (hdd_adapter_t *) netdev_priv(pWlanDev);
2646
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302647 qdf_mem_zero(adapter, sizeof(hdd_adapter_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002648
2649 adapter->dev = pWlanDev;
2650 adapter->pHddCtx = hdd_ctx;
2651 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05302652 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002653
2654 init_completion(&adapter->session_open_comp_var);
2655 init_completion(&adapter->session_close_comp_var);
2656 init_completion(&adapter->disconnect_comp_var);
2657 init_completion(&adapter->linkup_event_var);
2658 init_completion(&adapter->cancel_rem_on_chan_var);
2659 init_completion(&adapter->rem_on_chan_ready_event);
2660 init_completion(&adapter->sta_authorized_event);
2661 init_completion(&adapter->offchannel_tx_event);
2662 init_completion(&adapter->tx_action_cnf_event);
2663#ifdef FEATURE_WLAN_TDLS
2664 init_completion(&adapter->tdls_add_station_comp);
2665 init_completion(&adapter->tdls_del_station_comp);
2666 init_completion(&adapter->tdls_mgmt_comp);
2667 init_completion(&adapter->tdls_link_establish_req_comp);
2668#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002669 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002670 init_completion(&adapter->change_country_code);
2671
2672
2673 init_completion(&adapter->scan_info.abortscan_event_var);
2674
2675 adapter->offloads_configured = false;
2676 adapter->isLinkUpSvcNeeded = false;
2677 adapter->higherDtimTransition = true;
2678 /* Init the net_device structure */
2679 strlcpy(pWlanDev->name, name, IFNAMSIZ);
2680
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302681 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002682 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302683 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002684 sizeof(tSirMacAddr));
2685 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686
2687 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
2688 pWlanDev->features |=
2689 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2690 pWlanDev->features |= NETIF_F_RXCSUM;
2691
Dhanashri Atre83d373d2015-07-28 16:45:59 -07002692 hdd_set_tso_flags(hdd_ctx, pWlanDev);
2693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002694 hdd_set_station_ops(adapter->dev);
2695
2696 pWlanDev->destructor = free_netdev;
2697 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08002698 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002699 adapter->wdev.wiphy = hdd_ctx->wiphy;
2700 adapter->wdev.netdev = pWlanDev;
2701 /* set pWlanDev's parent to underlying device */
2702 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
2703 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05302704 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05302706 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707 }
2708
2709 return adapter;
2710}
2711
Jeff Johnson590e2012016-10-05 16:16:24 -07002712static QDF_STATUS hdd_register_interface(hdd_adapter_t *adapter,
2713 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002714{
2715 struct net_device *pWlanDev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002716
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08002717 if (rtnl_held) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002718 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
2719 if (dev_alloc_name(pWlanDev, pWlanDev->name) < 0) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002720 hdd_err("Failed:dev_alloc_name");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302721 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722 }
2723 }
2724 if (register_netdevice(pWlanDev)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002725 hdd_err("Failed:register_netdev");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302726 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002727 }
2728 } else {
2729 if (register_netdev(pWlanDev)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002730 hdd_err("Failed:register_netdev");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302731 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002732 }
2733 }
2734 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
2735
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302736 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002737}
2738
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002739QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740{
2741 hdd_adapter_t *adapter = pContext;
2742
2743 if (NULL == adapter) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002744 hdd_alert("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302745 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746 }
2747
2748 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002749 hdd_alert("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302750 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751 }
2752
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07002753 /*
2754 * For NAN Data interface, the close session results in the final
2755 * indication to the userspace
2756 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07002757 if (adapter->device_mode == QDF_NDI_MODE)
2758 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07002759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002760 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
2761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002762 /*
2763 * We can be blocked while waiting for scheduled work to be
2764 * flushed, and the adapter structure can potentially be freed, in
2765 * which case the magic will have been reset. So make sure the
2766 * magic is still good, and hence the adapter structure is still
2767 * valid, before signaling completion
2768 */
2769 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
2770 complete(&adapter->session_close_comp_var);
2771
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302772 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002773}
2774
Krunal Soni8c37e322016-02-03 16:08:37 -08002775/**
2776 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
2777 * @adapter: pointer to device adapter
2778 * @type: type of interface
2779 *
2780 * This routine will check the mode of adapter and if it is required then it
2781 * will initialize the TDLS operations
2782 *
2783 * Return: QDF_STATUS
2784 */
2785#ifdef FEATURE_WLAN_TDLS
2786static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter, uint32_t type)
2787{
2788 if (QDF_IBSS_MODE != type) {
2789 if (0 != wlan_hdd_tdls_init(adapter)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002790 hdd_err("wlan_hdd_tdls_init failed");
Krunal Soni8c37e322016-02-03 16:08:37 -08002791 return QDF_STATUS_E_FAILURE;
2792 }
2793 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
2794 }
2795 return QDF_STATUS_SUCCESS;
2796}
2797#else
2798static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter, uint32_t type)
2799{
2800 return QDF_STATUS_SUCCESS;
2801}
2802#endif
2803
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302804QDF_STATUS hdd_init_station_mode(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002805{
2806 struct net_device *pWlanDev = adapter->dev;
2807 hdd_station_ctx_t *pHddStaCtx = &adapter->sessionCtx.station;
2808 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302809 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302810 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811 uint32_t type, subType;
2812 unsigned long rc;
2813 int ret_val;
2814
2815 INIT_COMPLETION(adapter->session_open_comp_var);
2816 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07002817 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002818 status = cds_get_vdev_types(adapter->device_mode, &type, &subType);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302819 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002820 hdd_err("failed to get vdev type");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002821 goto error_sme_open;
2822 }
2823 /* Open a SME session for future operation */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302824 qdf_ret_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002825 sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
2826 (uint8_t *) &adapter->macAddressCurrent,
2827 &adapter->sessionId, type, subType);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302828 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002829 hdd_alert("sme_open_session() failed, status code %08d [x%08x]",
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302830 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302831 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 goto error_sme_open;
2833 }
2834 /* Block on a completion variable. Can't wait forever though. */
2835 rc = wait_for_completion_timeout(
2836 &adapter->session_open_comp_var,
2837 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
2838 if (!rc) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002839 hdd_alert("Session is not opened within timeout period code %ld",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002840 rc);
Sandeep Puligillae8065992016-11-14 00:23:43 -08002841 adapter->sessionId = HDD_SESSION_ID_INVALID;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302842 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843 }
2844
Rajeev Kumardeabf3e2017-01-13 15:55:05 -08002845 ret_val = hdd_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
2846 if (ret_val)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302847 goto error_vdev_create;
2848
Naveen Rawata410c5a2016-09-19 14:22:33 -07002849 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002850 /* Register wireless extensions */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302851 qdf_ret_status = hdd_register_wext(pWlanDev);
2852 if (QDF_STATUS_SUCCESS != qdf_ret_status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002853 hdd_alert("hdd_register_wext() failed, status code %08d [x%08x]",
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302854 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302855 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002856 goto error_register_wext;
2857 }
2858 /* Set the Connection State to Not Connected */
Jeff Johnson1346fab2016-08-15 13:09:42 -07002859 hdd_notice("Set HDD connState to eConnectionState_NotConnected");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
2861
Deepak Dhamdherea2785822016-11-17 01:17:45 -08002862 /* set fast roaming capability in sme session */
2863 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
2864 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002865 /* Set the default operation channel */
2866 pHddStaCtx->conn_info.operationChannel =
2867 hdd_ctx->config->OperatingChannel;
2868
2869 /* Make the default Auth Type as OPEN */
2870 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2871
2872 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302873 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002874 hdd_alert("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002875 status, status);
2876 goto error_init_txrx;
2877 }
2878
2879 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2880
2881 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302882 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002883 hdd_alert("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002884 status, status);
2885 goto error_wmm_init;
2886 }
2887
2888 set_bit(WMM_INIT_DONE, &adapter->event_flags);
2889
2890 ret_val = wma_cli_set_command(adapter->sessionId,
2891 WMI_PDEV_PARAM_BURST_ENABLE,
2892 hdd_ctx->config->enableSifsBurst,
2893 PDEV_CMD);
2894
2895 if (0 != ret_val) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002896 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002897 ret_val);
2898 }
Krunal Soni8c37e322016-02-03 16:08:37 -08002899 status = hdd_check_and_init_tdls(adapter, type);
2900 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002901 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05302903 status = hdd_lro_enable(hdd_ctx, adapter);
2904 if (status != QDF_STATUS_SUCCESS)
2905 goto error_lro_enable;
2906
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302907 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05302909error_lro_enable:
2910 wlan_hdd_tdls_exit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911error_tdls_init:
2912 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
2913 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002914error_wmm_init:
2915 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2916 hdd_deinit_tx_rx(adapter);
2917error_init_txrx:
2918 hdd_unregister_wext(pWlanDev);
2919error_register_wext:
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08002920 ret_val = hdd_release_and_destroy_vdev(adapter);
2921 if (ret_val)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302922 hdd_err("vdev delete failed");
2923error_vdev_create:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002924 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2925 INIT_COMPLETION(adapter->session_close_comp_var);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302926 if (QDF_STATUS_SUCCESS == sme_close_session(hdd_ctx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927 adapter->sessionId,
2928 hdd_sme_close_session_callback,
2929 adapter)) {
2930 unsigned long rc;
2931
2932 /*
2933 * Block on a completion variable.
2934 * Can't wait forever though.
2935 */
2936 rc = wait_for_completion_timeout(
2937 &adapter->session_close_comp_var,
2938 msecs_to_jiffies
2939 (WLAN_WAIT_TIME_SESSIONOPENCLOSE));
2940 if (rc <= 0)
Jeff Johnson1346fab2016-08-15 13:09:42 -07002941 hdd_err("Session is not opened within timeout period code %ld",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942 rc);
2943 }
2944 }
2945error_sme_open:
2946 return status;
2947}
2948
2949void hdd_cleanup_actionframe(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
2950{
2951 hdd_cfg80211_state_t *cfgState;
2952
2953 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
2954
2955 if (NULL != cfgState->buf) {
2956 unsigned long rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002957 rc = wait_for_completion_timeout(
2958 &adapter->tx_action_cnf_event,
2959 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
2960 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07002961 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05302962 /*
2963 * Inform tx status as FAILURE to upper layer and free
2964 * cfgState->buf
2965 */
2966 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967 }
2968 }
2969 return;
2970}
2971
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302972/**
2973 * hdd_station_adapter_deinit() - De-initialize the station adapter
2974 * @hdd_ctx: global hdd context
2975 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07002976 * @rtnl_held: Used to indicate whether or not the caller is holding
2977 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302978 *
2979 * This function De-initializes the STA/P2P/OCB adapter.
2980 *
2981 * Return: None.
2982 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002983static void hdd_station_adapter_deinit(hdd_context_t *hdd_ctx,
2984 hdd_adapter_t *adapter,
2985 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302986{
2987 ENTER_DEV(adapter->dev);
2988
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05302989 if (adapter->dev) {
2990 if (rtnl_held)
2991 adapter->dev->wireless_handlers = NULL;
2992 else {
2993 rtnl_lock();
2994 adapter->dev->wireless_handlers = NULL;
2995 rtnl_unlock();
2996 }
2997 }
2998
Arun Khandavalli7e857c32016-06-26 12:07:16 +05302999 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3000 hdd_deinit_tx_rx(adapter);
3001 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3002 }
3003
3004 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3005 hdd_wmm_adapter_close(adapter);
3006 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3007 }
3008
3009 hdd_cleanup_actionframe(hdd_ctx, adapter);
3010 wlan_hdd_tdls_exit(adapter);
3011
3012 EXIT();
3013}
3014
3015/**
3016 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3017 * @hdd_ctx: global hdd context
3018 * @adapter: HDD adapter
3019 * @rtnl_held: the rtnl lock hold flag
3020 * This function De-initializes the AP/P2PGo adapter.
3021 *
3022 * Return: None.
3023 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003024static void hdd_ap_adapter_deinit(hdd_context_t *hdd_ctx,
3025 hdd_adapter_t *adapter,
3026 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303027{
3028 ENTER_DEV(adapter->dev);
3029
3030 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3031 hdd_wmm_adapter_close(adapter);
3032 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3033 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003034 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303035
3036 hdd_cleanup_actionframe(hdd_ctx, adapter);
3037
3038 hdd_unregister_hostapd(adapter, rtnl_held);
3039
3040 EXIT();
3041}
3042
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003043void hdd_deinit_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3044 bool rtnl_held)
3045{
3046 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303047
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003048 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003049 case QDF_STA_MODE:
3050 case QDF_P2P_CLIENT_MODE:
3051 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303053 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003054 break;
3055 }
3056
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003057 case QDF_SAP_MODE:
3058 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059 {
3060
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303061 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003062 break;
3063 }
3064
3065 default:
3066 break;
3067 }
3068
3069 EXIT();
3070}
3071
Jeff Johnson590e2012016-10-05 16:16:24 -07003072static void hdd_cleanup_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3073 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074{
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08003075 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076 struct net_device *pWlanDev = NULL;
3077
3078 if (adapter)
3079 pWlanDev = adapter->dev;
3080 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003081 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082 return;
3083 }
3084
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08003085 ret = hdd_release_and_destroy_vdev(adapter);
3086 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303087 hdd_err("vdev delete failed");
3088
Rajeev Kumardca5f812016-02-04 17:28:06 -08003089 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303090
3091 if (adapter->scan_info.default_scan_ies) {
3092 qdf_mem_free(adapter->scan_info.default_scan_ies);
3093 adapter->scan_info.default_scan_ies = NULL;
3094 }
3095
Komal Seelama89be8d2016-09-29 11:09:26 +05303096 hdd_adapter_runtime_suspend_denit(adapter);
3097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003098 /*
3099 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3100 * the driver is almost closed and cannot handle either control
3101 * messages or data. However, unregister_netdevice() call above will
3102 * eventually invoke hdd_stop (ndo_close) driver callback, which attempts
3103 * to close the active connections (basically excites control path) which
3104 * is not right. Setting this flag helps hdd_stop() to recognize that
3105 * the interface is closed and restricts any operations on that
3106 */
3107 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3108
3109 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
3110 if (rtnl_held) {
3111 unregister_netdevice(pWlanDev);
3112 } else {
3113 unregister_netdev(pWlanDev);
3114 }
3115 /*
3116 * Note that the adapter is no longer valid at this point
3117 * since the memory has been reclaimed
3118 */
3119 }
3120}
3121
Jeff Johnson590e2012016-10-05 16:16:24 -07003122static QDF_STATUS hdd_check_for_existing_macaddr(hdd_context_t *hdd_ctx,
3123 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124{
3125 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
3126 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303127 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303129 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003130 adapter = adapterNode->pAdapter;
3131 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303132 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303134 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003135 }
3136 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3137 adapterNode = pNext;
3138 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303139 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003141
Arun Khandavalli2358d522016-05-16 18:05:37 +05303142#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3143/**
3144 * hdd_set_fw_log_params() - Set log parameters to FW
3145 * @hdd_ctx: HDD Context
3146 * @adapter: HDD Adapter
3147 *
3148 * This function set the FW Debug log level based on the INI.
3149 *
3150 * Return: None
3151 */
3152static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3153 hdd_adapter_t *adapter)
3154{
3155 uint8_t count = 0, numentries = 0,
3156 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3157 uint32_t value = 0;
3158 int ret;
3159
Arun Khandavallifae92942016-08-01 13:31:08 +05303160 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3161 (!hdd_ctx->config->enable_fw_log)) {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303162 hdd_info("enable_fw_log not enabled in INI or in FTM mode return");
3163 return;
3164 }
3165
Arun Khandavallifae92942016-08-01 13:31:08 +05303166 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303167 hdd_ctx->fw_log_settings.dl_type =
3168 hdd_ctx->config->enableFwLogType;
3169 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303170 WMI_DBGLOG_TYPE,
3171 hdd_ctx->config->enableFwLogType,
3172 DBG_CMD);
3173 if (ret != 0)
3174 hdd_err("Failed to enable FW log type ret %d",
3175 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303176
3177 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303178 hdd_ctx->config->enableFwLogLevel;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303179 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303180 WMI_DBGLOG_LOG_LEVEL,
3181 hdd_ctx->config->enableFwLogLevel,
3182 DBG_CMD);
3183 if (ret != 0)
3184 hdd_err("Failed to enable FW log level ret %d",
3185 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303186
3187 hdd_string_to_u8_array(
3188 hdd_ctx->config->enableFwModuleLogLevel,
3189 moduleloglevel,
3190 &numentries,
3191 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3192
3193 while (count < numentries) {
3194 /*
3195 * FW module log level input string looks like
3196 * below:
3197 * gFwDebugModuleLoglevel=<FW Module ID>,
3198 * <Log Level>,...
3199 * For example:
3200 * gFwDebugModuleLoglevel=
3201 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3202 * Above input string means :
3203 * For FW module ID 1 enable log level 0
3204 * For FW module ID 2 enable log level 1
3205 * For FW module ID 3 enable log level 2
3206 * For FW module ID 4 enable log level 3
3207 * For FW module ID 5 enable log level 4
3208 * For FW module ID 6 enable log level 5
3209 * For FW module ID 7 enable log level 6
3210 */
3211
Nishank Aggarwale239d962017-03-03 12:26:02 +05303212 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3213 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3214 hdd_err("Module id %d and dbglog level %d input length is more than max",
3215 moduleloglevel[count],
3216 moduleloglevel[count + 1]);
3217 return;
3218 }
3219
3220 value = moduleloglevel[count] << 16;
3221 value |= moduleloglevel[count + 1];
Arun Khandavalli2358d522016-05-16 18:05:37 +05303222 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303223 WMI_DBGLOG_MOD_LOG_LEVEL,
3224 value, DBG_CMD);
3225 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303226 hdd_err("Failed to enable FW module log level %d ret %d",
3227 value, ret);
3228
3229 count += 2;
3230 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303231
Arun Khandavalli2358d522016-05-16 18:05:37 +05303232}
3233#else
3234static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3235 hdd_adapter_t *adapter)
3236{
3237}
3238
3239#endif
3240
3241/**
3242 * hdd_set_fw_params() - Set parameters to firmware
3243 * @adapter: HDD adapter
3244 *
3245 * This function Sets various parameters to fw once the
3246 * adapter is started.
3247 *
3248 * Return: 0 on success or errno on failure
3249 */
3250int hdd_set_fw_params(hdd_adapter_t *adapter)
3251{
3252 int ret;
3253 hdd_context_t *hdd_ctx;
3254
3255 ENTER_DEV(adapter->dev);
3256
3257 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3258 if (!hdd_ctx)
3259 return -EINVAL;
3260
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003261 if ((cds_get_conparam() != QDF_GLOBAL_FTM_MODE) &&
Arun Khandavallifae92942016-08-01 13:31:08 +05303262 (!hdd_ctx->config->enable2x2)) {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303263#define HDD_DTIM_1CHAIN_RX_ID 0x5
3264#define HDD_SMPS_PARAM_VALUE_S 29
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003265 /*
3266 * Disable DTIM 1 chain Rx when in 1x1,
3267 * we are passing two value
3268 * as param_id << 29 | param_value.
3269 * Below param_value = 0(disable)
3270 */
3271 ret = wma_cli_set_command(adapter->sessionId,
3272 WMI_STA_SMPS_PARAM_CMDID,
3273 HDD_DTIM_1CHAIN_RX_ID <<
3274 HDD_SMPS_PARAM_VALUE_S,
3275 VDEV_CMD);
3276 if (ret) {
3277 hdd_err("DTIM 1 chain set failed %d", ret);
3278 goto error;
3279 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303280
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003281 ret = wma_cli_set_command(adapter->sessionId,
3282 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3283 hdd_ctx->config->txchainmask1x1,
3284 PDEV_CMD);
3285 if (ret) {
3286 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3287 ret);
3288 goto error;
3289 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303290
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003291 ret = wma_cli_set_command(adapter->sessionId,
3292 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3293 hdd_ctx->config->rxchainmask1x1,
3294 PDEV_CMD);
3295 if (ret) {
3296 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3297 ret);
3298 goto error;
3299 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303300#undef HDD_DTIM_1CHAIN_RX_ID
3301#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003302 } else {
3303 hdd_info("FTM Mode or 2x2 mode - Do not set 1x1 params");
3304 }
3305
Arun Khandavallifae92942016-08-01 13:31:08 +05303306 if (QDF_GLOBAL_FTM_MODE != cds_get_conparam()) {
3307 ret = wma_cli_set_command(adapter->sessionId,
3308 WMI_PDEV_PARAM_HYST_EN,
3309 hdd_ctx->config->enableMemDeepSleep,
3310 PDEV_CMD);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303311
Arun Khandavallifae92942016-08-01 13:31:08 +05303312 if (ret) {
3313 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d",
3314 ret);
3315 goto error;
3316 }
Rajeev Kumar Sirasanagandla2dab3ec2016-10-18 16:10:15 +05303317
3318 ret = wma_cli_set_command(adapter->sessionId,
3319 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3320 hdd_ctx->config->rts_profile,
3321 VDEV_CMD);
3322 if (ret) {
3323 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3324 goto error;
3325 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303326 }
3327
3328 hdd_set_fw_log_params(hdd_ctx, adapter);
3329
3330 EXIT();
3331 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303332
Arun Khandavalli2358d522016-05-16 18:05:37 +05303333error:
3334 return -EINVAL;
3335}
3336
Ryan Hsu07495ea2016-01-21 15:25:39 -08003337/**
3338 * hdd_open_adapter() - open and setup the hdd adatper
3339 * @hdd_ctx: global hdd context
3340 * @session_type: type of the interface to be created
3341 * @iface_name: User-visible name of the interface
3342 * @macAddr: MAC address to assign to the interface
3343 * @name_assign_type: the name of assign type of the netdev
3344 * @rtnl_held: the rtnl lock hold flag
3345 *
3346 * This function open and setup the hdd adpater according to the device
3347 * type request, assign the name, the mac address assigned, and then prepared
3348 * the hdd related parameters, queue, lock and ready to start.
3349 *
3350 * Return: the pointer of hdd adapter, otherwise NULL.
3351 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352hdd_adapter_t *hdd_open_adapter(hdd_context_t *hdd_ctx, uint8_t session_type,
3353 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003354 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003355 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356{
3357 hdd_adapter_t *adapter = NULL;
3358 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303359 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361
Arun Khandavallifae92942016-08-01 13:31:08 +05303362 hdd_info("iface(%s) type(%d)", iface_name, session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363
3364 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3365 /*
3366 * Max limit reached on the number of vdevs configured by the
3367 * host. Return error
3368 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303369 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3370 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371 return NULL;
3372 }
3373
3374 if (macAddr == NULL) {
3375 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303376 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377 return NULL;
3378 }
3379 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303380 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303381 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3382 " already exists",
3383 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384 return NULL;
3385 }
3386
3387 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003388 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389 /* Reset locally administered bit if the device mode is STA */
3390 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3391 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003392 case QDF_P2P_CLIENT_MODE:
3393 case QDF_P2P_DEVICE_MODE:
3394 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003395 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303396 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003397 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3398 name_assign_type,
3399 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400
3401 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303402 hdd_err("failed to allocate adapter for session %d",
3403 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 return NULL;
3405 }
3406
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003407 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003409 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303411 else if (QDF_MONITOR_MODE == session_type)
3412 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413 else
3414 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3415
3416 adapter->device_mode = session_type;
3417
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303418 if (QDF_NDI_MODE == session_type) {
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003419 status = hdd_init_nan_data_mode(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303420 if (QDF_STATUS_SUCCESS != status)
3421 goto err_free_netdev;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303422 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003424 /*
3425 * Workqueue which gets scheduled in IPv4 notification
3426 * callback
3427 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003428 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3429 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430
3431#ifdef WLAN_NS_OFFLOAD
3432 /*
3433 * Workqueue which gets scheduled in IPv6
3434 * notification callback.
3435 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3437 hdd_ipv6_notifier_work_queue);
3438#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303440 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303442 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443 }
3444
3445 /* Stop the Interface TX queue. */
Arun Khandavallifae92942016-08-01 13:31:08 +05303446 hdd_info("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303448 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3449 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 break;
Arun Khandavallifae92942016-08-01 13:31:08 +05303451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003453 case QDF_P2P_GO_MODE:
3454 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003455 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3456 name_assign_type,
3457 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303459 hdd_alert("failed to allocate adapter for session %d",
3460 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461 return NULL;
3462 }
3463
3464 adapter->wdev.iftype =
3465 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003466 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467 NL80211_IFTYPE_P2P_GO;
3468 adapter->device_mode = session_type;
3469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003470 status = hdd_register_hostapd(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303471 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3473 goto err_free_netdev;
3474 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303475 hdd_info("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303477 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3478 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303480 case QDF_FTM_MODE:
3481 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3482 name_assign_type,
3483 "wlan0");
3484 if (NULL == adapter) {
3485 hdd_err("Failed to allocate adapter for FTM mode");
3486 return NULL;
3487 }
3488 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3489 adapter->device_mode = session_type;
3490 status = hdd_register_interface(adapter, rtnl_held);
3491 if (QDF_STATUS_SUCCESS != status) {
3492 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3493 goto err_free_netdev;
3494 }
3495 /* Stop the Interface TX queue. */
3496 hdd_info("Disabling queues");
3497 wlan_hdd_netif_queue_control(adapter,
3498 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3499 WLAN_CONTROL_PATH);
3500 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501 default:
Arun Khandavallifae92942016-08-01 13:31:08 +05303502 hdd_alert("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303503 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504 return NULL;
3505 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506
3507 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3508 mutex_init(&cfgState->remain_on_chan_ctx_lock);
3509
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303510 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511 /* Add it to the hdd's session list. */
3512 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303513 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003514 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303515 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516 } else {
3517 pHddAdapterNode->pAdapter = adapter;
3518 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
3519 }
3520 }
3521
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303522 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003523 if (NULL != adapter) {
3524 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
3525 adapter = NULL;
3526 }
3527 if (NULL != pHddAdapterNode) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303528 qdf_mem_free(pHddAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003529 }
3530 return NULL;
3531 }
3532
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303533 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003534 cds_set_concurrency_mode(session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535
3536 /* Initialize the WoWL service */
3537 if (!hdd_init_wowl(adapter)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003538 hdd_alert("hdd_init_wowl failed");
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303539 goto err_close_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540 }
3541
3542 /* Adapter successfully added. Increment the vdev count */
3543 hdd_ctx->current_intf_count++;
3544
Jeff Johnson5880d792016-08-15 13:32:30 -07003545 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546 hdd_ctx->current_intf_count);
3547
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003548 cds_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003549 }
3550
Rajeev Kumardca5f812016-02-04 17:28:06 -08003551 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
3552 hdd_err("Interface %s wow debug_fs init failed", iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553
3554 return adapter;
3555
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303556err_close_adapter:
3557 hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003558err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303560 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561
3562 return NULL;
3563}
3564
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303565QDF_STATUS hdd_close_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003566 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003567{
3568 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303569 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570
3571 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303572 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003573 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 status);
3575 return status;
3576 }
3577
3578 while (pCurrent->pAdapter != adapter) {
3579 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303580 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581 break;
3582
3583 pCurrent = pNext;
3584 }
3585 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303586 if (QDF_STATUS_SUCCESS == status) {
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05303587 hdd_info("wait for bus bw work to flush");
3588 cancel_work_sync(&hdd_ctx->bus_bw_work);
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003589 cds_clear_concurrency_mode(adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
3591
3592 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303593 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 adapterNode = NULL;
3595
3596 /* Adapter removed. Decrement vdev count */
3597 if (hdd_ctx->current_intf_count != 0)
3598 hdd_ctx->current_intf_count--;
3599
3600 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303601 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303603
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303604 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605}
3606
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003607/**
3608 * hdd_close_all_adapters - Close all open adapters
3609 * @hdd_ctx: Hdd context
3610 * rtnl_held: True if RTNL lock held
3611 *
3612 * Close all open adapters.
3613 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303614 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003615 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303616QDF_STATUS hdd_close_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003617{
3618 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303619 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620
3621 ENTER();
3622
3623 do {
3624 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303625 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303626 wlan_hdd_release_intf_addr(hdd_ctx,
3627 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003629 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303630 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303631 /* Adapter removed. Decrement vdev count */
3632 if (hdd_ctx->current_intf_count != 0)
3633 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303635 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636
3637 EXIT();
3638
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303639 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003640}
3641
3642void wlan_hdd_reset_prob_rspies(hdd_adapter_t *pHostapdAdapter)
3643{
Anurag Chouhan6d760662016-02-20 16:05:43 +05303644 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 tSirUpdateIE updateIE;
3646 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003647 case QDF_STA_MODE:
3648 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 {
3650 hdd_station_ctx_t *pHddStaCtx =
3651 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003652 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 break;
3654 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003655 case QDF_SAP_MODE:
3656 case QDF_P2P_GO_MODE:
3657 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003658 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003659 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 break;
3661 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003662 case QDF_FTM_MODE:
3663 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664 default:
3665 /*
3666 * wlan_hdd_reset_prob_rspies should not have been called
3667 * for these kind of devices
3668 */
Jeff Johnson5880d792016-08-15 13:32:30 -07003669 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 pHostapdAdapter->device_mode);
3671 return;
3672 }
3673
Anurag Chouhanc5548422016-02-24 18:33:27 +05303674 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003675 updateIE.smeSessionId = pHostapdAdapter->sessionId;
3676 updateIE.ieBufferlength = 0;
3677 updateIE.pAdditionIEBuffer = NULL;
3678 updateIE.append = true;
3679 updateIE.notify = false;
3680 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
3681 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303682 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003683 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 }
3685}
3686
Peng Xu66162de2016-02-11 17:01:20 -08003687/**
3688 * hdd_wait_for_sme_close_sesion() - Close and wait for SME session close
3689 * @hdd_ctx: HDD context which is already NULL validated
3690 * @adapter: HDD adapter which is already NULL validated
3691 *
3692 * Close the SME session and wait for its completion, if needed.
3693 *
3694 * Return: None
3695 */
3696static void hdd_wait_for_sme_close_sesion(hdd_context_t *hdd_ctx,
3697 hdd_adapter_t *adapter)
3698{
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08003699 int ret;
Peng Xu66162de2016-02-11 17:01:20 -08003700 unsigned long rc;
3701
3702 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3703 hdd_err("session is not opened:%d", adapter->sessionId);
3704 return;
3705 }
3706
3707 INIT_COMPLETION(adapter->session_close_comp_var);
3708 if (QDF_STATUS_SUCCESS ==
3709 sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3710 hdd_sme_close_session_callback,
3711 adapter)) {
3712 /*
3713 * Block on a completion variable. Can't wait
3714 * forever though.
3715 */
3716 rc = wait_for_completion_timeout(
3717 &adapter->session_close_comp_var,
3718 msecs_to_jiffies
3719 (WLAN_WAIT_TIME_SESSIONOPENCLOSE));
Sandeep Puligillaada72922016-09-29 19:31:21 -07003720 if (!rc) {
Peng Xu66162de2016-02-11 17:01:20 -08003721 hdd_err("failure waiting for session_close_comp_var");
Sandeep Puligillaada72922016-09-29 19:31:21 -07003722 if (adapter->device_mode == QDF_NDI_MODE)
3723 hdd_ndp_session_end_handler(adapter);
3724 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Hanumanth Reddy Pothula33702122016-10-07 17:27:04 +05303725 return;
Sandeep Puligillaada72922016-09-29 19:31:21 -07003726 }
Rajeev Kumar9591d2b2017-01-13 16:05:06 -08003727 ret = hdd_release_and_destroy_vdev(adapter);
3728 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303729 hdd_err("vdev delete failed");
3730
Hanumanth Reddy Pothula33702122016-10-07 17:27:04 +05303731 adapter->sessionId = HDD_SESSION_ID_INVALID;
Peng Xu66162de2016-02-11 17:01:20 -08003732 }
3733}
3734
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303735QDF_STATUS hdd_stop_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003736 const bool bCloseSession)
3737{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303738 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003739 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
3740 union iwreq_data wrqu;
3741 tSirUpdateIE updateIE;
3742 unsigned long rc;
Sachin Ahuja988fd102016-09-15 17:16:25 +05303743 hdd_scaninfo_t *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003744
3745 ENTER();
3746
Sachin Ahuja988fd102016-09-15 17:16:25 +05303747 scan_info = &adapter->scan_info;
Jeff Johnson5880d792016-08-15 13:32:30 -07003748 hdd_notice("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003749 wlan_hdd_netif_queue_control(adapter, WLAN_NETIF_TX_DISABLE_N_CARRIER,
3750 WLAN_CONTROL_PATH);
3751 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003752 case QDF_STA_MODE:
3753 case QDF_P2P_CLIENT_MODE:
3754 case QDF_IBSS_MODE:
3755 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003756 case QDF_NDI_MODE:
3757 if ((QDF_NDI_MODE == adapter->device_mode) ||
3758 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
3760 hdd_is_connecting(
3761 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003762 INIT_COMPLETION(adapter->disconnect_comp_var);
3763 /*
3764 * For NDI do not use pWextState from sta_ctx, if needed
3765 * extract from ndi_ctx.
3766 */
3767 if (QDF_NDI_MODE == adapter->device_mode)
3768 qdf_ret_status = sme_roam_disconnect(
3769 hdd_ctx->hHal,
3770 adapter->sessionId,
3771 eCSR_DISCONNECT_REASON_NDI_DELETE);
3772 else if (pWextState->roamProfile.BSSType ==
3773 eCSR_BSS_TYPE_START_IBSS)
3774 qdf_ret_status = sme_roam_disconnect(
3775 hdd_ctx->hHal,
3776 adapter->sessionId,
3777 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003779 qdf_ret_status = sme_roam_disconnect(
3780 hdd_ctx->hHal,
3781 adapter->sessionId,
3782 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783 /* success implies disconnect command got queued up successfully */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303784 if (qdf_ret_status == QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 rc = wait_for_completion_timeout(
3786 &adapter->disconnect_comp_var,
3787 msecs_to_jiffies
3788 (WLAN_WAIT_TIME_DISCONNECT));
3789 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003790 hdd_err("wait on disconnect_comp_var failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003791 }
3792 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003793 hdd_err("failed to post disconnect event to SME");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003794 }
3795 memset(&wrqu, '\0', sizeof(wrqu));
3796 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3797 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3798 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
3799 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05303800 }
3801 if (scan_info != NULL && scan_info->mScanPending) {
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05303802 wlan_hdd_scan_abort(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803 }
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05303804 hdd_lro_disable(hdd_ctx, adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05303805 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806
3807#ifdef WLAN_OPEN_SOURCE
3808 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
3809#endif
3810
3811 hdd_deregister_tx_flow_control(adapter);
3812
3813#ifdef WLAN_NS_OFFLOAD
3814#ifdef WLAN_OPEN_SOURCE
3815 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
3816#endif
3817#endif
3818
3819 /*
3820 * It is possible that the caller of this function does not
3821 * wish to close the session
3822 */
Krunal Soni985b8132017-02-10 18:49:08 -08003823 if (true == bCloseSession) {
3824 if (0 != wlan_hdd_try_disconnect(adapter)) {
3825 hdd_err("Error: Can't disconnect adapter");
3826 return QDF_STATUS_E_FAILURE;
3827 }
Peng Xu66162de2016-02-11 17:01:20 -08003828 hdd_wait_for_sme_close_sesion(hdd_ctx, adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08003829 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 break;
3831
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003832 case QDF_SAP_MODE:
3833 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003834 if (hdd_ctx->config->conc_custom_rule1 &&
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003835 (QDF_SAP_MODE == adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003836 /*
3837 * Before stopping the sap adapter, lets make sure there
3838 * is no sap restart work pending.
3839 */
3840 cds_flush_work(&hdd_ctx->sap_start_work);
Jeff Johnson5880d792016-08-15 13:32:30 -07003841 hdd_info("Canceled the pending SAP restart work");
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003842 cds_change_sap_restart_required_status(false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003843 }
3844 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003845 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
3847
3848 hdd_deregister_tx_flow_control(adapter);
3849
3850 mutex_lock(&hdd_ctx->sap_lock);
3851 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303852 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05303853 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854
3855 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003856 status = wlansap_stop_bss(
3857 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303859 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860 hdd_hostapd_state_t *hostapd_state =
3861 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05303862 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303863 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05303864 qdf_status =
3865 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08003866 qdf_stop_bss_event,
3867 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003868
Anurag Chouhance0dc992016-02-16 18:18:03 +05303869 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003870 hdd_err("failure waiting for wlansap_stop_bss %d",
3871 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 }
3873 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003874 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003875 }
3876 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyaca50b322015-12-28 17:14:36 -08003877 cds_decr_session_set_pcl(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878 adapter->device_mode,
3879 adapter->sessionId);
3880
Anurag Chouhanc5548422016-02-24 18:33:27 +05303881 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003882 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883 updateIE.smeSessionId = adapter->sessionId;
3884 updateIE.ieBufferlength = 0;
3885 updateIE.pAdditionIEBuffer = NULL;
3886 updateIE.append = false;
3887 updateIE.notify = false;
3888 /* Probe bcn reset */
3889 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
3890 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303891 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003892 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003893 }
3894 /* Assoc resp reset */
3895 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
3896 &updateIE,
3897 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303898 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003899 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 }
3901 /* Reset WNI_CFG_PROBE_RSP Flags */
3902 wlan_hdd_reset_prob_rspies(adapter);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303903 qdf_mem_free(adapter->sessionCtx.ap.beacon);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904 adapter->sessionCtx.ap.beacon = NULL;
3905 }
3906 mutex_unlock(&hdd_ctx->sap_lock);
Peng Xu66162de2016-02-11 17:01:20 -08003907 if (true == bCloseSession)
3908 hdd_wait_for_sme_close_sesion(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003910 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08003911 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003912 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07003913 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 break;
3915 default:
3916 break;
3917 }
3918
3919 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303920 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921}
3922
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05303923/**
3924 * hdd_deinit_all_adapters - deinit all adapters
3925 * @hdd_ctx: HDD context
3926 * @rtnl_held: True if RTNL lock held
3927 *
3928 */
3929void hdd_deinit_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
3930{
3931 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3932 QDF_STATUS status;
3933 hdd_adapter_t *adapter;
3934
3935 ENTER();
3936
3937 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3938
3939 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3940 adapter = adapter_node->pAdapter;
3941 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3942 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
3943 adapter_node = next;
3944 }
3945
3946 EXIT();
3947}
3948
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303949QDF_STATUS hdd_stop_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950{
3951 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303952 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 hdd_adapter_t *adapter;
3954
3955 ENTER();
3956
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303957 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
3958
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003959 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
3960
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303961 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 adapter = adapterNode->pAdapter;
3963 hdd_stop_adapter(hdd_ctx, adapter, true);
3964 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3965 adapterNode = pNext;
3966 }
3967
3968 EXIT();
3969
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303970 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971}
3972
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303973QDF_STATUS hdd_reset_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974{
3975 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303976 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003977 hdd_adapter_t *adapter;
3978
3979 ENTER();
3980
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05303981 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
3982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
3984
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303985 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 adapter = adapterNode->pAdapter;
Jeff Johnson5880d792016-08-15 13:32:30 -07003987 hdd_notice("Disabling queues");
Arun Khandavallicc544b32017-01-30 19:52:16 +05303988 if (hdd_ctx->config->sap_internal_restart &&
3989 adapter->device_mode == QDF_SAP_MODE) {
3990 wlan_hdd_netif_queue_control(adapter,
3991 WLAN_NETIF_TX_DISABLE,
3992 WLAN_CONTROL_PATH);
3993 hdd_sap_indicate_disconnect_for_sta(adapter);
3994 hdd_cleanup_actionframe(hdd_ctx, adapter);
3995 hdd_sap_destroy_events(adapter);
3996 } else
3997 wlan_hdd_netif_queue_control(adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 WLAN_NETIF_TX_DISABLE_N_CARRIER,
3999 WLAN_CONTROL_PATH);
4000
4001 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4002
4003 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyya4adb3682016-01-07 15:07:12 -08004004 cds_decr_session_set_pcl(adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005 adapter->sessionId);
4006 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4007 hdd_wmm_adapter_close(adapter);
4008 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4009 }
4010
Wu Gao36717432016-11-21 15:09:48 +08004011 /*
4012 * If adapter is SAP, set session ID to invalid since SAP
4013 * session will be cleanup during SSR.
4014 */
4015 if (adapter->device_mode == QDF_SAP_MODE)
4016 wlansap_set_invalid_session(
4017 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4018
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4020 adapterNode = pNext;
4021 }
4022
4023 EXIT();
4024
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304025 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026}
4027
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304028bool hdd_check_for_opened_interfaces(hdd_context_t *hdd_ctx)
4029{
4030 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4031 QDF_STATUS status;
4032 bool close_modules = true;
4033
4034 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4035 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4036 if (test_bit(DEVICE_IFACE_OPENED,
4037 &adapter_node->pAdapter->event_flags)) {
4038 hdd_info("Still other ifaces are up cannot close modules");
4039 close_modules = false;
4040 break;
4041 }
4042 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4043 adapter_node = next;
4044 }
4045
4046 return close_modules;
4047}
4048
Arun Khandavallifae92942016-08-01 13:31:08 +05304049/**
4050 * hdd_is_interface_up()- Checkfor interface up before ssr
4051 * @hdd_ctx: HDD context
4052 *
4053 * check if there are any wlan interfaces before SSR accordingly start
4054 * the interface.
4055 *
4056 * Return: 0 if interface was opened else false
4057 */
4058static bool hdd_is_interface_up(hdd_adapter_t *adapter)
4059{
4060 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4061 return true;
4062 else
4063 return false;
4064}
4065
Anurag Chouhanc4092922016-09-08 15:56:11 +05304066#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
Abhishek Singhb5e38ef2017-01-02 12:09:34 +05304067 && !defined(WITH_BACKPORTS)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304068struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4069 struct ieee80211_channel *channel,
4070 const u8 *bssid, const u8 *ssid,
4071 size_t ssid_len)
4072{
4073 return cfg80211_get_bss(wiphy, channel, bssid,
4074 ssid, ssid_len,
4075 WLAN_CAPABILITY_ESS,
4076 WLAN_CAPABILITY_ESS);
4077}
4078#else
4079struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4080 struct ieee80211_channel *channel,
4081 const u8 *bssid, const u8 *ssid,
4082 size_t ssid_len)
4083{
4084 return cfg80211_get_bss(wiphy, channel, bssid,
4085 ssid, ssid_len,
4086 IEEE80211_BSS_TYPE_ESS,
4087 IEEE80211_PRIVACY_ANY);
4088}
4089#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304090
Abhishek Singha84d3952016-09-13 13:45:05 +05304091#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304092#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4093 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4094/**
4095 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4096 * @timeout_reason: reason for connect timeout
4097 *
4098 * This function is used to convert host timeout
4099 * reason enum to kernel specific enum.
4100 *
4101 * Return: nl timeout enum
4102 */
4103static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4104 tSirResultCodes timeout_reason)
4105{
4106 switch (timeout_reason) {
4107 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4108 return NL80211_TIMEOUT_SCAN;
4109 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4110 return NL80211_TIMEOUT_AUTH;
4111 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4112 return NL80211_TIMEOUT_ASSOC;
4113 default:
4114 return NL80211_TIMEOUT_UNSPECIFIED;
4115 }
4116}
4117
4118/**
4119 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4120 * @dev: network device
4121 * @bssid: bssid to which we want to associate
4122 * @timeout_reason: reason for connect timeout
4123 *
4124 * This API is used to send connection timeout reason to supplicant
4125 *
4126 * Return: void
4127 */
4128static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4129 const u8 *bssid,
4130 tSirResultCodes timeout_reason)
4131{
4132 enum nl80211_timeout_reason nl_timeout_reason;
4133 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4134
4135 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4136 nl_timeout_reason);
4137}
4138
4139/**
4140 * __hdd_connect_bss() - API to send connection status to supplicant
4141 * @dev: network device
4142 * @bssid: bssid to which we want to associate
4143 * @req_ie: Request Information Element
4144 * @req_ie_len: len of the req IE
4145 * @resp_ie: Response IE
4146 * @resp_ie_len: len of ht response IE
4147 * @status: status
4148 * @gfp: Kernel Flag
4149 * @timeout_reason: reason for connect timeout
4150 *
4151 * Return: void
4152 */
4153static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4154 struct cfg80211_bss *bss, const u8 *req_ie,
4155 size_t req_ie_len, const u8 *resp_ie,
4156 size_t resp_ie_len, int status, gfp_t gfp,
4157 tSirResultCodes timeout_reason)
4158{
4159 enum nl80211_timeout_reason nl_timeout_reason;
4160 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4161
4162 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4163 resp_ie, resp_ie_len, status, gfp,
4164 nl_timeout_reason);
4165}
4166#else
4167#if defined CFG80211_CONNECT_TIMEOUT
4168static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4169 const u8 *bssid,
4170 tSirResultCodes timeout_reason)
4171{
4172 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4173}
4174#endif
4175
4176static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4177 struct cfg80211_bss *bss, const u8 *req_ie,
4178 size_t req_ie_len, const u8 *resp_ie,
4179 size_t resp_ie_len, int status, gfp_t gfp,
4180 tSirResultCodes timeout_reason)
4181{
4182 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4183 resp_ie, resp_ie_len, status, gfp);
4184}
4185#endif
4186
Abhishek Singha84d3952016-09-13 13:45:05 +05304187/**
4188 * hdd_connect_bss() - API to send connection status to supplicant
4189 * @dev: network device
4190 * @bssid: bssid to which we want to associate
4191 * @req_ie: Request Information Element
4192 * @req_ie_len: len of the req IE
4193 * @resp_ie: Response IE
4194 * @resp_ie_len: len of ht response IE
4195 * @status: status
4196 * @gfp: Kernel Flag
4197 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304198 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304199 *
4200 * The API is a wrapper to send connection status to supplicant
4201 *
4202 * Return: Void
4203 */
4204#if defined CFG80211_CONNECT_TIMEOUT
4205static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4206 struct cfg80211_bss *bss, const u8 *req_ie,
4207 size_t req_ie_len, const u8 *resp_ie,
4208 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304209 bool connect_timeout,
4210 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304211{
4212 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304213 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304214 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304215 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4216 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304217}
4218#else
4219static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4220 struct cfg80211_bss *bss, const u8 *req_ie,
4221 size_t req_ie_len, const u8 *resp_ie,
4222 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304223 bool connect_timeout,
4224 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304225{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304226 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4227 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304228}
4229#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304230
4231/**
4232 * hdd_connect_result() - API to send connection status to supplicant
4233 * @dev: network device
4234 * @bssid: bssid to which we want to associate
4235 * @roam_info: information about connected bss
4236 * @req_ie: Request Information Element
4237 * @req_ie_len: len of the req IE
4238 * @resp_ie: Response IE
4239 * @resp_ie_len: len of ht response IE
4240 * @status: status
4241 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304242 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304243 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304244 *
4245 * The API is a wrapper to send connection status to supplicant
4246 * and allow runtime suspend
4247 *
4248 * Return: Void
4249 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304250void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4251 tCsrRoamInfo *roam_info, const u8 *req_ie,
4252 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304253 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304254 bool connect_timeout,
4255 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304256{
4257 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4258 struct cfg80211_bss *bss = NULL;
4259
4260 if (WLAN_STATUS_SUCCESS == status) {
4261 struct ieee80211_channel *chan;
4262 int freq;
4263 int chan_no = roam_info->pBssDesc->channelId;
4264
4265 if (chan_no <= 14)
4266 freq = ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -07004267 NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304268 else
4269 freq = ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -07004270 NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304271
4272 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4273 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4274 roam_info->u.pConnectedProfile->SSID.ssId,
4275 roam_info->u.pConnectedProfile->SSID.length);
4276 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304277
Abhishek Singha84d3952016-09-13 13:45:05 +05304278 hdd_connect_bss(dev, bssid, bss, req_ie,
4279 req_ie_len, resp_ie, resp_ie_len,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304280 status, gfp, connect_timeout, timeout_reason);
Komal Seelama89be8d2016-09-29 11:09:26 +05304281
4282 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304283}
4284#else
4285void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4286 tCsrRoamInfo *roam_info, const u8 *req_ie,
4287 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304288 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304289 bool connect_timeout,
4290 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304291{
Komal Seelama89be8d2016-09-29 11:09:26 +05304292 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4293
Anurag Chouhanc4092922016-09-08 15:56:11 +05304294 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4295 resp_ie, resp_ie_len, status, gfp);
Komal Seelama89be8d2016-09-29 11:09:26 +05304296 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304297}
4298#endif
4299
4300
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304301QDF_STATUS hdd_start_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302{
4303 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304304 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305 hdd_adapter_t *adapter;
4306#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05304307 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308#endif
4309 eConnectionState connState;
4310
4311 ENTER();
4312
4313 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304314 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315 adapter = adapterNode->pAdapter;
4316
Arun Khandavallifae92942016-08-01 13:31:08 +05304317 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304318 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05304319
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004320 hdd_wmm_init(adapter);
4321
4322 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004323 case QDF_STA_MODE:
4324 case QDF_P2P_CLIENT_MODE:
4325 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326
4327 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
4328 ->conn_info.connState;
4329
4330 hdd_init_station_mode(adapter);
4331 /* Open the gates for HDD to receive Wext commands */
4332 adapter->isLinkUpSvcNeeded = false;
4333 adapter->scan_info.mScanPending = false;
4334
4335 /* Indicate disconnect event to supplicant if associated previously */
4336 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07004337 eConnectionState_IbssConnected == connState ||
4338 eConnectionState_NotConnected == connState ||
4339 eConnectionState_IbssDisconnected == connState ||
4340 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 union iwreq_data wrqu;
4342 memset(&wrqu, '\0', sizeof(wrqu));
4343 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4344 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4345 wireless_send_event(adapter->dev, SIOCGIWAP,
4346 &wrqu, NULL);
4347 adapter->sessionCtx.station.
4348 hdd_ReassocScenario = false;
4349
4350 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05304351 wlan_hdd_cfg80211_indicate_disconnect(
4352 adapter->dev, false,
4353 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354 } else if (eConnectionState_Connecting == connState) {
4355 /*
4356 * Indicate connect failure to supplicant if we were in the
4357 * process of connecting
4358 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304359 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304360 NULL, 0, NULL, 0,
4361 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
4362 GFP_KERNEL, false,
4363 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 }
4365
4366 hdd_register_tx_flow_control(adapter,
4367 hdd_tx_resume_timer_expired_handler,
4368 hdd_tx_resume_cb);
4369
4370 break;
4371
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004372 case QDF_SAP_MODE:
Arun Khandavallicc544b32017-01-30 19:52:16 +05304373 if (hdd_ctx->config->sap_internal_restart)
4374 hdd_init_ap_mode(adapter, true);
4375
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376 break;
4377
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004378 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004379#ifdef MSM_PLATFORM
Jeff Johnson5880d792016-08-15 13:32:30 -07004380 hdd_err("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
4382#else
Jeff Johnson5880d792016-08-15 13:32:30 -07004383 hdd_err("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384 /* event supplicant to restart */
4385 cfg80211_del_sta(adapter->dev,
4386 (const u8 *)&bcastMac.bytes[0],
4387 GFP_KERNEL);
4388#endif
4389 break;
4390
4391 default:
4392 break;
4393 }
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304394get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4396 adapterNode = pNext;
4397 }
4398
4399 EXIT();
4400
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304401 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402}
4403
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304404QDF_STATUS hdd_get_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405 hdd_adapter_list_node_t **padapterNode)
4406{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304407 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004408 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304409 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
4410 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004411 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412 return status;
4413}
4414
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304415QDF_STATUS hdd_get_next_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 hdd_adapter_list_node_t *adapterNode,
4417 hdd_adapter_list_node_t **pNextAdapterNode)
4418{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304419 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004420 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304421 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
4422 (qdf_list_node_t *) adapterNode,
4423 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004425 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004426 return status;
4427}
4428
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304429QDF_STATUS hdd_remove_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430 hdd_adapter_list_node_t *adapterNode)
4431{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304432 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004433 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304434 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004435 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004436 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437 return status;
4438}
4439
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304440QDF_STATUS hdd_remove_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 hdd_adapter_list_node_t **padapterNode)
4442{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304443 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004444 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304445 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
4446 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004447 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448 return status;
4449}
4450
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304451QDF_STATUS hdd_add_adapter_back(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452 hdd_adapter_list_node_t *adapterNode)
4453{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304454 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004455 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304456 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
4457 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004458 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004459 return status;
4460}
4461
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304462QDF_STATUS hdd_add_adapter_front(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463 hdd_adapter_list_node_t *adapterNode)
4464{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304465 QDF_STATUS status;
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004466 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304467 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
4468 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004469 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004470 return status;
4471}
4472
4473hdd_adapter_t *hdd_get_adapter_by_macaddr(hdd_context_t *hdd_ctx,
4474 tSirMacAddr macAddr)
4475{
4476 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4477 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304478 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479
4480 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4481
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304482 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483 adapter = adapterNode->pAdapter;
4484
4485 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304486 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004487 macAddr, sizeof(tSirMacAddr))) {
4488 return adapter;
4489 }
4490 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4491 adapterNode = pNext;
4492 }
4493
4494 return NULL;
4495
4496}
4497
4498hdd_adapter_t *hdd_get_adapter_by_vdev(hdd_context_t *hdd_ctx,
4499 uint32_t vdev_id)
4500{
4501 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4502 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304503 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304505 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304507 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004508 adapter = adapterNode->pAdapter;
4509
4510 if (adapter->sessionId == vdev_id)
4511 return adapter;
4512
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304513 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004514 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4515 adapterNode = pNext;
4516 }
4517
Jeff Johnson5880d792016-08-15 13:32:30 -07004518 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004519
4520 return NULL;
4521}
4522
Abhishek Singh7996eb72015-12-30 17:24:02 +05304523/**
4524 * hdd_get_adapter_by_sme_session_id() - Return adapter with
4525 * the sessionid
4526 * @hdd_ctx: hdd context.
4527 * @sme_session_id: sme session is for the adapter to get.
4528 *
4529 * This function is used to get the adapter with provided session id
4530 *
4531 * Return: adapter pointer if found
4532 *
4533 */
4534hdd_adapter_t *hdd_get_adapter_by_sme_session_id(hdd_context_t *hdd_ctx,
4535 uint32_t sme_session_id)
4536{
4537 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4538 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304539 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05304540
4541
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304542 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05304543
4544 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304545 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05304546 adapter = adapter_node->pAdapter;
4547
4548 if (adapter &&
4549 adapter->sessionId == sme_session_id)
4550 return adapter;
4551
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304552 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05304553 hdd_get_next_adapter(hdd_ctx,
4554 adapter_node, &next);
4555 adapter_node = next;
4556 }
4557 return NULL;
4558}
4559
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004560/**
4561 * hdd_get_adapter() - to get adapter matching the mode
4562 * @hdd_ctx: hdd context
4563 * @mode: adapter mode
4564 *
4565 * This routine will return the pointer to adapter matching
4566 * with the passed mode.
4567 *
4568 * Return: pointer to adapter or null
4569 */
4570hdd_adapter_t *hdd_get_adapter(hdd_context_t *hdd_ctx,
4571 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004572{
4573 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4574 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304575 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004576
4577 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4578
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304579 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580 adapter = adapterNode->pAdapter;
4581
4582 if (adapter && (mode == adapter->device_mode))
4583 return adapter;
4584
4585 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4586 adapterNode = pNext;
4587 }
4588
4589 return NULL;
4590
4591}
4592
4593/**
4594 * hdd_get_operating_channel() - return operating channel of the device mode
4595 * @hdd_ctx: Pointer to the HDD context.
4596 * @mode: Device mode for which operating channel is required.
4597 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004598 * QDF_STA_MODE,
4599 * QDF_P2P_CLIENT_MODE,
4600 * QDF_SAP_MODE,
4601 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 *
4603 * This API returns the operating channel of the requested device mode
4604 *
4605 * Return: channel number. "0" id the requested device is not found OR it is
4606 * not connected.
4607 */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004608uint8_t hdd_get_operating_channel(hdd_context_t *hdd_ctx,
4609 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004610{
4611 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304612 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004613 hdd_adapter_t *adapter;
4614 uint8_t operatingChannel = 0;
4615
4616 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4617
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304618 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619 adapter = adapterNode->pAdapter;
4620
4621 if (mode == adapter->device_mode) {
4622 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004623 case QDF_STA_MODE:
4624 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625 if (hdd_conn_is_connected
4626 (WLAN_HDD_GET_STATION_CTX_PTR
4627 (adapter))) {
4628 operatingChannel =
4629 (WLAN_HDD_GET_STATION_CTX_PTR
4630 (adapter))->conn_info.
4631 operationChannel;
4632 }
4633 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004634 case QDF_SAP_MODE:
4635 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004636 /* softap connection info */
4637 if (test_bit
4638 (SOFTAP_BSS_STARTED,
4639 &adapter->event_flags))
4640 operatingChannel =
4641 (WLAN_HDD_GET_AP_CTX_PTR
4642 (adapter))->operatingChannel;
4643 break;
4644 default:
4645 break;
4646 }
4647
4648 break; /* Found the device of interest. break the loop */
4649 }
4650
4651 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4652 adapterNode = pNext;
4653 }
4654 return operatingChannel;
4655}
4656
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304657static inline QDF_STATUS hdd_unregister_wext_all_adapters(hdd_context_t *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004658 hdd_ctx)
4659{
4660 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304661 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 hdd_adapter_t *adapter;
4663
4664 ENTER();
4665
4666 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4667
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304668 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004670 if ((adapter->device_mode == QDF_STA_MODE) ||
4671 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4672 (adapter->device_mode == QDF_IBSS_MODE) ||
4673 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4674 (adapter->device_mode == QDF_SAP_MODE) ||
4675 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004676 wlan_hdd_cfg80211_deregister_frames(adapter);
4677 hdd_unregister_wext(adapter->dev);
4678 }
4679 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4680 adapterNode = pNext;
4681 }
4682
4683 EXIT();
4684
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304685 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004686}
4687
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304688QDF_STATUS hdd_abort_mac_scan_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689{
4690 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304691 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004692 hdd_adapter_t *adapter;
4693
4694 ENTER();
4695
4696 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4697
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304698 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004699 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004700 if ((adapter->device_mode == QDF_STA_MODE) ||
4701 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4702 (adapter->device_mode == QDF_IBSS_MODE) ||
4703 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4704 (adapter->device_mode == QDF_SAP_MODE) ||
4705 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004706 hdd_abort_mac_scan(hdd_ctx, adapter->sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304707 INVALID_SCAN_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004708 eCSR_SCAN_ABORT_DEFAULT);
4709 }
4710 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4711 adapterNode = pNext;
4712 }
4713
4714 EXIT();
4715
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304716 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717}
4718
Dustin Brownf27bce82016-11-03 12:52:27 -07004719/**
4720 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
4721 * adapters
4722 * @hdd_ctx: The HDD context containing the adapters to operate on
4723 *
4724 * return: QDF_STATUS_SUCCESS
4725 */
4726static QDF_STATUS hdd_abort_sched_scan_all_adapters(hdd_context_t *hdd_ctx)
4727{
4728 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
4729 QDF_STATUS status;
4730 hdd_adapter_t *adapter;
4731 int err;
4732
4733 ENTER();
4734
4735 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4736
4737 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4738 adapter = adapter_node->pAdapter;
4739 if ((adapter->device_mode == QDF_STA_MODE) ||
4740 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4741 (adapter->device_mode == QDF_IBSS_MODE) ||
4742 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4743 (adapter->device_mode == QDF_SAP_MODE) ||
4744 (adapter->device_mode == QDF_P2P_GO_MODE)) {
4745 err = wlan_hdd_sched_scan_stop(adapter->dev);
4746 if (err)
4747 hdd_err("Unable to stop scheduled scan");
4748 }
4749 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next_node);
4750 adapter_node = next_node;
4751 }
4752
4753 EXIT();
4754
4755 return QDF_STATUS_SUCCESS;
4756}
4757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004758#ifdef WLAN_NS_OFFLOAD
4759/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004760 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004761 * @hdd_ctx: Pointer to hdd context
4762 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004763 * Unregister for IPv6 address change notifications.
4764 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004765 * Return: None
4766 */
4767static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
4768{
4769 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
4770
4771 return;
4772}
4773
4774/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004775 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004776 * @hdd_ctx: Pointer to hdd context
4777 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004778 * Register for IPv6 address change notifications.
4779 *
4780 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004781 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004782static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004783{
4784 int ret;
4785
4786 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
4787 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004788 if (ret) {
4789 hdd_err("Failed to register IPv6 notifier: %d", ret);
4790 goto out;
4791 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004792
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004793 hdd_info("Registered IPv6 notifier");
4794out:
4795 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796}
4797#else
4798/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004799 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004800 * @hdd_ctx: Pointer to hdd context
4801 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004802 * Unregister for IPv6 address change notifications.
4803 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004804 * Return: None
4805 */
4806static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
4807{
4808}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004809
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004810/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004811 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004812 * @hdd_ctx: Pointer to hdd context
4813 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004814 * Register for IPv6 address change notifications.
4815 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004816 * Return: None
4817 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004818static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004819{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004820 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004821}
4822#endif
4823
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304824#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
4825/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004826 * hdd_logging_sock_activate_svc() - Activate logging
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304827 * @hdd_ctx: HDD context
4828 *
4829 * Activates the logging service
4830 *
4831 * Return: Zero in case of success, negative value otherwise
4832 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004833static int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304834{
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004835 int ret;
4836 struct hdd_config *config = hdd_ctx->config;
4837
4838 if (!config->wlanLoggingEnable)
4839 return 0;
4840
4841 ret = wlan_logging_sock_activate_svc(config->wlanLoggingFEToConsole,
4842 config->wlanLoggingNumBuf);
4843 if (ret)
4844 hdd_err("wlan_logging_sock_activate_svc failed: %d", ret);
4845 return ret;
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304846}
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004847
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304848/**
4849 * wlan_hdd_logging_sock_deactivate_svc() - Deactivate logging
4850 * @hdd_ctx: HDD context
4851 *
4852 * Deactivates the logging service
4853 *
4854 * Return: 0 on deactivating the logging service
4855 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004856static int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304857{
4858 if (hdd_ctx && hdd_ctx->config->wlanLoggingEnable)
4859 return wlan_logging_sock_deactivate_svc();
4860
4861 return 0;
4862}
4863#else
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004864static inline int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304865{
4866 return 0;
4867}
4868
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08004869static inline int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05304870{
4871 return 0;
4872}
4873#endif
4874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004875/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004876 * hdd_register_notifiers - Register netdev notifiers.
4877 * @hdd_ctx: HDD context
4878 *
4879 * Register netdev notifiers like IPv4 and IPv6.
4880 *
4881 * Return: 0 on success and errno on failure
4882 */
4883static int hdd_register_notifiers(hdd_context_t *hdd_ctx)
4884{
4885 int ret;
4886
4887 ret = register_netdevice_notifier(&hdd_netdev_notifier);
4888 if (ret) {
4889 hdd_err("register_netdevice_notifier failed: %d", ret);
4890 goto out;
4891 }
4892
4893 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
4894 if (ret)
4895 goto unregister_notifier;
4896
4897 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
4898 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
4899 if (ret) {
4900 hdd_err("Failed to register IPv4 notifier: %d", ret);
4901 goto unregister_ip6_notifier;
4902 }
4903
4904 return 0;
4905
4906unregister_ip6_notifier:
4907 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
4908unregister_notifier:
4909 unregister_netdevice_notifier(&hdd_netdev_notifier);
4910out:
4911 return ret;
4912
4913}
4914
4915/**
4916 * hdd_unregister_notifiers - Unregister netdev notifiers.
4917 * @hdd_ctx: HDD context
4918 *
4919 * Unregister netdev notifiers like IPv4 and IPv6.
4920 *
4921 * Return: None.
4922 */
4923static void hdd_unregister_notifiers(hdd_context_t *hdd_ctx)
4924{
4925 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
4926
4927 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
4928
4929 unregister_netdevice_notifier(&hdd_netdev_notifier);
4930}
4931
4932/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004933 * hdd_exit_netlink_services - Exit netlink services
4934 * @hdd_ctx: HDD context
4935 *
4936 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
4937 * nl service.
4938 *
4939 * Return: None.
4940 */
4941static void hdd_exit_netlink_services(hdd_context_t *hdd_ctx)
4942{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004943 hdd_close_cesium_nl_sock();
4944
4945 ptt_sock_deactivate_svc();
4946
4947 nl_srv_exit();
4948}
4949
4950/**
4951 * hdd_init_netlink_services- Init netlink services
4952 * @hdd_ctx: HDD context
4953 *
4954 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
4955 * nl service.
4956 *
4957 * Return: 0 on success and errno on failure.
4958 */
4959static int hdd_init_netlink_services(hdd_context_t *hdd_ctx)
4960{
4961 int ret;
4962
Ryan Hsuceddceb2016-04-28 10:20:14 -07004963 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004964 if (ret) {
4965 hdd_alert("nl_srv_init failed: %d", ret);
4966 goto out;
4967 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07004968 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004969
4970 ret = oem_activate_service(hdd_ctx);
4971 if (ret) {
4972 hdd_alert("oem_activate_service failed: %d", ret);
4973 goto err_nl_srv;
4974 }
4975
4976 ret = ptt_sock_activate_svc();
4977 if (ret) {
4978 hdd_alert("ptt_sock_activate_svc failed: %d", ret);
4979 goto err_nl_srv;
4980 }
4981
4982 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07004983 if (ret)
4984 hdd_warn("hdd_open_cesium_nl_sock failed");
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004985
4986 ret = cnss_diag_activate_service();
4987 if (ret) {
4988 hdd_alert("cnss_diag_activate_service failed: %d", ret);
4989 goto err_close_cesium;
4990 }
4991
4992 return 0;
4993
4994err_close_cesium:
4995 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08004996 ptt_sock_deactivate_svc();
4997err_nl_srv:
4998 nl_srv_exit();
4999out:
5000 return ret;
5001}
5002
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005003/**
5004 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5005 * @hdd_ctx: HDD context.
5006 *
5007 * Destroy RX wakelock.
5008 *
5009 * Return: None.
5010 */
5011static void hdd_rx_wake_lock_destroy(hdd_context_t *hdd_ctx)
5012{
5013 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5014}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005015
5016/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005017 * hdd_rx_wake_lock_create() - Create RX wakelock
5018 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005019 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005020 * Create RX wakelock.
5021 *
5022 * Return: None.
5023 */
5024static void hdd_rx_wake_lock_create(hdd_context_t *hdd_ctx)
5025{
5026 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5027}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005028
5029/**
5030 * hdd_roc_context_init() - Init ROC context
5031 * @hdd_ctx: HDD context.
5032 *
5033 * Initialize ROC context.
5034 *
5035 * Return: 0 on success and errno on failure.
5036 */
5037static int hdd_roc_context_init(hdd_context_t *hdd_ctx)
5038{
5039 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5040 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5041
5042 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5043
5044 return 0;
5045}
5046
5047/**
5048 * hdd_roc_context_destroy() - Destroy ROC context
5049 * @hdd_ctx: HDD context.
5050 *
5051 * Destroy roc list and flush the pending roc work.
5052 *
5053 * Return: None.
5054 */
5055static void hdd_roc_context_destroy(hdd_context_t *hdd_ctx)
5056{
5057 flush_delayed_work(&hdd_ctx->roc_req_work);
5058 qdf_list_destroy(&hdd_ctx->hdd_roc_req_q);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005059 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005060}
5061
5062/**
Houston Hoffman160db392016-10-10 17:37:51 -07005063 * hdd_context_deinit() - Deinitialize HDD context
5064 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005065 *
Houston Hoffman160db392016-10-10 17:37:51 -07005066 * Deinitialize HDD context along with all the feature specific contexts but
5067 * do not free hdd context itself. Caller of this API is supposed to free
5068 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005069 *
Houston Hoffman160db392016-10-10 17:37:51 -07005070 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005071 */
Houston Hoffman160db392016-10-10 17:37:51 -07005072static int hdd_context_deinit(hdd_context_t *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005073{
Houston Hoffman160db392016-10-10 17:37:51 -07005074 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005075
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005076 hdd_roc_context_destroy(hdd_ctx);
5077
5078 hdd_sap_context_destroy(hdd_ctx);
5079
5080 hdd_rx_wake_lock_destroy(hdd_ctx);
5081
5082 hdd_tdls_context_destroy(hdd_ctx);
5083
5084 hdd_scan_context_destroy(hdd_ctx);
5085
5086 qdf_list_destroy(&hdd_ctx->hddAdapters);
5087
Houston Hoffman160db392016-10-10 17:37:51 -07005088 return 0;
5089}
5090
5091/**
5092 * hdd_context_destroy() - Destroy HDD context
5093 * @hdd_ctx: HDD context to be destroyed.
5094 *
5095 * Free config and HDD context as well as destroy all the resources.
5096 *
5097 * Return: None
5098 */
5099static void hdd_context_destroy(hdd_context_t *hdd_ctx)
5100{
5101 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
5102 hdd_logging_sock_deactivate_svc(hdd_ctx);
5103
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305104 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5105
Houston Hoffman160db392016-10-10 17:37:51 -07005106 hdd_context_deinit(hdd_ctx);
5107
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305108 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005109 hdd_ctx->config = NULL;
5110
5111 wiphy_free(hdd_ctx->wiphy);
5112}
5113
5114/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115 * hdd_wlan_exit() - HDD WLAN exit function
5116 * @hdd_ctx: Pointer to the HDD Context
5117 *
5118 * This is the driver exit point (invoked during rmmod)
5119 *
5120 * Return: None
5121 */
Jeff Johnson590e2012016-10-05 16:16:24 -07005122static void hdd_wlan_exit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123{
5124 v_CONTEXT_t p_cds_context = hdd_ctx->pcds_context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305125 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005126 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305127 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005128
5129 ENTER();
5130
Arun Khandavallifae92942016-08-01 13:31:08 +05305131 if (QDF_TIMER_STATE_RUNNING ==
5132 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
5133 hdd_info("Stpp interface change timer");
5134 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 }
5136
Arun Khandavallifae92942016-08-01 13:31:08 +05305137 if (!QDF_IS_STATUS_SUCCESS
5138 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5139 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005140
Arun Khandavallifae92942016-08-01 13:31:08 +05305141
5142 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143
Nitesh Shah61c10d92016-10-19 19:29:15 +05305144 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5145
Prashanth Bhattaab004382016-10-11 16:08:11 -07005146 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147
5148#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305149 if (QDF_TIMER_STATE_RUNNING ==
5150 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5151 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 }
5153
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305154 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305155 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005156 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005158 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5159 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5160 hdd_ctx->last_acs_channel_list = NULL;
5161 hdd_ctx->num_of_channels = 0;
5162 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005164
Arun Khandavallifae92942016-08-01 13:31:08 +05305165 mutex_lock(&hdd_ctx->iface_change_lock);
5166 driver_status = hdd_ctx->driver_status;
5167 mutex_unlock(&hdd_ctx->iface_change_lock);
5168
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005169 /*
5170 * Powersave Offload Case
5171 * Disable Idle Power Save Mode
5172 */
5173 hdd_set_idle_ps_config(hdd_ctx, false);
5174
Arun Khandavallifae92942016-08-01 13:31:08 +05305175 if (driver_status != DRIVER_MODULES_CLOSED) {
5176 hdd_unregister_wext_all_adapters(hdd_ctx);
5177 /*
5178 * Cancel any outstanding scan requests. We are about to close
5179 * all of our adapters, but an adapter structure is what SME
5180 * passes back to our callback function. Hence if there
5181 * are any outstanding scan requests then there is a
5182 * race condition between when the adapter is closed and
5183 * when the callback is invoked. We try to resolve that
5184 * race condition here by canceling any outstanding scans
5185 * before we close the adapters.
5186 * Note that the scans may be cancelled in an asynchronous
5187 * manner, so ideally there needs to be some kind of
5188 * synchronization. Rather than introduce a new
5189 * synchronization here, we will utilize the fact that we are
5190 * about to Request Full Power, and since that is synchronized,
5191 * the expectation is that by the time Request Full Power has
5192 * completed, all scans will be cancelled
5193 */
Jeff Johnsonf337b0c2017-03-10 10:48:30 -08005194 hdd_cleanup_scan_queue(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305195 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005196 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305197 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 }
5199
5200 /*
5201 * Close the scheduler before calling cds_close to make sure no thread
5202 * is scheduled after the each module close is called i.e after all the
5203 * data structures are freed.
5204 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305205 qdf_status = cds_sched_close(p_cds_context);
5206 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005207 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305208 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305211 hdd_wlan_stop_modules(hdd_ctx);
5212
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305213 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5214 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5215 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5216
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 /*
5218 * Close CDS
5219 * This frees pMac(HAL) context. There should not be any call
5220 * that requires pMac access after this.
5221 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005223 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005224 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225
Komal Seelam8634b772016-09-29 12:12:24 +05305226 hdd_runtime_suspend_context_deinit(hdd_ctx);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005227 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005228
5229 hdd_ipa_cleanup(hdd_ctx);
5230
5231 /* Free up RoC request queue and flush workqueue */
5232 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305234 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305235 wlan_hdd_deinit_chan_info(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 wiphy_unregister(wiphy);
Abhishek Singhf512bf32016-05-04 16:47:46 +05305237 wlan_hdd_cfg80211_deinit(wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005238
Jeff Johnsonf7f66f02016-09-23 14:50:11 -07005239 hdd_lpass_notify_stop(hdd_ctx);
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005240
Arun Khandavallifae92942016-08-01 13:31:08 +05305241 hdd_exit_netlink_services(hdd_ctx);
5242 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005243 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244}
5245
5246void __hdd_wlan_exit(void)
5247{
5248 hdd_context_t *hdd_ctx;
5249
5250 ENTER();
5251
Anurag Chouhan6d760662016-02-20 16:05:43 +05305252 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 if (!hdd_ctx) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005254 hdd_alert("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005255 EXIT();
5256 return;
5257 }
5258
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005259 /* Check IPA HW Pipe shutdown */
5260 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
5261
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005262 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05305263 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005264
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265 /* Do all the cleanup before deregistering the driver */
5266 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07005267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 EXIT();
5269}
5270
5271#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04005272/**
5273 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
5274 * @data: pointer to hdd_context_t
5275 *
5276 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
5277 * Then new ACS request will do a fresh scan without reusing the cached
5278 * scan information.
5279 *
5280 * Return: void
5281 */
Tang Yingying523322d2017-01-17 23:28:43 +08005282static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005283{
5284 hdd_context_t *hdd_ctx = (hdd_context_t *) data;
5285
Jeff Johnson760350b2016-08-15 14:01:52 -07005286 hdd_notice("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04005288 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5289 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5290 hdd_ctx->last_acs_channel_list = NULL;
5291 hdd_ctx->num_of_channels = 0;
5292 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293
5294 if (!hdd_ctx->hHal)
5295 return;
5296 sme_scan_flush_result(hdd_ctx->hHal);
5297}
5298#endif
5299
5300#ifdef QCA_HT_2040_COEX
5301/**
5302 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
5303 * @adapter: pointer to adapter
5304 * @staId: station id
5305 * @macAddrSTA: station MAC address
5306 * @channel_type: channel type
5307 *
5308 * This function notifies FW with HT20/HT40 mode
5309 *
5310 * Return: 0 if successful, error number otherwise
5311 */
5312int hdd_wlan_set_ht2040_mode(hdd_adapter_t *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305313 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314{
5315 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305316 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317 hdd_context_t *hdd_ctx = NULL;
5318
5319 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5320
5321 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305322 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305324
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005325 if (!hdd_ctx->hHal)
5326 return -EINVAL;
5327
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305328 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305330 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005331 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 return -EINVAL;
5333 }
5334
5335 return 0;
5336}
5337#endif
5338
5339/**
5340 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
5341 * @state: state
5342 *
5343 * This function notifies FW with modem power status
5344 *
5345 * Return: 0 if successful, error number otherwise
5346 */
5347int hdd_wlan_notify_modem_power_state(int state)
5348{
5349 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305350 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005351 hdd_context_t *hdd_ctx;
5352
Anurag Chouhan6d760662016-02-20 16:05:43 +05305353 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305355 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005356 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305357
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 if (!hdd_ctx->hHal)
5359 return -EINVAL;
5360
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305361 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
5362 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005363 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364 state);
5365 return -EINVAL;
5366 }
5367 return 0;
5368}
5369
5370/**
5371 *
5372 * hdd_post_cds_enable_config() - HDD post cds start config helper
5373 * @adapter - Pointer to the HDD
5374 *
5375 * Return: None
5376 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305377QDF_STATUS hdd_post_cds_enable_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005378{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305379 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005380
5381 /*
5382 * Send ready indication to the HDD. This will kick off the MAC
5383 * into a 'running' state and should kick off an initial scan.
5384 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305385 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
5386 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005387 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
5388 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305389 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005390 }
5391
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305392 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005393}
5394
5395/* wake lock APIs for HDD */
5396void hdd_prevent_suspend(uint32_t reason)
5397{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305398 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005399}
5400
5401void hdd_allow_suspend(uint32_t reason)
5402{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305403 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005404}
5405
5406void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
5407{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05305408 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
5409 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410}
5411
5412/**
5413 * hdd_exchange_version_and_caps() - exchange version and capability with target
5414 * @hdd_ctx: Pointer to HDD context
5415 *
5416 * This is the HDD function to exchange version and capability information
5417 * between Host and Target
5418 *
5419 * This function gets reported version of FW.
5420 * It also finds the version of target headers used to compile the host;
5421 * It compares the above two and prints a warning if they are different;
5422 * It gets the SW and HW version string;
5423 * Finally, it exchanges capabilities between host and target i.e. host
5424 * and target exchange a msg indicating the features they support through a
5425 * bitmap
5426 *
5427 * Return: None
5428 */
5429void hdd_exchange_version_and_caps(hdd_context_t *hdd_ctx)
5430{
5431
5432 tSirVersionType versionCompiled;
5433 tSirVersionType versionReported;
5434 tSirVersionString versionString;
5435 uint8_t fwFeatCapsMsgSupported = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305436 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005437
5438 memset(&versionCompiled, 0, sizeof(versionCompiled));
5439 memset(&versionReported, 0, sizeof(versionReported));
5440
5441 /* retrieve and display WCNSS version information */
5442 do {
5443
5444 vstatus = sme_get_wcnss_wlan_compiled_version(hdd_ctx->hHal,
5445 &versionCompiled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305446 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005447 hdd_alert("unable to retrieve WCNSS WLAN compiled version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005448 break;
5449 }
5450
5451 vstatus = sme_get_wcnss_wlan_reported_version(hdd_ctx->hHal,
5452 &versionReported);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305453 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005454 hdd_alert("unable to retrieve WCNSS WLAN reported version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005455 break;
5456 }
5457
5458 if ((versionCompiled.major != versionReported.major) ||
5459 (versionCompiled.minor != versionReported.minor) ||
5460 (versionCompiled.version != versionReported.version) ||
5461 (versionCompiled.revision != versionReported.revision)) {
5462 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
5463 "Host expected %u.%u.%u.%u\n",
5464 WLAN_MODULE_NAME,
5465 (int)versionReported.major,
5466 (int)versionReported.minor,
5467 (int)versionReported.version,
5468 (int)versionReported.revision,
5469 (int)versionCompiled.major,
5470 (int)versionCompiled.minor,
5471 (int)versionCompiled.version,
5472 (int)versionCompiled.revision);
5473 } else {
5474 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
5475 WLAN_MODULE_NAME,
5476 (int)versionReported.major,
5477 (int)versionReported.minor,
5478 (int)versionReported.version,
5479 (int)versionReported.revision);
5480 }
5481
5482 vstatus = sme_get_wcnss_software_version(hdd_ctx->hHal,
5483 versionString,
5484 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305485 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005486 hdd_alert("unable to retrieve WCNSS software version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005487 break;
5488 }
5489
5490 pr_info("%s: WCNSS software version %s\n",
5491 WLAN_MODULE_NAME, versionString);
5492
5493 vstatus = sme_get_wcnss_hardware_version(hdd_ctx->hHal,
5494 versionString,
5495 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305496 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Jeff Johnsonb7082ae2016-08-23 13:13:30 -07005497 hdd_alert("unable to retrieve WCNSS hardware version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005498 break;
5499 }
5500
5501 pr_info("%s: WCNSS hardware version %s\n",
5502 WLAN_MODULE_NAME, versionString);
5503
5504 /*
5505 * 1.Check if FW version is greater than 0.1.1.0. Only then
5506 * send host-FW capability exchange message
5507 * 2.Host-FW capability exchange message is only present on
5508 * target 1.1 so send the message only if it the target is 1.1
5509 * minor numbers for different target branches:
5510 * 0 -> (1.0)Mainline Build
5511 * 1 -> (1.1)Mainline Build
5512 * 2->(1.04) Stability Build
5513 */
5514 if (((versionReported.major > 0) || (versionReported.minor > 1)
5515 || ((versionReported.minor >= 1)
5516 && (versionReported.version >= 1)))
5517 && ((versionReported.major == 1)
5518 && (versionReported.minor >= 1)))
5519 fwFeatCapsMsgSupported = 1;
5520
5521 if (fwFeatCapsMsgSupported) {
5522 /*
5523 * Indicate if IBSS heartbeat monitoring needs to be
5524 * offloaded
5525 */
5526 if (!hdd_ctx->config->enableIbssHeartBeatOffload) {
5527 sme_disable_feature_capablity
5528 (IBSS_HEARTBEAT_OFFLOAD);
5529 }
5530
5531 sme_feature_caps_exchange(hdd_ctx->hHal);
5532 }
5533
5534 } while (0);
5535
5536}
5537
5538/* Initialize channel list in sme based on the country code */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305539QDF_STATUS hdd_set_sme_chan_list(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005540{
5541 return sme_init_chan_list(hdd_ctx->hHal, hdd_ctx->reg.alpha2,
5542 hdd_ctx->reg.cc_src);
5543}
5544
5545/**
5546 * hdd_is_5g_supported() - check if hardware supports 5GHz
5547 * @hdd_ctx: Pointer to the hdd context
5548 *
5549 * HDD function to know if hardware supports 5GHz
5550 *
5551 * Return: true if hardware supports 5GHz
5552 */
5553bool hdd_is_5g_supported(hdd_context_t *hdd_ctx)
5554{
zdingf54169a2016-10-12 17:08:45 +08005555 if (!hdd_ctx || !hdd_ctx->config)
5556 return true;
5557
5558 if (hdd_ctx->config->nBandCapability != eCSR_BAND_24)
5559 return true;
5560 else
5561 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562}
5563
Amar Singhale4f28ee2015-10-21 14:36:56 -07005564static int hdd_wiphy_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565{
5566 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07005567 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005568
5569 wiphy = hdd_ctx->wiphy;
5570
5571 /*
5572 * The channel information in
5573 * wiphy needs to be initialized before wiphy registration
5574 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07005575 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
5576 if (ret_val) {
5577 hdd_alert("regulatory init failed");
5578 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005579 }
5580
5581#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
5582 wiphy->wowlan = &wowlan_support_reg_init;
5583#else
5584 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
5585 WIPHY_WOWLAN_MAGIC_PKT |
5586 WIPHY_WOWLAN_DISCONNECT |
5587 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
5588 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
5589 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
5590 WIPHY_WOWLAN_4WAY_HANDSHAKE |
5591 WIPHY_WOWLAN_RFKILL_RELEASE;
5592
5593 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
5594 WOW_MAX_FILTERS_PER_LIST);
5595 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
5596 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
5597#endif
5598
5599 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07005600 ret_val = wlan_hdd_cfg80211_register(wiphy);
5601 if (0 > ret_val)
5602 hdd_err("wiphy registration failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005603
Amar Singhale4f28ee2015-10-21 14:36:56 -07005604 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005605}
5606
Ravi Joshie2331e82015-07-01 18:18:54 -07005607/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07005608 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07005609 * @hdd_ctx - handle to hdd context
5610 * @tx_packets - transmit packet count
5611 * @rx_packets - receive packet count
5612 *
5613 * The function controls the bus bandwidth and dynamic control of
5614 * tcp delayed ack configuration
5615 *
5616 * Returns: None
5617 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005618#ifdef MSM_PLATFORM
Jeff Johnson590e2012016-10-05 16:16:24 -07005619static void hdd_pld_request_bus_bandwidth(hdd_context_t *hdd_ctx,
5620 const uint64_t tx_packets,
5621 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005622{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005623 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08005624 uint64_t temp_rx = 0;
5625 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07005626 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08005627 enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
5628 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07005629 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005630
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005632 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005634 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07005635 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005636 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07005637 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07005638 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639
Mohit Khannae71e2262015-11-10 09:37:24 -08005640 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].next_vote_level =
5641 next_vote_level;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642
5643 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07005644 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
5645 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646 hdd_ctx->cur_vote_level = next_vote_level;
Yuanyuan Liu13738502016-04-06 17:41:37 -07005647 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05305648 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05305649 if (hdd_ctx->hbw_requested) {
5650 pld_remove_pm_qos(hdd_ctx->parent_dev);
5651 hdd_ctx->hbw_requested = false;
5652 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05305653 if (cds_sched_handle_throughput_req(false))
Jeff Johnsonb7082ae2016-08-23 13:13:30 -07005654 hdd_err("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05305655 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05305656 if (!hdd_ctx->hbw_requested) {
5657 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
5658 hdd_ctx->hbw_requested = true;
5659 }
5660
Nirav Shah3bbfa512016-05-12 16:43:49 +05305661 if (cds_sched_handle_throughput_req(true))
Jeff Johnsonb7082ae2016-08-23 13:13:30 -07005662 hdd_err("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05305663 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07005664 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005665 }
Mohit Khannae71e2262015-11-10 09:37:24 -08005666
5667 /* fine-tuning parameters for RX Flows */
5668 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
5669
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005670 hdd_ctx->prev_rx = rx_packets;
Ravi Joshifed83572016-10-07 16:20:37 -07005671 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
5672 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
5673 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
5674 next_rx_level = WLAN_SVC_TP_HIGH;
5675 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07005676 } else {
Mohit Khannae71e2262015-11-10 09:37:24 -08005677 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07005678 hdd_ctx->rx_high_ind_cnt = 0;
5679 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005680
Mohit Khannae71e2262015-11-10 09:37:24 -08005681 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].next_rx_level =
5682 next_rx_level;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683
5684 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07005685 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005686 next_rx_level, temp_rx);
5687 hdd_ctx->cur_rx_level = next_rx_level;
Ravi Joshie2331e82015-07-01 18:18:54 -07005688 /* Send throughput indication only if it is enabled.
5689 * Disabling tcp_del_ack will revert the tcp stack behavior
5690 * to default delayed ack. Note that this will disable the
5691 * dynamic delayed ack mechanism across the system
5692 */
5693 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05305694 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
5695 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005696 &next_rx_level,
5697 sizeof(next_rx_level));
5698 }
5699
Mohit Khannae71e2262015-11-10 09:37:24 -08005700 /* fine-tuning parameters for TX Flows */
5701 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
5702 hdd_ctx->prev_tx = tx_packets;
5703 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
5704 next_tx_level = WLAN_SVC_TP_HIGH;
5705 else
5706 next_tx_level = WLAN_SVC_TP_LOW;
5707
5708 if (hdd_ctx->cur_tx_level != next_tx_level) {
5709 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
5710 next_tx_level, temp_tx);
5711 hdd_ctx->cur_tx_level = next_tx_level;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05305712 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
5713 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08005714 &next_tx_level,
5715 sizeof(next_tx_level));
5716 }
5717
5718 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].next_tx_level =
5719 next_tx_level;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720 hdd_ctx->hdd_txrx_hist_idx++;
5721 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005722}
5723
5724#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305725static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005726{
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305727 hdd_context_t *hdd_ctx = container_of(work, hdd_context_t,
5728 bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005729 hdd_adapter_t *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305730 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05305731 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
5732 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005733 uint64_t total_tx = 0, total_rx = 0;
5734 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305735 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305736 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005737 bool connected = false;
5738 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
5739
Prashanth Bhattaab004382016-10-11 16:08:11 -07005740 if (wlan_hdd_validate_context(hdd_ctx))
5741 return;
5742
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305744 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745 status =
5746 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
5747
5748 if (adapterNode->pAdapter == NULL)
5749 continue;
5750 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05305751 /*
5752 * Validate magic so we don't end up accessing
5753 * an invalid adapter.
5754 */
5755 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
5756 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005757
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005758 if ((adapter->device_mode == QDF_STA_MODE ||
5759 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
5761 != eConnectionState_Associated) {
5762
5763 continue;
5764 }
5765
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005766 if ((adapter->device_mode == QDF_SAP_MODE ||
5767 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005768 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
5769
5770 continue;
5771 }
5772
5773 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
5774 adapter->prev_tx_packets);
5775 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
5776 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305777
5778 if (adapter->device_mode == QDF_SAP_MODE ||
5779 adapter->device_mode == QDF_P2P_GO_MODE ||
5780 adapter->device_mode == QDF_IBSS_MODE) {
5781
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08005782 ret = cdp_get_intra_bss_fwd_pkts_count(
5783 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305784 adapter->sessionId,
5785 &fwd_tx_packets, &fwd_rx_packets);
5786 if (ret == A_OK) {
5787 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
5788 fwd_tx_packets,
5789 adapter->prev_fwd_tx_packets);
5790 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
5791 fwd_tx_packets,
5792 adapter->prev_fwd_rx_packets);
5793 }
5794 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005795
5796 total_rx += adapter->stats.rx_packets;
5797 total_tx += adapter->stats.tx_packets;
5798
5799 spin_lock_bh(&hdd_ctx->bus_bw_lock);
5800 adapter->prev_tx_packets = adapter->stats.tx_packets;
5801 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305802 adapter->prev_fwd_tx_packets = fwd_tx_packets;
5803 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005804 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
5805 connected = true;
5806 }
5807
5808 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].total_rx = total_rx;
5809 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].total_tx = total_tx;
5810 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].interval_rx =
5811 rx_packets;
5812 hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].interval_tx =
5813 tx_packets;
5814
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305815 /* add intra bss forwarded tx and rx packets */
5816 tx_packets += fwd_tx_packets_diff;
5817 rx_packets += fwd_rx_packets_diff;
5818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005819 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
5820 tx_packets += (uint64_t)ipa_tx_packets;
5821 rx_packets += (uint64_t)ipa_rx_packets;
5822
5823 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005824 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005825 return;
5826 }
5827
Yuanyuan Liu13738502016-04-06 17:41:37 -07005828 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005829
5830 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
5831 hdd_ipa_uc_stat_request(adapter, 2);
5832
Dustin Brown2ed60362017-01-18 12:25:50 -08005833 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08005834 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08005835 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05305836 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08005837 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08005838 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005839}
Prashanth Bhattaab004382016-10-11 16:08:11 -07005840
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305841/**
5842 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
5843 * @arg: Argument of timer function
5844 *
5845 * Schedule a workqueue in this function where all the processing is done.
5846 *
5847 * Return: None.
5848 */
5849static void __hdd_bus_bw_cbk(void *arg)
5850{
5851 hdd_context_t *hdd_ctx = (hdd_context_t *) arg;
5852
5853 if (wlan_hdd_validate_context(hdd_ctx))
5854 return;
5855
5856 schedule_work(&hdd_ctx->bus_bw_work);
5857}
5858
5859/**
5860 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
5861 * @arg: Argument of timer function
5862 *
5863 * Return: None.
5864 */
5865static void hdd_bus_bw_cbk(void *arg)
5866{
5867 cds_ssr_protect(__func__);
5868 __hdd_bus_bw_cbk(arg);
5869 cds_ssr_unprotect(__func__);
5870}
5871
Prashanth Bhattaab004382016-10-11 16:08:11 -07005872int hdd_bus_bandwidth_init(hdd_context_t *hdd_ctx)
5873{
5874 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305875 INIT_WORK(&hdd_ctx->bus_bw_work,
5876 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08005877 hdd_ctx->bus_bw_timer_running = false;
5878 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305879 qdf_timer_init(NULL,
5880 &hdd_ctx->bus_bw_timer,
5881 hdd_bus_bw_cbk, (void *)hdd_ctx,
5882 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07005883
5884 return 0;
5885}
5886
5887void hdd_bus_bandwidth_destroy(hdd_context_t *hdd_ctx)
5888{
Dustin Brownfce08d12017-01-17 16:29:38 -08005889 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07005890 hdd_reset_tcp_delack(hdd_ctx);
5891
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305892 hdd_info("wait for bus bw work to flush");
5893 cancel_work_sync(&hdd_ctx->bus_bw_work);
5894 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08005895 hdd_ctx->bus_bw_timer_running = false;
5896 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07005897}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898#endif
5899
5900/**
Nirav Shahed34b212016-04-25 10:59:16 +05305901 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
5902 * @hdd_ctx: hdd context
5903 *
5904 * Return: 0 for success or error code
5905 */
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07005906static int wlan_hdd_init_tx_rx_histogram(hdd_context_t *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05305907{
5908 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
5909 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
5910 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005911 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05305912 return -ENOMEM;
5913 }
5914 return 0;
5915}
5916
5917/**
5918 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
5919 * @hdd_ctx: hdd context
5920 *
5921 * Return: none
5922 */
5923void wlan_hdd_deinit_tx_rx_histogram(hdd_context_t *hdd_ctx)
5924{
5925 if (hdd_ctx->hdd_txrx_hist) {
5926 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
5927 hdd_ctx->hdd_txrx_hist = NULL;
5928 }
5929}
5930
Nirav Shahda008342016-05-17 18:50:40 +05305931static uint8_t *convert_level_to_string(uint32_t level)
5932{
5933 switch (level) {
5934 /* initialize the wlan sub system */
5935 case WLAN_SVC_TP_NONE:
5936 return "NONE";
5937 case WLAN_SVC_TP_LOW:
5938 return "LOW";
5939 case WLAN_SVC_TP_MEDIUM:
5940 return "MED";
5941 case WLAN_SVC_TP_HIGH:
5942 return "HIGH";
5943 default:
5944 return "INVAL";
5945 }
5946}
5947
Nirav Shahed34b212016-04-25 10:59:16 +05305948
5949/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
5951 * @hdd_ctx: hdd context
5952 *
5953 * Return: none
5954 */
5955void wlan_hdd_display_tx_rx_histogram(hdd_context_t *hdd_ctx)
5956{
5957 int i;
5958
5959#ifdef MSM_PLATFORM
Jeff Johnson760350b2016-08-15 14:01:52 -07005960 hdd_err("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05305961 hdd_ctx->config->busBandwidthComputeInterval);
Jeff Johnson760350b2016-08-15 14:01:52 -07005962 hdd_err("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005963 hdd_ctx->config->busBandwidthHighThreshold,
5964 hdd_ctx->config->busBandwidthMediumThreshold,
5965 hdd_ctx->config->busBandwidthLowThreshold);
Jeff Johnson760350b2016-08-15 14:01:52 -07005966 hdd_err("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05305967 hdd_ctx->config->enable_tcp_delack);
Jeff Johnson760350b2016-08-15 14:01:52 -07005968 hdd_err("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005969 hdd_ctx->config->tcpDelackThresholdHigh,
5970 hdd_ctx->config->tcpDelackThresholdLow);
Jeff Johnson760350b2016-08-15 14:01:52 -07005971 hdd_err("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05305972 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005973#endif
5974
Jeff Johnson760350b2016-08-15 14:01:52 -07005975 hdd_err("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05305976 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
5977
Jeff Johnson760350b2016-08-15 14:01:52 -07005978 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 -08005979
5980 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005981 hdd_err("%d: %llu, %llu, %llu, %llu, %s, %s, %s",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982 i, hdd_ctx->hdd_txrx_hist[i].total_rx,
5983 hdd_ctx->hdd_txrx_hist[i].interval_rx,
5984 hdd_ctx->hdd_txrx_hist[i].total_tx,
5985 hdd_ctx->hdd_txrx_hist[i].interval_tx,
Nirav Shahda008342016-05-17 18:50:40 +05305986 convert_level_to_string(
5987 hdd_ctx->hdd_txrx_hist[i].next_vote_level),
5988 convert_level_to_string(
5989 hdd_ctx->hdd_txrx_hist[i].next_rx_level),
5990 convert_level_to_string(
5991 hdd_ctx->hdd_txrx_hist[i].next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005992 }
5993 return;
5994}
5995
5996/**
5997 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
5998 * @hdd_ctx: hdd context
5999 *
6000 * Return: none
6001 */
6002void wlan_hdd_clear_tx_rx_histogram(hdd_context_t *hdd_ctx)
6003{
6004 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306005 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6006 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007}
6008
6009/**
6010 * wlan_hdd_display_netif_queue_history() - display netif queue operation history
6011 * @pHddCtx: hdd context
6012 *
6013 * Return: none
6014 */
6015void wlan_hdd_display_netif_queue_history(hdd_context_t *hdd_ctx)
6016{
6017
6018 hdd_adapter_t *adapter = NULL;
6019 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306020 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006021 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306022 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006023
6024 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306025 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006026 adapter = adapter_node->pAdapter;
6027
Jeff Johnson760350b2016-08-15 14:01:52 -07006028 hdd_err("\nNetif queue operation statistics:");
6029 hdd_err("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306030 adapter->sessionId, adapter->device_mode);
Jeff Johnson760350b2016-08-15 14:01:52 -07006031 hdd_err("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306032 curr_time = qdf_system_ticks();
6033 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306034 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306035 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306036 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306037 unpause = adapter->total_unpause_time;
6038 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306039 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306040 pause = adapter->total_pause_time;
6041 }
Jeff Johnson760350b2016-08-15 14:01:52 -07006042 hdd_err("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306043 qdf_system_ticks_to_msecs(total),
6044 qdf_system_ticks_to_msecs(pause),
6045 qdf_system_ticks_to_msecs(unpause));
Jeff Johnson760350b2016-08-15 14:01:52 -07006046 hdd_err("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006047
Nirav Shahda008342016-05-17 18:50:40 +05306048 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6049 qdf_time_t pause_delta = 0;
6050
6051 if (adapter->pause_map & (1 << i))
6052 pause_delta = delta;
6053
Jeff Johnson760350b2016-08-15 14:01:52 -07006054 hdd_err("%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006055 hdd_reason_type_to_string(i),
6056 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306057 adapter->queue_oper_stats[i].unpause_count,
6058 qdf_system_ticks_to_msecs(
6059 adapter->queue_oper_stats[i].total_pause_time +
6060 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006061 }
6062
Jeff Johnson760350b2016-08-15 14:01:52 -07006063 hdd_err("\nNetif queue operation history:");
6064 hdd_err("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306065 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6066
Jeff Johnson760350b2016-08-15 14:01:52 -07006067 hdd_err("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006068
6069 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006070 hdd_err("%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306071 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006072 adapter->queue_oper_history[i].time),
6073 hdd_action_type_to_string(
6074 adapter->queue_oper_history[i].netif_action),
6075 hdd_reason_type_to_string(
6076 adapter->queue_oper_history[i].netif_reason),
6077 adapter->queue_oper_history[i].pause_map);
6078 }
6079
6080 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6081 adapter_node = next;
6082 }
6083
6084
6085}
6086
6087/**
6088 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6089 * @hdd_ctx: hdd context
6090 *
6091 * Return: none
6092 */
6093void wlan_hdd_clear_netif_queue_history(hdd_context_t *hdd_ctx)
6094{
6095 hdd_adapter_t *adapter = NULL;
6096 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306097 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098
6099 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306100 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006101 adapter = adapter_node->pAdapter;
6102
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306103 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006104 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306105 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306107 adapter->history_index = 0;
6108 adapter->start_time = adapter->last_time = qdf_system_ticks();
6109 adapter->total_pause_time = 0;
6110 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6112 adapter_node = next;
6113 }
6114}
6115
6116/**
6117 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6118 * @halHandle: Hal handle
6119 * @pContext: Pointer to the context
6120 * @sessionId: Session ID
6121 * @scanId: Scan ID
6122 * @status: Status
6123 *
6124 * This is the callback to be executed when 11d scan is completed to flush out
6125 * the scan results
6126 *
6127 * 11d scan is done during driver load and is a passive scan on all
6128 * channels supported by the device, 11d scans may find some APs on
6129 * frequencies which are forbidden to be used in the regulatory domain
6130 * the device is operating in. If these APs are notified to the supplicant
6131 * it may try to connect to these APs, thus flush out all the scan results
6132 * which are present in SME after 11d scan is done.
6133 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306134 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006135 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306136static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006137 uint8_t sessionId, uint32_t scanId,
6138 eCsrScanStatus status)
6139{
6140 ENTER();
6141
6142 sme_scan_flush_result(halHandle);
6143
6144 EXIT();
6145
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306146 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006147}
6148
6149#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6150/**
6151 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6152 * @hdd_ctx: hdd global context
6153 *
6154 * Return: none
6155 */
6156static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6157{
6158 uint8_t i;
6159
6160 mutex_init(&hdd_ctx->op_ctx.op_lock);
6161 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6162 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6163 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6164 }
6165}
6166#else
6167static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6168{
6169}
6170#endif
6171
Yingying Tang95409972016-10-20 15:16:15 +08006172#ifdef WLAN_FEATURE_WOW_PULSE
6173/**
6174 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
6175 * @phddctx: hdd_context_t structure pointer
6176 * @enable: enable or disable this behaviour
6177 *
6178 * Return: int
6179 */
6180static int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6181{
6182 struct hdd_config *pcfg_ini = phddctx->config;
6183 struct wow_pulse_mode wow_pulse_set_info;
6184 QDF_STATUS status;
6185
6186 hdd_notice("wow pulse enable flag is %d", enable);
6187
6188 if (false == phddctx->config->wow_pulse_support)
6189 return 0;
6190
6191 /* prepare the request to send to SME */
6192 if (enable == true) {
6193 wow_pulse_set_info.wow_pulse_enable = true;
6194 wow_pulse_set_info.wow_pulse_pin =
6195 pcfg_ini->wow_pulse_pin;
6196 wow_pulse_set_info.wow_pulse_interval_low =
6197 pcfg_ini->wow_pulse_interval_low;
6198 wow_pulse_set_info.wow_pulse_interval_high =
6199 pcfg_ini->wow_pulse_interval_high;
6200 } else {
6201 wow_pulse_set_info.wow_pulse_enable = false;
6202 wow_pulse_set_info.wow_pulse_pin = 0;
6203 wow_pulse_set_info.wow_pulse_interval_low = 0;
6204 wow_pulse_set_info.wow_pulse_interval_high = 0;
6205 }
6206 hdd_notice("enable %d pin %d low %d high %d",
6207 wow_pulse_set_info.wow_pulse_enable,
6208 wow_pulse_set_info.wow_pulse_pin,
6209 wow_pulse_set_info.wow_pulse_interval_low,
6210 wow_pulse_set_info.wow_pulse_interval_high);
6211
6212 status = sme_set_wow_pulse(&wow_pulse_set_info);
6213 if (QDF_STATUS_E_FAILURE == status) {
6214 hdd_notice("sme_set_wow_pulse failure!");
6215 return -EIO;
6216 }
6217 hdd_notice("sme_set_wow_pulse success!");
6218 return 0;
6219}
6220#else
6221static inline int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6222{
6223 return 0;
6224}
6225#endif
6226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227#ifdef WLAN_FEATURE_FASTPATH
6228/**
6229 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6230 * @hdd_cfg: hdd config
6231 * @context: lower layer context
6232 *
6233 * Return: none
6234 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306235void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236 void *context)
6237{
6238 if (hdd_cfg->fastpath_enable)
6239 hif_enable_fastpath(context);
6240}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241#endif
6242
Yuanyuan Liu13738502016-04-06 17:41:37 -07006243#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006244/**
6245 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006246 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247 * @level: thermal level
6248 *
6249 * Change IPA data path to SW path when the thermal throttle level greater
6250 * than 0, and restore the original data path when throttle level is 0
6251 *
6252 * Return: none
6253 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006254static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255{
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006256 hdd_context_t *hdd_ctx = context;
6257
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006258 /* Change IPA to SW path when throttle level greater than 0 */
6259 if (level > THROTTLE_LEVEL_0)
6260 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6261 else
6262 /* restore original concurrency mode */
6263 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6264}
6265
6266/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306267 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6268 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306269 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006270 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306271 * Get a safe channel to restart SAP. PCL already takes into account the
6272 * unsafe channels. So, the PCL is validated with the ACS range to provide
6273 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006274 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306275 * Return: Channel number to restart SAP in case of success. In case of any
6276 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306278static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
6279 hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306281 struct sir_pcl_list pcl;
6282 QDF_STATUS status;
6283 uint32_t i, j;
6284 tHalHandle *hal_handle;
6285 hdd_context_t *hdd_ctx;
6286 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006287
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306288 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6289 if (!hdd_ctx) {
6290 hdd_err("invalid HDD context");
6291 return INVALID_CHANNEL_ID;
6292 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006293
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306294 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6295 if (!hal_handle) {
6296 hdd_err("invalid HAL handle");
6297 return INVALID_CHANNEL_ID;
6298 }
6299
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306300 status = cds_get_pcl_for_existing_conn(CDS_SAP_MODE,
6301 pcl.pcl_list, &pcl.pcl_len,
6302 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list));
6303 if (QDF_IS_STATUS_ERROR(status)) {
6304 hdd_err("Get PCL failed");
6305 return INVALID_CHANNEL_ID;
6306 }
6307
6308 if (!pcl.pcl_len) {
6309 hdd_alert("pcl length is zero. this is not expected");
6310 return INVALID_CHANNEL_ID;
6311 }
6312
6313 hdd_info("start:%d end:%d",
6314 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
6315 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
6316
6317 /* PCL already takes unsafe channel into account */
6318 for (i = 0; i < pcl.pcl_len; i++) {
6319 hdd_info("chan[%d]:%d", i, pcl.pcl_list[i]);
6320 if ((pcl.pcl_list[i] >=
6321 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6322 (pcl.pcl_list[i] <=
6323 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
6324 hdd_info("found PCL safe chan:%d", pcl.pcl_list[i]);
6325 return pcl.pcl_list[i];
6326 }
6327 }
6328
6329 hdd_info("no safe channel from PCL found in ACS range");
6330
6331 /* Try for safe channel from all valid channel */
6332 pcl.pcl_len = MAX_NUM_CHAN;
6333 status = sme_get_cfg_valid_channels(hal_handle, pcl.pcl_list,
6334 &pcl.pcl_len);
6335 if (QDF_IS_STATUS_ERROR(status)) {
6336 hdd_err("error in getting valid channel list");
6337 return INVALID_CHANNEL_ID;
6338 }
6339
6340 for (i = 0; i < pcl.pcl_len; i++) {
6341 hdd_info("chan[%d]:%d", i, pcl.pcl_list[i]);
6342 found = false;
6343 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006344 if (pcl.pcl_list[i] ==
6345 hdd_ctx->unsafe_channel_list[j]) {
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306346 hdd_info("unsafe chan:%d", pcl.pcl_list[i]);
6347 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006348 break;
6349 }
6350 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306351
6352 if (found)
6353 continue;
6354
6355 if ((pcl.pcl_list[i] >=
6356 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6357 (pcl.pcl_list[i] <=
6358 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
6359 hdd_info("found safe chan:%d", pcl.pcl_list[i]);
6360 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006361 }
6362 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306363
6364 return INVALID_CHANNEL_ID;
6365}
6366
6367/**
6368 * hdd_restart_sap() - Restarts SAP on the given channel
6369 * @adapter: AP adapter
6370 * @channel: Channel
6371 *
6372 * Restarts the SAP interface by invoking the function which executes the
6373 * callback to perform channel switch using (E)CSA.
6374 *
6375 * Return: None
6376 */
Kapil Gupta8878ad92017-02-13 11:56:04 +05306377void hdd_restart_sap(hdd_adapter_t *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306378{
6379 hdd_ap_ctx_t *hdd_ap_ctx;
6380 tHalHandle *hal_handle;
6381
6382 if (!adapter) {
6383 hdd_err("invalid adapter");
6384 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006385 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306386
6387 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
6388
6389 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6390 if (!hal_handle) {
6391 hdd_err("invalid HAL handle");
6392 return;
6393 }
6394
6395 hdd_ap_ctx->sapConfig.channel = channel;
6396 hdd_ap_ctx->sapConfig.ch_params.ch_width =
6397 hdd_ap_ctx->sapConfig.ch_width_orig;
6398
6399 hdd_info("chan:%d width:%d",
6400 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
6401
Sandeep Puligilla1cc23f62016-04-27 16:52:49 -07006402 cds_set_channel_params(hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306403 hdd_ap_ctx->sapConfig.sec_ch,
6404 &hdd_ap_ctx->sapConfig.ch_params);
6405
6406 cds_change_sap_channel_with_csa(adapter, hdd_ap_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006407}
Kapil Gupta8878ad92017-02-13 11:56:04 +05306408
6409int hdd_update_acs_timer_reason(hdd_adapter_t *adapter, uint8_t reason)
6410{
6411 struct hdd_external_acs_timer_context *timer_context;
6412
6413 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
6414
6415 if (QDF_TIMER_STATE_RUNNING ==
6416 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
6417 ap.vendor_acs_timer)) {
6418 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
6419 }
6420 timer_context = (struct hdd_external_acs_timer_context *)
6421 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
6422 timer_context->reason = reason;
6423 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
6424 WLAN_VENDOR_ACS_WAIT_TIME);
6425 /* Update config to application */
6426 hdd_cfg80211_update_acs_config(adapter, reason);
6427 hdd_notice("Updated ACS config to nl with reason %d", reason);
6428
6429 return 0;
6430}
6431
Agrawal Ashish467dde42016-09-08 18:44:22 +05306432/**
6433 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
6434 * @hdd_ctx: hdd context pointer
6435 *
6436 * hdd_unsafe_channel_restart_sap check all unsafe channel list
6437 * and if ACS is enabled, driver will ask userspace to restart the
6438 * sap. User space on LTE coex indication restart driver.
6439 *
6440 * Return - none
6441 */
6442void hdd_unsafe_channel_restart_sap(hdd_context_t *hdd_ctxt)
6443{
6444 QDF_STATUS status;
6445 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
6446 hdd_adapter_t *adapter_temp;
6447 uint32_t i;
6448 bool found = false;
6449 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450
Agrawal Ashish467dde42016-09-08 18:44:22 +05306451 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
6452 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
6453 adapter_temp = adapter_node->pAdapter;
6454
6455 if (!adapter_temp) {
6456 hdd_err("adapter is NULL, moving to next one");
6457 goto next_adapater;
6458 }
6459
6460 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
6461 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
6462 hdd_info("skip device mode:%d acs:%d",
6463 adapter_temp->device_mode,
6464 adapter_temp->sessionCtx.ap.sapConfig.
6465 acs_cfg.acs_mode);
6466 goto next_adapater;
6467 }
6468
6469 found = false;
6470 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006471 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05306472 hdd_ctxt->unsafe_channel_list[i]) {
6473 found = true;
6474 hdd_info("operating ch:%d is unsafe",
6475 adapter_temp->sessionCtx.ap.operatingChannel);
6476 break;
6477 }
6478 }
6479
6480 if (!found) {
6481 hdd_info("ch:%d is safe. no need to change channel",
6482 adapter_temp->sessionCtx.ap.operatingChannel);
6483 goto next_adapater;
6484 }
6485
Kapil Gupta8878ad92017-02-13 11:56:04 +05306486 if (hdd_ctxt->config->vendor_acs_support &&
6487 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
6488 hdd_update_acs_timer_reason(adapter_temp,
6489 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
6490 goto next_adapater;
6491 } else
6492 restart_chan =
6493 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05306494 adapter_temp);
6495 if (!restart_chan) {
6496 hdd_alert("fail to restart SAP");
6497 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08006498 /*
6499 * SAP restart due to unsafe channel. While
6500 * restarting the SAP, make sure to clear
6501 * acs_channel, channel to reset to
6502 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05306503 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08006504 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05306505 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
6506 adapter_temp->sessionCtx.ap.sapConfig.channel =
6507 AUTO_CHANNEL_SELECT;
Agrawal Ashish467dde42016-09-08 18:44:22 +05306508 hdd_info("sending coex indication");
6509 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
6510 WLAN_SVC_LTE_COEX_IND, NULL, 0);
6511 hdd_restart_sap(adapter_temp, restart_chan);
6512 }
6513
6514next_adapater:
6515 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
6516 adapter_node = next;
6517 }
6518}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006519/**
6520 * hdd_ch_avoid_cb() - Avoid notified channels from FW handler
6521 * @adapter: HDD adapter pointer
6522 * @indParam: Channel avoid notification parameter
6523 *
6524 * Avoid channel notification from FW handler.
6525 * FW will send un-safe channel list to avoid over wrapping.
6526 * hostapd should not use notified channel
6527 *
6528 * Return: None
6529 */
Agrawal Ashish467dde42016-09-08 18:44:22 +05306530void hdd_ch_avoid_cb(void *hdd_context, void *indi_param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006531{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532 hdd_context_t *hdd_ctxt;
6533 tSirChAvoidIndType *ch_avoid_indi;
6534 uint8_t range_loop;
Amar Singhalb8d4f152016-02-10 10:21:43 -08006535 enum channel_enum channel_loop, start_channel_idx = INVALID_CHANNEL,
6536 end_channel_idx = INVALID_CHANNEL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006537 uint16_t start_channel;
6538 uint16_t end_channel;
6539 v_CONTEXT_t cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 tHddAvoidFreqList hdd_avoid_freq_list;
6541 uint32_t i;
6542
6543 /* Basic sanity */
6544 if (!hdd_context || !indi_param) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006545 hdd_err("Invalid arguments");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006546 return;
6547 }
6548
6549 hdd_ctxt = (hdd_context_t *) hdd_context;
6550 ch_avoid_indi = (tSirChAvoidIndType *) indi_param;
6551 cds_context = hdd_ctxt->pcds_context;
6552
6553 /* Make unsafe channel list */
Jeff Johnson34c88b72016-08-15 14:27:11 -07006554 hdd_notice("band count %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006555 ch_avoid_indi->avoid_range_count);
6556
6557 /* generate vendor specific event */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306558 qdf_mem_zero((void *)&hdd_avoid_freq_list, sizeof(tHddAvoidFreqList));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006559 for (i = 0; i < ch_avoid_indi->avoid_range_count; i++) {
6560 hdd_avoid_freq_list.avoidFreqRange[i].startFreq =
6561 ch_avoid_indi->avoid_freq_range[i].start_freq;
6562 hdd_avoid_freq_list.avoidFreqRange[i].endFreq =
6563 ch_avoid_indi->avoid_freq_range[i].end_freq;
6564 }
6565 hdd_avoid_freq_list.avoidFreqRangeCount =
6566 ch_avoid_indi->avoid_range_count;
6567
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568 /* clear existing unsafe channel cache */
6569 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306570 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006571 sizeof(hdd_ctxt->unsafe_channel_list));
6572
6573 for (range_loop = 0; range_loop < ch_avoid_indi->avoid_range_count;
6574 range_loop++) {
Amar Singhalb8d4f152016-02-10 10:21:43 -08006575 if (hdd_ctxt->unsafe_channel_count >= NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006576 hdd_warn("LTE Coex unsafe channel list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006577 break;
6578 }
6579
6580 start_channel = ieee80211_frequency_to_channel(
6581 ch_avoid_indi->avoid_freq_range[range_loop].start_freq);
6582 end_channel = ieee80211_frequency_to_channel(
6583 ch_avoid_indi->avoid_freq_range[range_loop].end_freq);
Jeff Johnson34c88b72016-08-15 14:27:11 -07006584 hdd_notice("start %d : %d, end %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006585 ch_avoid_indi->avoid_freq_range[range_loop].start_freq,
6586 start_channel,
6587 ch_avoid_indi->avoid_freq_range[range_loop].end_freq,
6588 end_channel);
6589
6590 /* do not process frequency bands that are not mapped to
6591 * predefined channels
6592 */
6593 if (start_channel == 0 || end_channel == 0)
6594 continue;
6595
Amar Singhalb8d4f152016-02-10 10:21:43 -08006596 for (channel_loop = CHAN_ENUM_1; channel_loop <=
6597 CHAN_ENUM_184; channel_loop++) {
Amar Singhal7a1726a2015-10-14 16:28:11 -07006598 if (CDS_CHANNEL_FREQ(channel_loop) >=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599 ch_avoid_indi->avoid_freq_range[
6600 range_loop].start_freq) {
6601 start_channel_idx = channel_loop;
6602 break;
6603 }
6604 }
Amar Singhalb8d4f152016-02-10 10:21:43 -08006605 for (channel_loop = CHAN_ENUM_1; channel_loop <=
6606 CHAN_ENUM_184; channel_loop++) {
Amar Singhal7a1726a2015-10-14 16:28:11 -07006607 if (CDS_CHANNEL_FREQ(channel_loop) >=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006608 ch_avoid_indi->avoid_freq_range[
6609 range_loop].end_freq) {
6610 end_channel_idx = channel_loop;
Amar Singhal7a1726a2015-10-14 16:28:11 -07006611 if (CDS_CHANNEL_FREQ(channel_loop) >
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006612 ch_avoid_indi->avoid_freq_range[
6613 range_loop].end_freq)
6614 end_channel_idx--;
6615 break;
6616 }
6617 }
6618
Amar Singhalb8d4f152016-02-10 10:21:43 -08006619 if (start_channel_idx == INVALID_CHANNEL ||
6620 end_channel_idx == INVALID_CHANNEL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006621 continue;
6622
6623 for (channel_loop = start_channel_idx; channel_loop <=
6624 end_channel_idx; channel_loop++) {
6625 hdd_ctxt->unsafe_channel_list[
Amar Singhal7a1726a2015-10-14 16:28:11 -07006626 hdd_ctxt->unsafe_channel_count++] =
Krunal Soni15f0db12016-10-11 18:53:37 -07006627 CDS_CHANNEL_NUM(channel_loop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006628 if (hdd_ctxt->unsafe_channel_count >=
Amar Singhalb8d4f152016-02-10 10:21:43 -08006629 NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006630 hdd_warn("LTECoex unsafe ch list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006631 break;
6632 }
6633 }
6634 }
6635
Jeff Johnson34c88b72016-08-15 14:27:11 -07006636 hdd_notice("number of unsafe channels is %d ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637 hdd_ctxt->unsafe_channel_count);
6638
Yuanyuan Liu13738502016-04-06 17:41:37 -07006639 if (pld_set_wlan_unsafe_channel(hdd_ctxt->parent_dev,
6640 hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006641 hdd_ctxt->unsafe_channel_count)) {
6642 hdd_err("Failed to set unsafe channel");
6643
6644 /* clear existing unsafe channel cache */
6645 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306646 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006647 sizeof(hdd_ctxt->unsafe_channel_list));
6648
6649 return;
6650 }
6651
6652 for (channel_loop = 0;
6653 channel_loop < hdd_ctxt->unsafe_channel_count; channel_loop++) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006654 hdd_notice("channel %d is not safe ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655 hdd_ctxt->unsafe_channel_list[channel_loop]);
6656 }
6657
Kondabattini, Ganeshcf7b60f2016-08-10 16:31:55 +05306658 /*
6659 * first update the unsafe channel list to the platform driver and
6660 * send the avoid freq event to the application
6661 */
6662 wlan_hdd_send_avoid_freq_event(hdd_ctxt, &hdd_avoid_freq_list);
6663
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306664 if (!hdd_ctxt->unsafe_channel_count) {
6665 hdd_info("no unsafe channels - not restarting SAP");
6666 return;
6667 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05306668 hdd_unsafe_channel_restart_sap(hdd_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006669 return;
6670}
6671
6672/**
6673 * hdd_init_channel_avoidance() - Initialize channel avoidance
6674 * @hdd_ctx: HDD global context
6675 *
6676 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07006677 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006678 * down to the lower layers. Then subscribe to subsequent channel
6679 * avoidance events.
6680 *
6681 * Return: None
6682 */
6683static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
6684{
6685 uint16_t unsafe_channel_count;
6686 int index;
6687
Yuanyuan Liu13738502016-04-06 17:41:37 -07006688 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
6689 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006690 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08006691 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692
Jeff Johnson34c88b72016-08-15 14:27:11 -07006693 hdd_notice("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006694 hdd_ctx->unsafe_channel_count);
6695
Anurag Chouhan6d760662016-02-20 16:05:43 +05306696 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08006697 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006698
6699 for (index = 0; index < unsafe_channel_count; index++) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006700 hdd_notice("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006701 hdd_ctx->unsafe_channel_list[index]);
6702
6703 }
6704
6705 /* Plug in avoid channel notification callback */
6706 sme_add_ch_avoid_callback(hdd_ctx->hHal, hdd_ch_avoid_cb);
6707}
6708#else
6709static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
6710{
6711}
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006712static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713{
6714}
Yuanyuan Liu13738502016-04-06 17:41:37 -07006715#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716
6717/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08006718 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
6719 * user space
6720 * @frame_ind: Management frame data to be informed.
6721 *
6722 * This function is used to indicate management frame to
6723 * user space
6724 *
6725 * Return: None
6726 *
6727 */
6728void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
6729{
6730 hdd_context_t *hdd_ctx = NULL;
6731 hdd_adapter_t *adapter = NULL;
6732 void *cds_context = NULL;
6733 int i;
6734
6735 /* Get the global VOSS context.*/
6736 cds_context = cds_get_global_context();
6737 if (!cds_context) {
6738 hdd_err("Global CDS context is Null");
6739 return;
6740 }
6741 /* Get the HDD context.*/
6742 hdd_ctx = (hdd_context_t *)cds_get_context(QDF_MODULE_ID_HDD);
6743
6744 if (0 != wlan_hdd_validate_context(hdd_ctx))
6745 return;
6746
6747 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
6748 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
6749 adapter =
6750 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
6751 if (adapter)
6752 break;
6753 }
6754 } else {
6755 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
6756 frame_ind->sessionId);
6757 }
6758
6759 if ((NULL != adapter) &&
6760 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
6761 __hdd_indicate_mgmt_frame(adapter,
6762 frame_ind->frame_len,
6763 frame_ind->frameBuf,
6764 frame_ind->frameType,
6765 frame_ind->rxChan,
6766 frame_ind->rxRssi);
6767 return;
6768}
6769
Kapil Gupta8878ad92017-02-13 11:56:04 +05306770static void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
6771 hdd_context_t *hdd_ctx)
6772{
6773 uint8_t restart_chan = 0;
6774
6775 restart_chan =
6776 hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
6777 if (!restart_chan) {
6778 hdd_alert("fail to restart SAP");
6779 } else {
6780 /* SAP restart due to unsafe channel. While restarting
6781 * the SAP, make sure to clear acs_channel, channel to
6782 * reset to 0. Otherwise these settings will override
6783 * the ACS while restart.
6784 */
6785 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
6786 adapter->sessionCtx.ap.sapConfig.channel =
6787 AUTO_CHANNEL_SELECT;
6788 hdd_info("sending coex indication");
6789 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6790 WLAN_SVC_LTE_COEX_IND, NULL, 0);
6791 hdd_restart_sap(adapter, restart_chan);
6792 }
6793}
6794
6795void hdd_acs_response_timeout_handler(void *context)
6796{
6797 struct hdd_external_acs_timer_context *timer_context =
6798 (struct hdd_external_acs_timer_context *)context;
6799 hdd_adapter_t *adapter;
6800 hdd_context_t *hdd_ctx;
6801 uint8_t reason;
6802
6803 ENTER();
6804 if (!timer_context) {
6805 hdd_err("invlaid timer context");
6806 return;
6807 }
6808 adapter = timer_context->adapter;
6809 reason = timer_context->reason;
6810
6811
6812 if ((!adapter) ||
6813 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
6814 hdd_err("invalid adapter or adapter has invalid magic");
6815 return;
6816 }
6817 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6818 if (wlan_hdd_validate_context(hdd_ctx))
6819 return;
6820
6821 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
6822 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
6823 else
6824 return;
6825
6826 hdd_err("ACS timeout happened for %s reason %d",
6827 adapter->dev->name, reason);
6828 switch (reason) {
6829 /* SAP init case */
6830 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
6831 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
6832 false);
6833 wlan_hdd_cfg80211_start_acs(adapter);
6834 break;
6835 /* DFS detected on current channel */
6836 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
6837 wlan_sap_update_next_channel(
6838 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
6839 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
6840 adapter->sessionId);
6841 break;
6842 /* LTE coex event on current channel */
6843 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
6844 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
6845 break;
6846 default:
6847 hdd_info("invalid reason for timer invoke");
6848
6849 }
6850}
6851
Rajeev Kumard004abc2016-02-17 12:09:56 -08006852/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006853 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
6854 * @hdd_ctx: HDD context
6855 *
6856 * Disables all the dual mac features like DBS, Agile DFS etc.
6857 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306858 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006859 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306860static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006861{
6862 struct sir_dual_mac_config cfg;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306863 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864
6865 if (!hdd_ctx) {
6866 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306867 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006868 }
6869
6870 cfg.scan_config = 0;
6871 cfg.fw_mode_config = 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +05306872 cfg.set_dual_mac_cb = cds_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006873
6874 hdd_debug("Disabling all dual mac features...");
6875
6876 status = sme_soc_set_dual_mac_config(hdd_ctx->hHal, cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306877 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006878 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
6879 return status;
6880 }
6881
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306882 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006883}
6884
6885/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006886 * hdd_override_ini_config - Override INI config
6887 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006889 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006890 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006891 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006892 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006893static void hdd_override_ini_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006894{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006895
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006896 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
6897 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
6898 hdd_notice("Module enable_dfs_chan_scan set to %d",
6899 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006900 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006901 if (0 == enable_11d || 1 == enable_11d) {
6902 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
6903 hdd_notice("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006904 }
Leo Chang11545d62016-10-17 14:53:50 -07006905
6906 if (!hdd_ipa_is_present(hdd_ctx))
6907 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006908}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006909
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006910/**
6911 * hdd_set_trace_level_for_each - Set trace level for each INI config
6912 * @hdd_ctx - HDD context
6913 *
6914 * Set trace level for each module based on INI config.
6915 *
6916 * Return: None
6917 */
6918static void hdd_set_trace_level_for_each(hdd_context_t *hdd_ctx)
6919{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306920 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
6921 hdd_ctx->config->qdf_trace_enable_wdi);
6922 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
6923 hdd_ctx->config->qdf_trace_enable_hdd);
6924 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
6925 hdd_ctx->config->qdf_trace_enable_sme);
6926 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
6927 hdd_ctx->config->qdf_trace_enable_pe);
6928 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
6929 hdd_ctx->config->qdf_trace_enable_wma);
6930 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
6931 hdd_ctx->config->qdf_trace_enable_sys);
6932 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
6933 hdd_ctx->config->qdf_trace_enable_qdf);
6934 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
6935 hdd_ctx->config->qdf_trace_enable_sap);
6936 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
6937 hdd_ctx->config->qdf_trace_enable_hdd_sap);
6938 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
6939 hdd_ctx->config->qdf_trace_enable_bmi);
6940 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
6941 hdd_ctx->config->qdf_trace_enable_cfg);
6942 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
6943 hdd_ctx->config->qdf_trace_enable_epping);
6944 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
6945 hdd_ctx->config->qdf_trace_enable_qdf_devices);
6946 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Bhargav Shah480a90f2015-06-24 15:10:14 +05306947 hdd_ctx->config->cfd_trace_enable_txrx);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306948 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
6949 hdd_ctx->config->qdf_trace_enable_htc);
6950 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
6951 hdd_ctx->config->qdf_trace_enable_hif);
6952 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
6953 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
6954 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
6955 hdd_ctx->config->qdf_trace_enable_hdd_data);
Bhargav Shah480a90f2015-06-24 15:10:14 +05306956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006957 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006958}
6959
6960/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006961 * hdd_context_init() - Initialize HDD context
6962 * @hdd_ctx: HDD context.
6963 *
6964 * Initialize HDD context along with all the feature specific contexts.
6965 *
6966 * return: 0 on success and errno on failure.
6967 */
6968static int hdd_context_init(hdd_context_t *hdd_ctx)
6969{
6970 int ret;
6971
6972 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
6973 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
6974
6975 hdd_init_ll_stats_ctx();
6976
6977 init_completion(&hdd_ctx->mc_sus_event_var);
6978 init_completion(&hdd_ctx->ready_to_suspend);
6979
6980 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306981 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006982 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306983
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006984 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
6985
6986 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
6987
6988 ret = hdd_scan_context_init(hdd_ctx);
6989 if (ret)
6990 goto list_destroy;
6991
Nitesh Shahd1266d72017-01-25 22:07:07 +05306992 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006993
6994 hdd_rx_wake_lock_create(hdd_ctx);
6995
6996 ret = hdd_sap_context_init(hdd_ctx);
6997 if (ret)
6998 goto scan_destroy;
6999
7000 ret = hdd_roc_context_init(hdd_ctx);
7001 if (ret)
7002 goto sap_destroy;
7003
7004 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7005
7006 hdd_init_offloaded_packets_ctx(hdd_ctx);
7007
7008 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7009 hdd_ctx->config);
7010 if (ret)
7011 goto roc_destroy;
7012
7013 return 0;
7014
7015roc_destroy:
7016 hdd_roc_context_destroy(hdd_ctx);
7017
7018sap_destroy:
7019 hdd_sap_context_destroy(hdd_ctx);
7020
7021scan_destroy:
7022 hdd_scan_context_destroy(hdd_ctx);
7023 hdd_rx_wake_lock_destroy(hdd_ctx);
7024 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007025list_destroy:
7026 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007027
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007028 return ret;
7029}
7030
7031/**
7032 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307033 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007034 *
7035 * Allocate and initialize HDD context. HDD context is allocated as part of
7036 * wiphy allocation and then context is initialized.
7037 *
7038 * Return: HDD context on success and ERR_PTR on failure
7039 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007040static hdd_context_t *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007041{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307042 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007043 int ret = 0;
7044 hdd_context_t *hdd_ctx;
7045 v_CONTEXT_t p_cds_context;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05307046 int qdf_print_idx = -1;
7047
7048 struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
7049 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
7050 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
7051 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
7052 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
7053 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
7054 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
7055 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
7056 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
7057 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
7058 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
7059 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
7060 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
7061 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
7062 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
7063 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
7064 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
7065 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
7066 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
7067 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
7068 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiyaf928edf2017-02-06 14:43:24 +05307069 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
7070 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
7071 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
7072 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
7073 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
7074 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
Mukul Sharma4d7d6b02017-02-13 20:45:22 +05307075 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh9679dbf2017-02-15 11:35:41 +05307076 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
Tushnim Bhattacharyya6796d8d2017-03-17 11:06:03 -07007077 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
7078 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05307079 };
7080
7081 status = qdf_print_setup();
7082 if (status != QDF_STATUS_SUCCESS) {
7083 pr_err("QDF print control object setup failed\n");
7084 ret = -EINVAL;
7085 goto err_out;
7086 }
7087 /* Register the module here with QDF */
7088 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL,
7089 "MCL_WLAN");
7090
7091 /* if qdf_print_idx is negative */
7092 if (qdf_print_idx < 0) {
7093 pr_err("QDF print control can not be registered %d\n",
7094 qdf_print_idx);
7095 ret = -EINVAL;
7096 goto err_out;
7097 }
7098
7099 /* Store the qdf_pidx information into qdf module */
7100 qdf_set_pidx(qdf_print_idx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007101
7102 ENTER();
7103
7104 p_cds_context = cds_get_global_context();
7105 if (p_cds_context == NULL) {
7106 hdd_alert("Failed to get CDS global context");
7107 ret = -EINVAL;
7108 goto err_out;
7109 }
7110
7111 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t));
7112
7113 if (hdd_ctx == NULL) {
7114 ret = -ENOMEM;
7115 goto err_out;
7116 }
7117
7118 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007119 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307120 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007121
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307122 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007123 if (hdd_ctx->config == NULL) {
7124 hdd_alert("Failed to alloc memory for HDD config!");
7125 ret = -ENOMEM;
7126 goto err_free_hdd_context;
7127 }
7128
7129 /* Read and parse the qcom_cfg.ini file */
7130 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307131 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307132 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007133 WLAN_INI_FILE);
7134 ret = -EINVAL;
7135 goto err_free_config;
7136 }
7137
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007138 hdd_notice("Setting configuredMcastBcastFilter: %d",
7139 hdd_ctx->config->mcastBcastFilterSetting);
7140
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307141 if (hdd_ctx->config->fhostNSOffload)
7142 hdd_ctx->ns_offload_enable = true;
7143
Abhishek Singh5ea86532016-04-27 14:10:53 +05307144 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7145
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007146 hdd_override_ini_config(hdd_ctx);
7147
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007148 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007149
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007150 ret = hdd_context_init(hdd_ctx);
7151
7152 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007153 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007154
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007155
Yuanyuan Liu7a97b8f2017-01-27 10:42:52 -08007156 pld_set_fw_log_mode(hdd_ctx->parent_dev,
7157 hdd_ctx->config->enable_fw_log);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007158
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007159
7160 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307161 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007162
Anurag Chouhan6d760662016-02-20 16:05:43 +05307163 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007164 goto skip_multicast_logging;
7165
7166 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7167
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007168 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7169 if (ret)
7170 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307171
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007172 ret = hdd_logging_sock_activate_svc(hdd_ctx);
7173 if (ret)
Nirav Shahed34b212016-04-25 10:59:16 +05307174 goto err_free_histogram;
7175
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007176skip_multicast_logging:
7177 hdd_set_trace_level_for_each(hdd_ctx);
7178
7179 return hdd_ctx;
7180
Nirav Shahed34b212016-04-25 10:59:16 +05307181err_free_histogram:
7182 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7183
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007184err_deinit_hdd_context:
7185 hdd_context_deinit(hdd_ctx);
7186
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007187err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307188 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007189
7190err_free_hdd_context:
7191 wiphy_free(hdd_ctx->wiphy);
7192
7193err_out:
7194 return ERR_PTR(ret);
7195}
7196
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007197#ifdef WLAN_OPEN_P2P_INTERFACE
7198/**
7199 * hdd_open_p2p_interface - Open P2P interface
7200 * @hdd_ctx: HDD context
7201 * @rtnl_held: True if RTNL lock held
7202 *
7203 * Open P2P interface during probe. This function called to open the P2P
7204 * interface at probe along with STA interface.
7205 *
7206 * Return: 0 on success and errno on failure
7207 */
7208static int hdd_open_p2p_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7209{
7210 hdd_adapter_t *adapter;
7211 uint8_t *p2p_dev_addr;
7212
7213 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7214 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307215 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007216 hdd_ctx->config->intfMacAddr[0].bytes,
7217 sizeof(tSirMacAddr));
7218
7219 /*
7220 * Generate the P2P Device Address. This consists of
7221 * the device's primary MAC address with the locally
7222 * administered bit set.
7223 */
7224 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7225 } else {
7226 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7227 if (p2p_dev_addr == NULL) {
7228 hdd_alert("Failed to allocate mac_address for p2p_device");
7229 return -ENOSPC;
7230 }
7231
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307232 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307233 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007234 }
7235
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007236 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007237 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007238 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007239
7240 if (NULL == adapter) {
7241 hdd_alert("Failed to do hdd_open_adapter for P2P Device Interface");
7242 return -ENOSPC;
7243 }
7244
7245 return 0;
7246}
7247#else
Manishekar Chandrasekaranc81ba242016-07-18 17:44:44 +05307248static inline int hdd_open_p2p_interface(hdd_context_t *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007249 bool rtnl_held)
7250{
7251 return 0;
7252}
7253#endif
7254
Jeff Johnson957bc272017-02-02 08:54:48 -08007255static int hdd_open_ocb_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7256{
7257 hdd_adapter_t *adapter;
7258 int ret = 0;
7259
7260 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7261 wlan_hdd_get_intf_addr(hdd_ctx),
7262 NET_NAME_UNKNOWN, rtnl_held);
7263 if (adapter == NULL) {
7264 hdd_err("Failed to open 802.11p interface");
7265 ret = -ENOSPC;
7266 }
7267
7268 return ret;
7269}
7270
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007271/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307272 * hdd_start_station_adapter()- Start the Station Adapter
7273 * @adapter: HDD adapter
7274 *
7275 * This function initializes the adapter for the station mode.
7276 *
7277 * Return: 0 on success or errno on failure.
7278 */
7279int hdd_start_station_adapter(hdd_adapter_t *adapter)
7280{
7281 QDF_STATUS status;
7282
7283 ENTER_DEV(adapter->dev);
7284
7285 status = hdd_init_station_mode(adapter);
7286
7287 if (QDF_STATUS_SUCCESS != status) {
7288 hdd_err("Error Initializing station mode: %d", status);
7289 return qdf_status_to_os_return(status);
7290 }
7291
Arun Khandavallifae92942016-08-01 13:31:08 +05307292 hdd_register_tx_flow_control(adapter,
7293 hdd_tx_resume_timer_expired_handler,
7294 hdd_tx_resume_cb);
7295
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307296 EXIT();
7297 return 0;
7298}
7299
7300/**
7301 * hdd_start_ap_adapter()- Start AP Adapter
7302 * @adapter: HDD adapter
7303 *
7304 * This function initializes the adapter for the AP mode.
7305 *
7306 * Return: 0 on success errno on failure.
7307 */
7308int hdd_start_ap_adapter(hdd_adapter_t *adapter)
7309{
7310 QDF_STATUS status;
7311
7312 ENTER();
7313
Arun Khandavallicc544b32017-01-30 19:52:16 +05307314 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307315
7316 if (QDF_STATUS_SUCCESS != status) {
7317 hdd_err("Error Initializing the AP mode: %d", status);
7318 return qdf_status_to_os_return(status);
7319 }
7320
Arun Khandavallifae92942016-08-01 13:31:08 +05307321 hdd_register_tx_flow_control(adapter,
7322 hdd_softap_tx_resume_timer_expired_handler,
7323 hdd_softap_tx_resume_cb);
7324
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307325 EXIT();
7326 return 0;
7327}
7328
7329/**
7330 * hdd_start_ftm_adapter()- Start FTM adapter
7331 * @adapter: HDD adapter
7332 *
7333 * This function initializes the adapter for the FTM mode.
7334 *
7335 * Return: 0 on success or errno on failure.
7336 */
7337int hdd_start_ftm_adapter(hdd_adapter_t *adapter)
7338{
7339 QDF_STATUS qdf_status;
7340
7341 ENTER_DEV(adapter->dev);
7342
7343 qdf_status = hdd_init_tx_rx(adapter);
7344
7345 if (QDF_STATUS_SUCCESS != qdf_status) {
7346 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7347 return qdf_status_to_os_return(qdf_status);
7348 }
7349
7350 return 0;
7351 EXIT();
7352}
7353
7354/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007355 * hdd_open_interfaces - Open all required interfaces
7356 * hdd_ctx: HDD context
7357 * rtnl_held: True if RTNL lock is held
7358 *
7359 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7360 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007361 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007362 */
Jeff Johnson957bc272017-02-02 08:54:48 -08007363static int hdd_open_interfaces(hdd_context_t *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007364{
Jeff Johnson957bc272017-02-02 08:54:48 -08007365 hdd_adapter_t *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007366 int ret;
7367
Jeff Johnson957bc272017-02-02 08:54:48 -08007368 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05307369 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08007370 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007371
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007372 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007373 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08007374 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007375
7376 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08007377 return -ENOSPC;
7378
Deepak Dhamdherea2785822016-11-17 01:17:45 -08007379 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
7380 adapter->fast_roaming_allowed = true;
7381
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007382 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
7383 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08007384 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007385
7386 /* Open 802.11p Interface */
7387 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08007388 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
7389 if (ret)
7390 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007391 }
7392
Jeff Johnson957bc272017-02-02 08:54:48 -08007393 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007394
Jeff Johnson957bc272017-02-02 08:54:48 -08007395err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007396 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08007397 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007398}
7399
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007400/**
7401 * hdd_update_country_code - Update country code
7402 * @hdd_ctx: HDD context
7403 * @adapter: Primary adapter context
7404 *
7405 * Update country code based on module parameter country_code at SME and wait
7406 * for the settings to take effect.
7407 *
7408 * Return: 0 on success and errno on failure
7409 */
7410static int hdd_update_country_code(hdd_context_t *hdd_ctx,
7411 hdd_adapter_t *adapter)
7412{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307413 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007414 int ret = 0;
7415 unsigned long rc;
7416
7417 if (country_code == NULL)
7418 return 0;
7419
7420 INIT_COMPLETION(adapter->change_country_code);
7421
7422 status = sme_change_country_code(hdd_ctx->hHal,
7423 wlan_hdd_change_country_code_callback,
7424 country_code, adapter,
7425 hdd_ctx->pcds_context, eSIR_TRUE,
7426 eSIR_TRUE);
7427
7428
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307429 if (!QDF_IS_STATUS_SUCCESS(status)) {
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007430 hdd_err("SME Change Country code from module param fail ret=%d",
7431 ret);
7432 return -EINVAL;
7433 }
7434
7435 rc = wait_for_completion_timeout(&adapter->change_country_code,
7436 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
7437 if (!rc) {
7438 hdd_err("SME while setting country code timed out");
7439 ret = -ETIMEDOUT;
7440 }
7441
7442 return ret;
7443}
7444
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307445#ifdef QCA_LL_TX_FLOW_CONTROL_V2
7446/**
7447 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
7448 * @cds_cfg: CDS Configuration
7449 * @hdd_ctx: Pointer to hdd context
7450 *
7451 * Return: none
7452 */
7453static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7454 *cds_cfg,
7455 hdd_context_t *hdd_ctx)
7456{
7457 cds_cfg->tx_flow_stop_queue_th =
7458 hdd_ctx->config->TxFlowStopQueueThreshold;
7459 cds_cfg->tx_flow_start_queue_offset =
7460 hdd_ctx->config->TxFlowStartQueueOffset;
7461}
7462#else
7463static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7464 *cds_cfg,
7465 hdd_context_t *hdd_ctx)
7466{
7467}
7468#endif
7469
7470#ifdef FEATURE_WLAN_RA_FILTERING
7471/**
7472 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
7473 * @cds_cfg: CDS Configuration
7474 * @hdd_ctx: Pointer to hdd context
7475 *
7476 * Return: none
7477 */
Anand Kumar3b92a912016-12-05 12:01:26 +05307478static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307479 hdd_context_t *hdd_ctx)
7480{
7481 cds_cfg->ra_ratelimit_interval =
7482 hdd_ctx->config->RArateLimitInterval;
7483 cds_cfg->is_ra_ratelimit_enabled =
7484 hdd_ctx->config->IsRArateLimitEnabled;
7485}
7486#else
Anand Kumar3b92a912016-12-05 12:01:26 +05307487static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307488 hdd_context_t *hdd_ctx)
7489{
7490}
7491#endif
7492
7493/**
7494 * hdd_update_cds_config() - API to update cds configuration parameters
7495 * @hdd_ctx: HDD Context
7496 *
7497 * Return: 0 for Success, errno on failure
7498 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007499static int hdd_update_cds_config(hdd_context_t *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307500{
7501 struct cds_config_info *cds_cfg;
7502
7503 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
7504 if (!cds_cfg) {
7505 hdd_err("failed to allocate cds config");
7506 return -ENOMEM;
7507 }
7508
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307509 cds_cfg->driver_type = DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08007510 if (!hdd_ctx->config->nMaxPsPoll ||
7511 !hdd_ctx->config->enablePowersaveOffload) {
7512 cds_cfg->powersave_offload_enabled =
7513 hdd_ctx->config->enablePowersaveOffload;
7514 } else {
7515 if ((hdd_ctx->config->enablePowersaveOffload ==
7516 PS_QPOWER_NODEEPSLEEP) ||
7517 (hdd_ctx->config->enablePowersaveOffload ==
7518 PS_LEGACY_NODEEPSLEEP))
7519 cds_cfg->powersave_offload_enabled =
7520 PS_LEGACY_NODEEPSLEEP;
7521 else
7522 cds_cfg->powersave_offload_enabled =
7523 PS_LEGACY_DEEPSLEEP;
7524 hdd_info("Qpower disabled in cds config, %d",
7525 cds_cfg->powersave_offload_enabled);
7526 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307527 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
7528 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
7529 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
7530 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
7531 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
7532
7533 /* Here ol_ini_info is used to store ini status of arp offload
7534 * ns offload and others. Currently 1st bit is used for arp
7535 * off load and 2nd bit for ns offload currently, rest bits are unused
7536 */
7537 if (hdd_ctx->config->fhostArpOffload)
7538 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
7539 if (hdd_ctx->config->fhostNSOffload)
7540 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
7541
7542 /*
7543 * Copy the DFS Phyerr Filtering Offload status.
7544 * This parameter reflects the value of the
7545 * dfs_phyerr_filter_offload flag as set in the ini.
7546 */
7547 cds_cfg->dfs_phyerr_filter_offload =
7548 hdd_ctx->config->fDfsPhyerrFilterOffload;
7549 if (hdd_ctx->config->ssdp)
7550 cds_cfg->ssdp = hdd_ctx->config->ssdp;
7551
7552 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
7553 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
7554
7555 cds_cfg->ap_maxoffload_reorderbuffs =
7556 hdd_ctx->config->apMaxOffloadReorderBuffs;
7557
7558 cds_cfg->ap_disable_intrabss_fwd =
7559 hdd_ctx->config->apDisableIntraBssFwd;
7560
7561 cds_cfg->dfs_pri_multiplier =
7562 hdd_ctx->config->dfsRadarPriMultiplier;
7563 cds_cfg->reorder_offload =
7564 hdd_ctx->config->reorderOffloadSupport;
7565
7566 /* IPA micro controller data path offload resource config item */
7567 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07007568 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
7569 /* IpaUcTxBufCount should be power of 2 */
7570 hdd_err("Round down IpaUcTxBufCount %d to nearest power of 2",
7571 hdd_ctx->config->IpaUcTxBufCount);
7572 hdd_ctx->config->IpaUcTxBufCount =
7573 rounddown_pow_of_two(
7574 hdd_ctx->config->IpaUcTxBufCount);
7575 if (!hdd_ctx->config->IpaUcTxBufCount) {
7576 hdd_err("Failed to round down IpaUcTxBufCount");
7577 return -EINVAL;
7578 }
7579 hdd_err("IpaUcTxBufCount rounded down to %d",
7580 hdd_ctx->config->IpaUcTxBufCount);
7581 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307582 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
7583 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07007584 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
7585 /* IpaUcRxIndRingCount should be power of 2 */
7586 hdd_err("Round down IpaUcRxIndRingCount %d to nearest power of 2",
7587 hdd_ctx->config->IpaUcRxIndRingCount);
7588 hdd_ctx->config->IpaUcRxIndRingCount =
7589 rounddown_pow_of_two(
7590 hdd_ctx->config->IpaUcRxIndRingCount);
7591 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
7592 hdd_err("Failed to round down IpaUcRxIndRingCount");
7593 return -EINVAL;
7594 }
7595 hdd_err("IpaUcRxIndRingCount rounded down to %d",
7596 hdd_ctx->config->IpaUcRxIndRingCount);
7597 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307598 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07007599 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307600 cds_cfg->uc_tx_partition_base =
7601 hdd_ctx->config->IpaUcTxPartitionBase;
7602 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
7603
7604 cds_cfg->ip_tcp_udp_checksum_offload =
7605 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05307606 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307607 cds_cfg->ce_classify_enabled =
7608 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07007609 cds_cfg->bpf_packet_filter_enable =
7610 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307611 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
7612 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
7613 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07007614 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07007615 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07007616 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07007617 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Dustin Brown13995f02017-01-12 15:38:42 -08007618 cds_cfg->active_bpf_mode = hdd_ctx->config->active_bpf_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307619
7620 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
7621 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
7622 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07007623 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307624 cds_init_ini_config(cds_cfg);
7625 return 0;
7626}
7627
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007628/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08007629 * hdd_update_user_config() - API to update user configuration
7630 * parameters to obj mgr which are used by multiple components
7631 * @hdd_ctx: HDD Context
7632 *
7633 * Return: 0 for Success, errno on failure
7634 */
7635static int hdd_update_user_config(hdd_context_t *hdd_ctx)
7636{
7637 struct wlan_objmgr_psoc_user_config *user_config;
7638
7639 user_config = qdf_mem_malloc(sizeof(*user_config));
7640 if (user_config == NULL) {
7641 hdd_alert("Failed to alloc memory for user_config!");
7642 return -ENOMEM;
7643 }
7644
7645 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
7646 user_config->dual_mac_feature_disable =
7647 hdd_ctx->config->dual_mac_feature_disable;
7648 user_config->indoor_channel_support =
7649 hdd_ctx->config->indoor_channel_support;
7650 user_config->is_11d_support_enabled =
7651 hdd_ctx->config->Is11dSupportEnabled;
7652 user_config->is_11h_support_enabled =
7653 hdd_ctx->config->Is11hSupportEnabled;
7654 user_config->optimize_chan_avoid_event =
7655 hdd_ctx->config->goptimize_chan_avoid_event;
7656 user_config->skip_dfs_chnl_in_p2p_search =
7657 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07007658 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08007659 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
7660
7661 qdf_mem_free(user_config);
7662 return 0;
7663}
7664
7665/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007666 * hdd_init_thermal_info - Initialize thermal level
7667 * @hdd_ctx: HDD context
7668 *
7669 * Initialize thermal level at SME layer and set the thermal level callback
7670 * which would be called when a configured thermal threshold is hit.
7671 *
7672 * Return: 0 on success and errno on failure
7673 */
7674static int hdd_init_thermal_info(hdd_context_t *hdd_ctx)
7675{
7676 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307677 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007678
7679 thermal_param.smeThermalMgmtEnabled =
7680 hdd_ctx->config->thermalMitigationEnable;
7681 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
7682
Poddar, Siddarth83905022016-04-16 17:56:08 -07007683 thermal_param.sme_throttle_duty_cycle_tbl[0] =
7684 hdd_ctx->config->throttle_dutycycle_level0;
7685 thermal_param.sme_throttle_duty_cycle_tbl[1] =
7686 hdd_ctx->config->throttle_dutycycle_level1;
7687 thermal_param.sme_throttle_duty_cycle_tbl[2] =
7688 hdd_ctx->config->throttle_dutycycle_level2;
7689 thermal_param.sme_throttle_duty_cycle_tbl[3] =
7690 hdd_ctx->config->throttle_dutycycle_level3;
7691
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007692 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
7693 hdd_ctx->config->thermalTempMinLevel0;
7694 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
7695 hdd_ctx->config->thermalTempMaxLevel0;
7696 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
7697 hdd_ctx->config->thermalTempMinLevel1;
7698 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
7699 hdd_ctx->config->thermalTempMaxLevel1;
7700 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
7701 hdd_ctx->config->thermalTempMinLevel2;
7702 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
7703 hdd_ctx->config->thermalTempMaxLevel2;
7704 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
7705 hdd_ctx->config->thermalTempMinLevel3;
7706 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
7707 hdd_ctx->config->thermalTempMaxLevel3;
7708
7709 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
7710
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307711 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05307712 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007713
7714 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
7715 hdd_set_thermal_level_cb);
7716
7717 return 0;
7718
7719}
7720
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007721#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
7722/**
7723 * hdd_hold_rtnl_lock - Hold RTNL lock
7724 *
7725 * Hold RTNL lock
7726 *
7727 * Return: True if held and false otherwise
7728 */
7729static inline bool hdd_hold_rtnl_lock(void)
7730{
7731 rtnl_lock();
7732 return true;
7733}
7734
7735/**
7736 * hdd_release_rtnl_lock - Release RTNL lock
7737 *
7738 * Release RTNL lock
7739 *
7740 * Return: None
7741 */
7742static inline void hdd_release_rtnl_lock(void)
7743{
7744 rtnl_unlock();
7745}
7746#else
7747static inline bool hdd_hold_rtnl_lock(void) { return false; }
7748static inline void hdd_release_rtnl_lock(void) { }
7749#endif
7750
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007751#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007752
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307753/* MAX iwpriv command support */
7754#define PKTLOG_SET_BUFF_SIZE 3
7755#define MAX_PKTLOG_SIZE 16
7756
7757/**
7758 * hdd_pktlog_set_buff_size() - set pktlog buffer size
7759 * @hdd_ctx: hdd context
7760 * @set_value2: pktlog buffer size value
7761 *
7762 *
7763 * Return: 0 for success or error.
7764 */
7765static int hdd_pktlog_set_buff_size(hdd_context_t *hdd_ctx, int set_value2)
7766{
7767 struct sir_wifi_start_log start_log = { 0 };
7768 QDF_STATUS status;
7769
7770 start_log.ring_id = RING_ID_PER_PACKET_STATS;
7771 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
7772 start_log.ini_triggered = cds_is_packet_log_enabled();
7773 start_log.user_triggered = 1;
7774 start_log.size = set_value2;
7775
7776 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
7777 if (!QDF_IS_STATUS_SUCCESS(status)) {
7778 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
7779 EXIT();
7780 return -EINVAL;
7781 }
7782
7783 return 0;
7784}
7785
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007786/**
7787 * hdd_process_pktlog_command() - process pktlog command
7788 * @hdd_ctx: hdd context
7789 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307790 * @set_value2: pktlog buffer size value
7791 *
7792 * This function process pktlog command.
7793 * set_value2 only matters when set_value is 3 (set buff size)
7794 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007795 *
7796 * Return: 0 for success or error.
7797 */
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307798int hdd_process_pktlog_command(hdd_context_t *hdd_ctx, uint32_t set_value,
7799 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007800{
7801 int ret;
7802 bool enable;
7803 uint8_t user_triggered = 0;
7804
7805 ret = wlan_hdd_validate_context(hdd_ctx);
7806 if (0 != ret)
7807 return ret;
7808
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307809 hdd_info("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007810
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307811 if (set_value > PKTLOG_SET_BUFF_SIZE) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007812 hdd_err("invalid pktlog value %d", set_value);
7813 return -EINVAL;
7814 }
7815
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307816 if (set_value == PKTLOG_SET_BUFF_SIZE) {
7817 if (set_value2 <= 0) {
7818 hdd_err("invalid pktlog size %d", set_value2);
7819 return -EINVAL;
7820 } else if (set_value2 > MAX_PKTLOG_SIZE) {
7821 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
7822 return -EINVAL;
7823 }
7824 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
7825 }
7826
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007827 /*
7828 * set_value = 0 then disable packetlog
7829 * set_value = 1 enable packetlog forcefully
7830 * set_vlaue = 2 then disable packetlog if disabled through ini or
7831 * enable packetlog with AUTO type.
7832 */
7833 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
7834 true : false;
7835
7836 if (1 == set_value) {
7837 enable = true;
7838 user_triggered = 1;
7839 }
7840
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307841 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007842}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007843/**
7844 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
7845 * @hdd_ctx: HDD context
7846 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307847 * @user_triggered: triggered through iwpriv
7848 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007849 *
7850 * Return: 0 on success; error number otherwise
7851 */
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007852int hdd_pktlog_enable_disable(hdd_context_t *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307853 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007854{
7855 struct sir_wifi_start_log start_log;
7856 QDF_STATUS status;
7857
7858 start_log.ring_id = RING_ID_PER_PACKET_STATS;
7859 start_log.verbose_level =
7860 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08007861 start_log.ini_triggered = cds_is_packet_log_enabled();
7862 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05307863 start_log.size = size;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05307864 /*
7865 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
7866 * commands. Host uses this flag to decide whether to send pktlog
7867 * disable command to fw without sending pktlog enable command
7868 * previously. For eg, If vendor sends pktlog disable command without
7869 * sending pktlog enable command, then host discards the packet
7870 * but for iwpriv command, host will send it to fw.
7871 */
7872 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08007873 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
7874 if (!QDF_IS_STATUS_SUCCESS(status)) {
7875 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
7876 EXIT();
7877 return -EINVAL;
7878 }
7879
7880 return 0;
7881}
7882#endif /* REMOVE_PKT_LOG */
7883
7884
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05307885#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
7886/**
7887 * hdd_register_for_sap_restart_with_channel_switch() - Register for SAP channel
7888 * switch without restart
7889 *
7890 * Registers callback function to change the operating channel of SAP by using
7891 * channel switch announcements instead of restarting SAP.
7892 *
7893 * Return: QDF_STATUS
7894 */
7895QDF_STATUS hdd_register_for_sap_restart_with_channel_switch(void)
7896{
7897 QDF_STATUS status;
7898
7899 status = cds_register_sap_restart_channel_switch_cb(
7900 (void *)hdd_sap_restart_with_channel_switch);
7901 if (!QDF_IS_STATUS_SUCCESS(status))
7902 hdd_err("restart cb registration failed");
7903
7904 return status;
7905}
7906#endif
7907
Komal Seelam92fff912016-03-24 11:51:41 +05307908/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007909 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
7910 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05307911 * @dev: Device Pointer
7912 * @num: Number of Valid Mac address
7913 *
7914 * Return: Pointer to MAC address buffer
7915 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007916static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
7917 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05307918{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007919 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05307920}
Komal Seelam92fff912016-03-24 11:51:41 +05307921
7922/**
7923 * hdd_populate_random_mac_addr() - API to populate random mac addresses
7924 * @hdd_ctx: HDD Context
7925 * @num: Number of random mac addresses needed
7926 *
7927 * Generate random addresses using bit manipulation on the base mac address
7928 *
7929 * Return: None
7930 */
7931static void hdd_populate_random_mac_addr(hdd_context_t *hdd_ctx, uint32_t num)
7932{
7933 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
7934 uint32_t iter;
7935 struct hdd_config *ini = hdd_ctx->config;
7936 uint8_t *buf = NULL;
7937 uint8_t macaddr_b3, tmp_br3;
7938 uint8_t *src = ini->intfMacAddr[0].bytes;
7939
7940 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
7941 buf = ini->intfMacAddr[iter].bytes;
7942 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
7943 macaddr_b3 = buf[3];
7944 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
7945 INTF_MACADDR_MASK;
7946 macaddr_b3 += tmp_br3;
7947 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
7948 buf[0] |= 0x02;
7949 buf[3] = macaddr_b3;
Jeff Johnson34c88b72016-08-15 14:27:11 -07007950 hdd_info(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05307951 }
7952}
7953
7954/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007955 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05307956 * @hdd_ctx: HDD Context
7957 *
7958 * API to get mac addresses from platform driver and update the driver
7959 * structures and configure FW with the base mac address.
7960 * Return: int
7961 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007962static int hdd_platform_wlan_mac(hdd_context_t *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05307963{
7964 uint32_t no_of_mac_addr, iter;
7965 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
7966 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
7967 uint8_t *addr, *buf;
7968 struct device *dev = hdd_ctx->parent_dev;
7969 struct hdd_config *ini = hdd_ctx->config;
7970 tSirMacAddr mac_addr;
7971 QDF_STATUS status;
7972
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08007973 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05307974
7975 if (no_of_mac_addr == 0 || !addr) {
7976 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
7977 return -EINVAL;
7978 }
7979
7980 if (no_of_mac_addr > max_mac_addr)
7981 no_of_mac_addr = max_mac_addr;
7982
7983 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
7984
7985 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
7986 buf = ini->intfMacAddr[iter].bytes;
7987 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Jeff Johnson34c88b72016-08-15 14:27:11 -07007988 hdd_info(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05307989 }
7990
7991 status = sme_set_custom_mac_addr(mac_addr);
7992
7993 if (!QDF_IS_STATUS_SUCCESS(status))
7994 return -EAGAIN;
7995 if (no_of_mac_addr < max_mac_addr)
7996 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
7997 no_of_mac_addr);
7998 return 0;
7999}
8000
8001/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008002 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8003 * @hdd_ctx: HDD Context
8004 *
8005 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8006 * will generate its own MAC and update it to FW.
8007 *
8008 * Return: 0 for success
8009 * Non-zero error code for failure
8010 */
8011static int hdd_update_mac_addr_to_fw(hdd_context_t *hdd_ctx)
8012{
8013 tSirMacAddr customMacAddr;
8014 QDF_STATUS status;
8015
8016 qdf_mem_copy(&customMacAddr,
8017 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8018 sizeof(tSirMacAddr));
8019 status = sme_set_custom_mac_addr(customMacAddr);
8020 if (!QDF_IS_STATUS_SUCCESS(status))
8021 return -EAGAIN;
8022 return 0;
8023}
8024
8025/**
Komal Seelam92fff912016-03-24 11:51:41 +05308026 * hdd_initialize_mac_address() - API to get wlan mac addresses
8027 * @hdd_ctx: HDD Context
8028 *
8029 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8030 * is provisioned with mac addresses, driver uses it, else it will use
8031 * wlan_mac.bin to update HW MAC addresses.
8032 *
8033 * Return: None
8034 */
8035static void hdd_initialize_mac_address(hdd_context_t *hdd_ctx)
8036{
8037 QDF_STATUS status;
8038 int ret;
8039
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008040 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308041 if (ret == 0)
8042 return;
8043
8044 hdd_warn("Can't update mac config via platform driver ret:%d", ret);
8045
8046 status = hdd_update_mac_config(hdd_ctx);
8047
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008048 if (QDF_IS_STATUS_SUCCESS(status))
8049 return;
8050
8051 hdd_warn("can't update mac config via wlan_mac.bin, using MAC from ini file or auto-gen");
8052
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008053 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008054 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008055 if (ret != 0) {
8056 hdd_err("MAC address out-of-sync, ret:%d", ret);
8057 QDF_ASSERT(ret);
8058 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008059 }
Komal Seelam92fff912016-03-24 11:51:41 +05308060}
8061
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008062/**
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008063 * hdd_tsf_init() - Initialize the TSF synchronization interface
8064 * @hdd_ctx: HDD global context
8065 *
8066 * When TSF synchronization via GPIO is supported by the driver and
8067 * has been enabled in the configuration file, this function plumbs
8068 * the GPIO value down to firmware via SME.
8069 *
8070 * Return: None
8071 */
8072#ifdef WLAN_FEATURE_TSF
8073static void hdd_tsf_init(hdd_context_t *hdd_ctx)
8074{
8075 QDF_STATUS status;
8076
8077 if (hdd_ctx->config->tsf_gpio_pin == TSF_GPIO_PIN_INVALID)
8078 return;
8079
8080 status = sme_set_tsf_gpio(hdd_ctx->hHal,
8081 hdd_ctx->config->tsf_gpio_pin);
8082 if (!QDF_IS_STATUS_SUCCESS(status))
8083 hdd_err("Set tsf GPIO failed, status: %d", status);
8084}
8085#else
8086static void hdd_tsf_init(hdd_context_t *hdd_ctx)
8087{
8088}
8089#endif
8090
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008091static int hdd_set_smart_chainmask_enabled(hdd_context_t *hdd_ctx)
8092{
8093 int vdev_id = 0;
8094 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8095 int value = hdd_ctx->config->smart_chainmask_enabled;
8096 int vpdev = PDEV_CMD;
8097 int ret;
8098
8099 ret = wma_cli_set_command(vdev_id, param_id, value, vpdev);
8100 if (ret)
8101 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8102
8103 return ret;
8104}
8105
8106static int hdd_set_alternative_chainmask_enabled(hdd_context_t *hdd_ctx)
8107{
8108 int vdev_id = 0;
8109 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8110 int value = hdd_ctx->config->alternative_chainmask_enabled;
8111 int vpdev = PDEV_CMD;
8112 int ret;
8113
8114 ret = wma_cli_set_command(vdev_id, param_id, value, vpdev);
8115 if (ret)
8116 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8117 ret);
8118
8119 return ret;
8120}
8121
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008122/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008123 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8124 * @hdd_ctx: HDD context
8125 *
8126 * Pre configurations to be done at lower layer before calling cds enable.
8127 *
8128 * Return: 0 on success and errno on failure.
8129 */
8130static int hdd_pre_enable_configure(hdd_context_t *hdd_ctx)
8131{
8132 int ret;
8133 QDF_STATUS status;
8134 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008135 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008136
Leo Changfdb45c32016-10-28 11:09:23 -07008137 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008138 /*
8139 * Set 802.11p config
8140 * TODO-OCB: This has been temporarily added here to ensure this
8141 * parameter is set in CSR when we init the channel list. This should
8142 * be removed once the 5.9 GHz channels are added to the regulatory
8143 * domain.
8144 */
8145 hdd_set_dot11p_config(hdd_ctx);
8146
8147 /*
8148 * Note that the cds_pre_enable() sequence triggers the cfg download.
8149 * The cfg download must occur before we update the SME config
8150 * since the SME config operation must access the cfg database
8151 */
8152 status = hdd_set_sme_config(hdd_ctx);
8153
8154 if (QDF_STATUS_SUCCESS != status) {
8155 hdd_alert("Failed hdd_set_sme_config: %d", status);
8156 ret = qdf_status_to_os_return(status);
8157 goto out;
8158 }
8159
8160 ret = wma_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
8161 hdd_ctx->config->tx_chain_mask_1ss,
8162 PDEV_CMD);
8163 if (0 != ret) {
8164 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8165 goto out;
8166 }
8167
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008168 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8169 if (ret)
8170 goto out;
8171
8172 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8173 if (ret)
8174 goto out;
8175
Prashanth Bhatta07998752016-04-28 12:35:33 -07008176 hdd_program_country_code(hdd_ctx);
8177
8178 status = hdd_set_sme_chan_list(hdd_ctx);
8179 if (status != QDF_STATUS_SUCCESS) {
8180 hdd_alert("Failed to init channel list: %d", status);
8181 ret = qdf_status_to_os_return(status);
8182 goto out;
8183 }
8184
8185 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008186 if (!hdd_update_config_cfg(hdd_ctx)) {
Prashanth Bhatta07998752016-04-28 12:35:33 -07008187 hdd_alert("config update failed");
8188 ret = -EINVAL;
8189 goto out;
8190 }
8191
Prashanth Bhatta07998752016-04-28 12:35:33 -07008192 /*
8193 * Set the MAC Address Currently this is used by HAL to add self sta.
8194 * Remove this once self sta is added as part of session open.
8195 */
8196 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8197 hdd_ctx->config->intfMacAddr[0].bytes,
8198 sizeof(hdd_ctx->config->intfMacAddr[0]));
8199
8200 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8201 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8202 hal_status, hal_status);
8203 ret = -EINVAL;
8204 goto out;
8205 }
8206
8207 hdd_init_channel_avoidance(hdd_ctx);
8208
8209out:
8210 return ret;
8211}
8212
8213/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008214 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8215 * @context_ptr - hdd context pointer
8216 * @event_ptr - event structure pointer
8217 *
8218 * This is the p2p listen offload stop event handler, it sends vendor
8219 * event back to supplicant to notify the stop reason.
8220 *
8221 * Return: None
8222 */
8223static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8224 void *event_ptr)
8225{
8226 hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr;
8227 struct sir_p2p_lo_event *evt = event_ptr;
8228 struct sk_buff *vendor_event;
8229
8230 ENTER();
8231
8232 if (hdd_ctx == NULL) {
8233 hdd_err("Invalid HDD context pointer");
8234 return;
8235 }
8236
8237 vendor_event =
8238 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
8239 NULL, sizeof(uint32_t) + NLMSG_HDRLEN,
8240 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8241 GFP_KERNEL);
8242
8243 if (!vendor_event) {
8244 hdd_err("cfg80211_vendor_event_alloc failed");
8245 return;
8246 }
8247
8248 if (nla_put_u32(vendor_event,
8249 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8250 evt->reason_code)) {
8251 hdd_err("nla put failed");
8252 kfree_skb(vendor_event);
8253 return;
8254 }
8255
8256 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
8257}
8258
8259/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308260 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8261 * @hdd_ctx: HDD context
8262 *
8263 * This function sends the adaptive dwell time config configuration to the
8264 * firmware via WMA
8265 *
8266 * Return: 0 - success, < 0 - failure
8267 */
8268static int hdd_adaptive_dwelltime_init(hdd_context_t *hdd_ctx)
8269{
8270 QDF_STATUS status;
8271 struct adaptive_dwelltime_params dwelltime_params;
8272
8273 dwelltime_params.is_enabled =
8274 hdd_ctx->config->adaptive_dwell_mode_enabled;
8275 dwelltime_params.dwelltime_mode =
8276 hdd_ctx->config->global_adapt_dwelltime_mode;
8277 dwelltime_params.lpf_weight =
8278 hdd_ctx->config->adapt_dwell_lpf_weight;
8279 dwelltime_params.passive_mon_intval =
8280 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8281 dwelltime_params.wifi_act_threshold =
8282 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8283
8284 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8285 &dwelltime_params);
8286
8287 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8288 if (!QDF_IS_STATUS_SUCCESS(status)) {
8289 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8290 return -EAGAIN;
8291 }
8292 return 0;
8293}
8294
Arun Khandavallid4349a92016-07-25 11:10:43 +05308295#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8296/**
8297 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
8298 * @hdd_ctx: HDD context
8299 *
8300 * Set auto shutdown callback to get indications from firmware to indicate
8301 * userspace to shutdown WLAN after a configured amount of inactivity.
8302 *
8303 * Return: 0 on success and errno on failure.
8304 */
8305static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8306{
8307 QDF_STATUS status;
8308
8309 if (!hdd_ctx->config->WlanAutoShutdown)
8310 return 0;
8311
8312 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
8313 wlan_hdd_auto_shutdown_cb);
8314 if (status != QDF_STATUS_SUCCESS)
8315 hdd_err("Auto shutdown feature could not be enabled: %d",
8316 status);
8317
8318 return qdf_status_to_os_return(status);
8319}
8320#else
8321static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8322{
8323 return 0;
8324}
8325#endif
8326
8327/**
8328 * hdd_features_init() - Init features
8329 * @hdd_ctx: HDD context
8330 * @adapter: Primary adapter context
8331 *
8332 * Initialize features and their feature context after WLAN firmware is up.
8333 *
8334 * Return: 0 on success and errno on failure.
8335 */
8336static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8337{
8338 tSirTxPowerLimit hddtxlimit;
8339 QDF_STATUS status;
8340 int ret;
8341
8342 ENTER();
8343
8344 ret = hdd_update_country_code(hdd_ctx, adapter);
8345 if (ret) {
8346 hdd_err("Failed to update country code: %d", ret);
8347 goto out;
8348 }
8349
8350 /* FW capabilities received, Set the Dot11 mode */
8351 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07008352 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
8353 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308354
Arun Khandavallid4349a92016-07-25 11:10:43 +05308355
8356 if (hdd_ctx->config->fIsImpsEnabled)
8357 hdd_set_idle_ps_config(hdd_ctx, true);
8358 else
8359 hdd_set_idle_ps_config(hdd_ctx, false);
8360
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308361 if (hdd_ctx->config->enable_go_cts2self_for_sta)
8362 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
8363
Arun Khandavallid4349a92016-07-25 11:10:43 +05308364 if (hdd_lro_init(hdd_ctx))
8365 hdd_err("Unable to initialize LRO in fw");
8366
8367 if (hdd_adaptive_dwelltime_init(hdd_ctx))
8368 hdd_err("Unable to send adaptive dwelltime setting to FW");
8369
8370 ret = hdd_init_thermal_info(hdd_ctx);
8371 if (ret) {
8372 hdd_err("Error while initializing thermal information");
8373 goto deregister_frames;
8374 }
8375
Poddar, Siddarth66a46592017-02-22 11:44:44 +05308376 if (cds_is_packet_log_enabled())
8377 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
8378
Arun Khandavallid4349a92016-07-25 11:10:43 +05308379 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
8380 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
8381 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
8382 if (!QDF_IS_STATUS_SUCCESS(status))
8383 hdd_err("Error setting txlimit in sme: %d", status);
8384
8385 hdd_tsf_init(hdd_ctx);
8386
Arun Khandavallid4349a92016-07-25 11:10:43 +05308387 ret = hdd_register_cb(hdd_ctx);
8388 if (ret) {
8389 hdd_err("Failed to register HDD callbacks!");
8390 goto deregister_frames;
8391 }
8392
8393 if (hdd_ctx->config->dual_mac_feature_disable) {
8394 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
8395 if (status != QDF_STATUS_SUCCESS) {
8396 hdd_err("Failed to disable dual mac features");
8397 goto deregister_cb;
8398 }
8399 }
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05308400 if (hdd_ctx->config->goptimize_chan_avoid_event) {
8401 status = sme_enable_disable_chanavoidind_event(
8402 hdd_ctx->hHal, 0);
8403 if (!QDF_IS_STATUS_SUCCESS(status)) {
8404 hdd_err("Failed to disable Chan Avoidance Indication");
8405 goto deregister_cb;
8406 }
8407 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05308408
8409 /* register P2P Listen Offload event callback */
8410 if (wma_is_p2p_lo_capable())
8411 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
8412 wlan_hdd_p2p_lo_event_callback);
8413
8414 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
8415
8416 if (ret)
8417 goto deregister_cb;
8418
8419 EXIT();
8420 return 0;
8421
8422deregister_cb:
8423 hdd_deregister_cb(hdd_ctx);
8424deregister_frames:
8425 wlan_hdd_cfg80211_deregister_frames(adapter);
8426out:
8427 return -EINVAL;
8428
8429}
8430
Abhishek Singh6092fbb2017-01-25 18:10:31 +05308431#ifdef NAPIER_SCAN
8432/**
8433 *
8434 * hdd_post_cds_enable_config() - HDD post cds start config helper
8435 * @adapter - Pointer to the HDD
8436 *
8437 * Return: None
8438 */
8439static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
8440{
8441 QDF_STATUS status;
8442
8443 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
8444 wlan_cfg80211_inform_bss_frame,
8445 SCAN_CB_TYPE_INFORM_BCN);
8446 if (!QDF_IS_STATUS_SUCCESS(status)) {
8447 hdd_err("failed with status code %08d [x%08x]",
8448 status, status);
8449 return status;
8450 }
8451
8452 return QDF_STATUS_SUCCESS;
8453}
8454#else
8455static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
8456{
8457 return QDF_STATUS_SUCCESS;
8458}
8459
8460#endif
Arun Khandavallid4349a92016-07-25 11:10:43 +05308461
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308462/**
Arun Khandavallifae92942016-08-01 13:31:08 +05308463 * hdd_configure_cds() - Configure cds modules
8464 * @hdd_ctx: HDD context
8465 * @adapter: Primary adapter context
8466 *
8467 * Enable Cds modules after WLAN firmware is up.
8468 *
8469 * Return: 0 on success and errno on failure.
8470 */
8471int hdd_configure_cds(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8472{
8473 int ret;
8474 QDF_STATUS status;
8475 /* structure of function pointers to be used by CDS */
8476 struct cds_sme_cbacks sme_cbacks;
8477
8478 ret = hdd_pre_enable_configure(hdd_ctx);
8479 if (ret) {
8480 hdd_err("Failed to pre-configure cds");
8481 goto out;
8482 }
8483
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08008484 /* Always get latest IPA resources allocated from cds_open and configure
8485 * IPA module before configuring them to FW. Sequence required as crash
8486 * observed otherwise.
8487 */
8488 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
8489 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
8490 hdd_err("Failed to setup pipes");
8491 goto out;
8492 }
8493 }
8494
Arun Khandavallifae92942016-08-01 13:31:08 +05308495 /*
8496 * Start CDS which starts up the SME/MAC/HAL modules and everything
8497 * else
8498 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308499 status = cds_enable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308500
8501 if (!QDF_IS_STATUS_SUCCESS(status)) {
8502 hdd_alert("cds_enable failed");
8503 goto out;
8504 }
8505
8506 status = hdd_post_cds_enable_config(hdd_ctx);
8507 if (!QDF_IS_STATUS_SUCCESS(status)) {
8508 hdd_alert("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008509 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05308510 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05308511 status = hdd_register_bcn_cb(hdd_ctx);
8512 if (!QDF_IS_STATUS_SUCCESS(status)) {
8513 hdd_alert("hdd_post_cds_enable_config failed");
8514 goto cds_disable;
8515 }
Arun Khandavallifae92942016-08-01 13:31:08 +05308516
8517 ret = hdd_features_init(hdd_ctx, adapter);
8518 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008519 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05308520
8521 sme_cbacks.sme_get_valid_channels = sme_get_cfg_valid_channels;
8522 sme_cbacks.sme_get_nss_for_vdev = sme_get_vdev_type_nss;
8523 status = cds_init_policy_mgr(&sme_cbacks);
8524 if (!QDF_IS_STATUS_SUCCESS(status)) {
8525 hdd_err("Policy manager initialization failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008526 goto hdd_features_deinit;
Arun Khandavallifae92942016-08-01 13:31:08 +05308527 }
8528
8529 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008530
8531hdd_features_deinit:
8532 hdd_deregister_cb(hdd_ctx);
8533 wlan_hdd_cfg80211_deregister_frames(adapter);
8534cds_disable:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308535 cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008536
Arun Khandavallifae92942016-08-01 13:31:08 +05308537out:
8538 return -EINVAL;
8539}
8540
8541/**
8542 * hdd_deconfigure_cds() -De-Configure cds
8543 * @hdd_ctx: HDD context
8544 *
8545 * Deconfigure Cds modules before WLAN firmware is down.
8546 *
8547 * Return: 0 on success and errno on failure.
8548 */
Jeff Johnson590e2012016-10-05 16:16:24 -07008549static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05308550{
8551 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07008552 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05308553
8554 ENTER();
8555 /* De-register the SME callbacks */
8556 hdd_deregister_cb(hdd_ctx);
8557
8558 /* De-init Policy Manager */
8559 if (!QDF_IS_STATUS_SUCCESS(cds_deinit_policy_mgr())) {
8560 hdd_err("Failed to deinit policy manager");
8561 /* Proceed and complete the clean up */
Houston Hoffman6640cf32016-10-10 16:44:29 -07008562 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308563 }
8564
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308565 qdf_status = cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308566 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8567 hdd_err("Failed to Disable the CDS Modules! :%d",
8568 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07008569 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308570 }
8571
8572 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07008573 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05308574}
8575
8576
8577/**
8578 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
8579 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05308580 *
8581 * This function maintains the driver state machine it will be invoked from
8582 * exit, shutdown and con_mode change handler. Depending on the driver state
8583 * shall perform the stopping/closing of the modules.
8584 *
8585 * Return: 0 for success; non-zero for failure
8586 */
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07008587int hdd_wlan_stop_modules(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05308588{
8589 void *hif_ctx;
8590 qdf_device_t qdf_ctx;
8591 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308592 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05308593 p_cds_sched_context cds_sched_context = NULL;
8594
8595 ENTER();
8596
8597 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
8598 if (!qdf_ctx) {
8599 hdd_err("QDF device context NULL");
8600 return -EINVAL;
8601 }
8602
8603 cds_sched_context = get_cds_sched_ctxt();
8604 if (!cds_sched_context) {
8605 hdd_err("cds scheduler context NULL");
8606 return -EINVAL;
8607 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308608 mutex_lock(&hdd_ctx->iface_change_lock);
8609 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05308610
8611 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
8612
8613 switch (hdd_ctx->driver_status) {
8614 case DRIVER_MODULES_UNINITIALIZED:
8615 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308616 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308617 case DRIVER_MODULES_CLOSED:
8618 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308619 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308620 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05308621 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05308622 if (hdd_deconfigure_cds(hdd_ctx)) {
8623 hdd_alert("Failed to de-configure CDS");
8624 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308625 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308626 }
8627 hdd_info("successfully Disabled the CDS modules!");
8628 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
8629 break;
8630 case DRIVER_MODULES_OPENED:
8631 hdd_info("Closing CDS modules!");
8632 break;
8633 default:
8634 hdd_err("Trying to stop wlan in a wrong state: %d",
8635 hdd_ctx->driver_status);
8636 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308637 ret = -EINVAL;
8638 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308639 }
8640
Govind Singhb048e872016-09-27 22:07:43 +05308641 qdf_status = cds_post_disable(hdd_ctx->pcds_context);
8642 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8643 hdd_err("Failed to process post CDS disable Modules! :%d",
8644 qdf_status);
8645 ret = -EINVAL;
8646 QDF_ASSERT(0);
8647 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308648 qdf_status = cds_close(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308649 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8650 hdd_warn("Failed to stop CDS:%d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05308651 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308652 QDF_ASSERT(0);
8653 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07008654
Rajeev Kumarecf87ff2017-01-13 15:46:07 -08008655 ret = hdd_release_and_destroy_pdev(hdd_ctx);
8656 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308657 hdd_err("Pdev delete failed");
8658
Rajeev Kumar99e4cf62017-01-13 15:31:19 -08008659 ret = hdd_release_and_destroy_psoc(hdd_ctx);
8660 if (ret)
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308661 hdd_err("Psoc delete failed");
8662
Arun Khandavallifae92942016-08-01 13:31:08 +05308663 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
8664 if (!hif_ctx) {
8665 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308666 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308667 }
8668
8669 hdd_hif_close(hif_ctx);
8670
8671 ol_cds_free();
8672
Arunk Khandavalli649c0092016-11-22 21:20:43 +05308673 if (!cds_is_driver_recovering() && !cds_is_driver_unloading()) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308674 ret = pld_power_off(qdf_ctx->dev);
8675 if (ret)
8676 hdd_err("CNSS power down failed put device into Low power mode:%d",
8677 ret);
8678 }
8679 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
8680
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308681done:
8682 hdd_ctx->stop_modules_in_progress = false;
8683 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05308684 EXIT();
8685
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308686 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05308687
8688}
8689
8690/**
8691 * hdd_iface_change_callback() - Function invoked when stop modules expires
8692 * @priv: pointer to hdd context
8693 *
8694 * This function is invoked when the timer waiting for the interface change
8695 * expires, it shall cut-down the power to wlan and stop all the modules.
8696 *
8697 * Return: void
8698 */
8699static void hdd_iface_change_callback(void *priv)
8700{
8701 hdd_context_t *hdd_ctx = (hdd_context_t *) priv;
8702 int ret;
8703 int status = wlan_hdd_validate_context(hdd_ctx);
8704
8705 if (status)
8706 return;
8707
8708 ENTER();
8709 hdd_info("Interface change timer expired close the modules!");
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07008710 ret = hdd_wlan_stop_modules(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05308711 if (ret)
8712 hdd_alert("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05308713 EXIT();
8714}
8715
8716/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05308717 * hdd_state_info_dump() - prints state information of hdd layer
8718 * @buf: buffer pointer
8719 * @size: size of buffer to be filled
8720 *
8721 * This function is used to dump state information of hdd layer
8722 *
8723 * Return: None
8724 */
8725static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
8726{
8727 hdd_context_t *hdd_ctx;
8728 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
8729 QDF_STATUS status;
8730 hdd_station_ctx_t *hdd_sta_ctx;
8731 hdd_adapter_t *adapter;
8732 uint16_t len = 0;
8733 char *buf = *buf_ptr;
8734
8735 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8736 if (!hdd_ctx) {
8737 hdd_err("Failed to get hdd context ");
8738 return;
8739 }
8740
8741 hdd_notice("size of buffer: %d", *size);
8742
8743 len += scnprintf(buf + len, *size - len,
8744 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
8745 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08008746 "\n is_scheduler_suspended %d",
8747 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05308748
8749 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
8750
8751 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
8752 adapter = adapter_node->pAdapter;
8753 if (adapter->dev)
8754 len += scnprintf(buf + len, *size - len,
8755 "\n device name: %s", adapter->dev->name);
8756 len += scnprintf(buf + len, *size - len,
8757 "\n device_mode: %d", adapter->device_mode);
8758 switch (adapter->device_mode) {
8759 case QDF_STA_MODE:
8760 case QDF_P2P_CLIENT_MODE:
8761 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
8762 len += scnprintf(buf + len, *size - len,
8763 "\n connState: %d",
8764 hdd_sta_ctx->conn_info.connState);
8765 break;
8766
8767 default:
8768 break;
8769 }
8770 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
8771 adapter_node = next;
8772 }
8773
8774 *size -= len;
8775 *buf_ptr += len;
8776}
8777
8778/**
8779 * hdd_register_debug_callback() - registration function for hdd layer
8780 * to print hdd state information
8781 *
8782 * Return: None
8783 */
8784static void hdd_register_debug_callback(void)
8785{
8786 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
8787}
8788
8789/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008790 * hdd_wlan_startup() - HDD init function
8791 * @dev: Pointer to the underlying device
8792 *
8793 * This is the driver startup code executed once a WLAN device has been detected
8794 *
8795 * Return: 0 for success, < 0 for failure
8796 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308797int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008798{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308799 QDF_STATUS status;
Jeff Johnson957bc272017-02-02 08:54:48 -08008800 hdd_context_t *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008801 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008802 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05308803 int set_value;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008804
8805 ENTER();
8806
Arun Khandavallifae92942016-08-01 13:31:08 +05308807 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008808
8809 if (IS_ERR(hdd_ctx))
8810 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008811
Arun Khandavallifae92942016-08-01 13:31:08 +05308812 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
8813 hdd_iface_change_callback, (void *)hdd_ctx);
8814
8815 mutex_init(&hdd_ctx->iface_change_lock);
8816
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008817 ret = hdd_init_netlink_services(hdd_ctx);
8818 if (ret)
8819 goto err_hdd_free_context;
8820
Jeff Johnsonce0032c2017-01-20 07:18:27 -08008821 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07008822 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05308823
Jeff Johnson957bc272017-02-02 08:54:48 -08008824 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05308825 if (ret) {
8826 hdd_alert("Failed to start modules: %d", ret);
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008827 goto err_exit_nl_srv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008828 }
8829
Yingying Tang80e15f32016-09-27 18:23:01 +08008830 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008831
Yingying Tang95409972016-10-20 15:16:15 +08008832 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
8833 hdd_notice("Failed to set wow pulse");
8834
Anurag Chouhan6d760662016-02-20 16:05:43 +05308835 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008836
8837 if (NULL == hdd_ctx->hHal) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07008838 hdd_alert("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05308839 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008840 }
8841
Prashanth Bhatta07998752016-04-28 12:35:33 -07008842 ret = hdd_wiphy_init(hdd_ctx);
8843 if (ret) {
8844 hdd_alert("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05308845 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008846 }
8847
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05308848 if (hdd_ctx->config->enable_dp_trace)
8849 qdf_dp_trace_init();
8850
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308851 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008852 goto err_wiphy_unregister;
8853
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05308854 wlan_hdd_init_chan_info(hdd_ctx);
8855
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07008856 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08008857
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008858 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008859
Jeff Johnson957bc272017-02-02 08:54:48 -08008860 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
8861 if (ret) {
8862 hdd_alert("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08008863 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008864 }
8865
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008866 hdd_release_rtnl_lock();
8867 rtnl_held = false;
8868
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08008869 wlan_hdd_update_11n_mode(hdd_ctx->config);
8870
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008871#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05308872 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05308873 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008874 hdd_skip_acs_scan_timer_handler,
8875 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308876 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07008877 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04008878 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008879#endif
8880
Nitesh Shah61c10d92016-10-19 19:29:15 +05308881 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
8882 QDF_TIMER_TYPE_SW,
8883 wlan_hdd_change_tdls_mode,
8884 hdd_ctx);
8885
Prashanth Bhattaab004382016-10-11 16:08:11 -07008886 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008887
Jeff Johnson9afc5012016-09-23 13:56:27 -07008888 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008889
Nirav Shahbd36b062016-07-18 11:12:59 +05308890 if (hdd_ctx->rps)
8891 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07008892
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07008893 ret = hdd_register_notifiers(hdd_ctx);
8894 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008895 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05308896
8897 status = wlansap_global_init();
8898 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08008899 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07008900
Komal Seelam8634b772016-09-29 12:12:24 +05308901 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08008902 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05308903 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08008904
bings612b9c42016-11-07 10:52:03 +08008905 if (hdd_enable_egap(hdd_ctx))
8906 hdd_err("enhance green ap is not enabled");
8907
Arun Khandavallifae92942016-08-01 13:31:08 +05308908 if (hdd_ctx->config->fIsImpsEnabled)
8909 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308910
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05308911 if (hdd_ctx->config->sifs_burst_duration) {
8912 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
8913 hdd_ctx->config->sifs_burst_duration;
8914
8915 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
8916 wma_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
8917 set_value, PDEV_CMD);
8918 }
8919
Arun Khandavallifae92942016-08-01 13:31:08 +05308920 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
8921 hdd_ctx->config->iface_change_wait_time * 5000);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05308922
Selvaraj, Sridhar1ffa0ec2017-03-10 09:52:12 +05308923 complete(&wlan_start_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008924 goto success;
8925
Jeff Johnson957bc272017-02-02 08:54:48 -08008926err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08008927 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008928
Jeff Johnson46bde382017-02-01 15:31:16 -08008929err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05308930 if (rtnl_held)
8931 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008932
Anurag Chouhance6a4052016-09-14 18:20:42 +05308933 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08008934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008935err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008936 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008937
Arun Khandavallifae92942016-08-01 13:31:08 +05308938err_stop_modules:
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07008939 hdd_wlan_stop_modules(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05308940
8941
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008942 status = cds_sched_close(hdd_ctx->pcds_context);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308943 if (!QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07008944 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05308945 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008946 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008947
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008948err_exit_nl_srv:
Houston Hoffman47a4a052016-11-14 23:22:44 -08008949 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08008950 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07008951 hdd_exit_netlink_services(hdd_ctx);
8952
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308953 cds_deinit_ini_config();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008954err_hdd_free_context:
Arun Khandavallifae92942016-08-01 13:31:08 +05308955 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
8956 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008957 hdd_context_destroy(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05308958 QDF_BUG(1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008959
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008960 return -EIO;
8961
8962success:
8963 EXIT();
8964 return 0;
8965}
8966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008967/**
Arun Khandavallifae92942016-08-01 13:31:08 +05308968 * hdd_wlan_update_target_info() - update target type info
8969 * @hdd_ctx: HDD context
8970 * @context: hif context
8971 *
8972 * Update target info received from firmware in hdd context
8973 * Return:None
8974 */
8975
8976void hdd_wlan_update_target_info(hdd_context_t *hdd_ctx, void *context)
8977{
8978 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
8979
8980 if (!tgt_info) {
8981 hdd_err("Target info is Null");
8982 return;
8983 }
8984
8985 hdd_ctx->target_type = tgt_info->target_type;
8986}
8987
8988/**
8989 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05308990 * @hdd_ctx: HDD context
8991 *
8992 * Register the HDD callbacks to CDS/SME.
8993 *
8994 * Return: 0 for success or Error code for failure
8995 */
8996int hdd_register_cb(hdd_context_t *hdd_ctx)
8997{
8998 QDF_STATUS status;
8999 int ret = 0;
9000
9001 ENTER();
9002
9003 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9004
9005 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9006 hdd_send_oem_data_rsp_msg);
9007
9008 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9009 wlan_hdd_cfg80211_fw_mem_dump_cb);
9010 if (!QDF_IS_STATUS_SUCCESS(status)) {
9011 hdd_err("Failed to register memdump callback");
9012 ret = -EINVAL;
9013 return ret;
9014 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309015 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9016 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309017 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9018 sme_nan_register_callback(hdd_ctx->hHal,
9019 wlan_hdd_cfg80211_nan_callback);
9020 sme_stats_ext_register_callback(hdd_ctx->hHal,
9021 wlan_hdd_cfg80211_stats_ext_callback);
9022
9023 sme_ext_scan_register_callback(hdd_ctx->hHal,
9024 wlan_hdd_cfg80211_extscan_callback);
9025
9026 status = cds_register_sap_restart_channel_switch_cb(
9027 (void *)hdd_sap_restart_with_channel_switch);
9028 if (!QDF_IS_STATUS_SUCCESS(status)) {
9029 hdd_err("restart cb registration failed");
9030 ret = -EINVAL;
9031 return ret;
9032 }
9033
9034 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9035 hdd_rssi_threshold_breached);
9036
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309037 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9038 wlan_hdd_cfg80211_link_layer_stats_callback);
9039
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309040 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9041 hdd_lost_link_info_cb);
9042 /* print error and not block the startup process */
9043 if (!QDF_IS_STATUS_SUCCESS(status))
9044 hdd_err("set lost link info callback failed");
9045
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309046 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9047
9048 EXIT();
9049
9050 return ret;
9051}
9052
9053/**
9054 * hdd_deregister_cb() - De-Register HDD callbacks.
9055 * @hdd_ctx: HDD context
9056 *
9057 * De-Register the HDD callbacks to CDS/SME.
9058 *
9059 * Return: void
9060 */
9061void hdd_deregister_cb(hdd_context_t *hdd_ctx)
9062{
9063 QDF_STATUS status;
9064
9065 ENTER();
9066
9067 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
9068 if (!QDF_IS_STATUS_SUCCESS(status))
9069 hdd_err("De-register of dcc stats callback failed: %d",
9070 status);
9071
9072 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309073 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
9074
9075 status = cds_deregister_sap_restart_channel_switch_cb();
9076 if (!QDF_IS_STATUS_SUCCESS(status))
9077 hdd_err("De-register restart cb registration failed: %d",
9078 status);
9079
9080 sme_stats_ext_register_callback(hdd_ctx->hHal,
9081 wlan_hdd_cfg80211_stats_ext_callback);
9082
9083 sme_nan_deregister_callback(hdd_ctx->hHal);
9084 status = sme_reset_tsfcb(hdd_ctx->hHal);
9085 if (!QDF_IS_STATUS_SUCCESS(status))
9086 hdd_err("Failed to de-register tsfcb the callback:%d",
9087 status);
9088 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
9089 if (!QDF_IS_STATUS_SUCCESS(status))
9090 hdd_err("Failed to de-register the fw mem dump callback: %d",
9091 status);
9092
9093 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
9094 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
9095
9096 EXIT();
9097}
9098
9099/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009100 * hdd_softap_sta_deauth() - handle deauth req from HDD
9101 * @adapter: Pointer to the HDD
9102 * @enable: bool value
9103 *
9104 * This to take counter measure to handle deauth req from HDD
9105 *
9106 * Return: None
9107 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309108QDF_STATUS hdd_softap_sta_deauth(hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009109 struct tagCsrDelStaParams *pDelStaParams)
9110{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309111 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009112
9113 ENTER();
9114
Jeff Johnson34c88b72016-08-15 14:27:11 -07009115 hdd_notice("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009116 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9117
9118 /* Ignore request to deauth bcmc station */
9119 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309120 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009121
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309122 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009123 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9124 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009125
9126 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309127 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009128}
9129
9130/**
9131 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
9132 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309133 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009134 *
9135 * This to take counter measure to handle deauth req from HDD
9136 *
9137 * Return: None
9138 */
9139void hdd_softap_sta_disassoc(hdd_adapter_t *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309140 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009141{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009142 ENTER();
9143
Jeff Johnson34c88b72016-08-15 14:27:11 -07009144 hdd_err("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009145 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9146
9147 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309148 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009149 return;
9150
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009151 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309152 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009153}
9154
9155void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *adapter,
9156 bool enable)
9157{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009158 ENTER();
9159
Jeff Johnson34c88b72016-08-15 14:27:11 -07009160 hdd_err("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009161 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9162
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009163 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9164 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009165}
9166
9167/**
9168 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
9169 * @hdd_ctx: HDD Context
9170 *
9171 * API to find if there is any STA or P2P-Client is connected
9172 *
9173 * Return: true if connected; false otherwise
9174 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309175QDF_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009176{
9177 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
9178}
9179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009180/**
9181 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
9182 * @adapter: HDD adapter pointer
9183 *
9184 * This function loop through each adapter and disable roaming on each STA
9185 * device mode except the input adapter.
9186 *
9187 * Note: On the input adapter roaming is not enabled yet hence no need to
9188 * disable.
9189 *
9190 * Return: None
9191 */
9192void wlan_hdd_disable_roaming(hdd_adapter_t *adapter)
9193{
9194 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9195 hdd_adapter_t *adapterIdx = NULL;
9196 hdd_adapter_list_node_t *adapterNode = NULL;
9197 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309198 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009199
9200 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
9201 hdd_ctx->config->isRoamOffloadScanEnabled &&
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009202 QDF_STA_MODE == adapter->device_mode &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009203 cds_is_sta_active_connection_exists()) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009204 hdd_notice("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009205 adapter->sessionId);
9206 /*
9207 * Loop through adapter and disable roaming for each STA device
9208 * mode except the input adapter.
9209 */
9210 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9211
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309212 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009213 adapterIdx = adapterNode->pAdapter;
9214
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009215 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009216 && adapter->sessionId != adapterIdx->sessionId) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009217 hdd_notice("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009218 adapterIdx->sessionId);
9219 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
9220 (adapterIdx),
9221 adapterIdx->sessionId, 0);
9222 }
9223
9224 status = hdd_get_next_adapter(hdd_ctx,
9225 adapterNode,
9226 &pNext);
9227 adapterNode = pNext;
9228 }
9229 }
9230}
9231
9232/**
9233 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
9234 * @adapter: HDD adapter pointer
9235 *
9236 * This function loop through each adapter and enable roaming on each STA
9237 * device mode except the input adapter.
9238 * Note: On the input adapter no need to enable roaming because link got
9239 * disconnected on this.
9240 *
9241 * Return: None
9242 */
9243void wlan_hdd_enable_roaming(hdd_adapter_t *adapter)
9244{
9245 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9246 hdd_adapter_t *adapterIdx = NULL;
9247 hdd_adapter_list_node_t *adapterNode = NULL;
9248 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309249 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009250
9251 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
9252 hdd_ctx->config->isRoamOffloadScanEnabled &&
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009253 QDF_STA_MODE == adapter->device_mode &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009254 cds_is_sta_active_connection_exists()) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009255 hdd_notice("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009256 adapter->sessionId);
9257 /*
9258 * Loop through adapter and enable roaming for each STA device
9259 * mode except the input adapter.
9260 */
9261 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9262
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309263 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009264 adapterIdx = adapterNode->pAdapter;
9265
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009266 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009267 && adapter->sessionId != adapterIdx->sessionId) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009268 hdd_notice("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009269 adapterIdx->sessionId);
9270 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
9271 (adapterIdx),
9272 adapterIdx->sessionId,
9273 REASON_CONNECT);
9274 }
9275
9276 status = hdd_get_next_adapter(hdd_ctx,
9277 adapterNode,
9278 &pNext);
9279 adapterNode = pNext;
9280 }
9281 }
9282}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009283
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +05309284/**
9285 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
9286 * @skb: sk buffer pointer
9287 *
9288 * Sends the bcast message to SVC multicast group with generic nl socket
9289 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
9290 *
9291 * Return: None
9292 */
9293static void nl_srv_bcast_svc(struct sk_buff *skb)
9294{
9295#ifdef CNSS_GENL
9296 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
9297#else
9298 nl_srv_bcast(skb);
9299#endif
9300}
9301
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309302void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009303{
9304 struct sk_buff *skb;
9305 struct nlmsghdr *nlh;
9306 tAniMsgHdr *ani_hdr;
9307 void *nl_data = NULL;
9308 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309309 struct radio_index_tlv *radio_info;
9310 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009311
9312 if (in_interrupt() || irqs_disabled() || in_atomic())
9313 flags = GFP_ATOMIC;
9314
9315 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
9316
9317 if (skb == NULL) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07009318 hdd_err("alloc_skb failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009319 return;
9320 }
9321
9322 nlh = (struct nlmsghdr *)skb->data;
9323 nlh->nlmsg_pid = 0; /* from kernel */
9324 nlh->nlmsg_flags = 0;
9325 nlh->nlmsg_seq = 0;
9326 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
9327
9328 ani_hdr = NLMSG_DATA(nlh);
9329 ani_hdr->type = type;
9330
9331 switch (type) {
9332 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +05309333 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009334 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009335 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -07009336 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009337 ani_hdr->length = 0;
9338 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009339 break;
9340 case WLAN_SVC_WLAN_STATUS_IND:
9341 case WLAN_SVC_WLAN_VERSION_IND:
9342 case WLAN_SVC_DFS_CAC_START_IND:
9343 case WLAN_SVC_DFS_CAC_END_IND:
9344 case WLAN_SVC_DFS_RADAR_DETECT_IND:
9345 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
9346 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -08009347 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +05309348 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009349 ani_hdr->length = len;
9350 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
9351 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
9352 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009353 break;
9354
9355 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -07009356 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009357 type);
9358 kfree_skb(skb);
9359 return;
9360 }
9361
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309362 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08009363 * Add radio index at the end of the svc event in TLV format
9364 * to maintain the backward compatibility with userspace
9365 * applications.
9366 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309367
9368 tlv_len = 0;
9369
9370 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
9371 < WLAN_NL_MAX_PAYLOAD) {
9372 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
9373 sizeof(*ani_hdr) + len);
9374 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
9375 radio_info->length = (unsigned short) sizeof(radio_info->radio);
9376 radio_info->radio = radio;
9377 tlv_len = sizeof(*radio_info);
9378 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
9379 "Added radio index tlv - radio index %d",
9380 radio_info->radio);
9381 }
9382
9383 nlh->nlmsg_len += tlv_len;
9384 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
9385
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +05309386 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009387
9388 return;
9389}
9390
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009391#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9392void wlan_hdd_auto_shutdown_cb(void)
9393{
Mahesh Kumar Kalikot Veetild214d552016-09-14 15:15:49 -07009394 hdd_context_t *hdd_ctx = cds_get_global_context();
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309395
9396 if (!hdd_ctx)
9397 return;
9398
Jeff Johnson28f8a772016-08-15 15:30:36 -07009399 hdd_err("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309400 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
9401 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009402}
9403
9404void wlan_hdd_auto_shutdown_enable(hdd_context_t *hdd_ctx, bool enable)
9405{
9406 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309407 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009408 hdd_adapter_t *adapter;
9409 bool ap_connected = false, sta_connected = false;
9410 tHalHandle hal_handle;
9411
9412 hal_handle = hdd_ctx->hHal;
9413 if (hal_handle == NULL)
9414 return;
9415
9416 if (hdd_ctx->config->WlanAutoShutdown == 0)
9417 return;
9418
9419 if (enable == false) {
9420 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309421 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009422 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009423 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309424 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -07009425 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009426 return;
9427 }
9428
9429 /* To enable shutdown timer check conncurrency */
9430 if (cds_concurrent_open_sessions_running()) {
9431 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9432
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309433 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009434 adapter = adapterNode->pAdapter;
9435 if (adapter
9436 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009437 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009438 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
9439 conn_info.connState ==
9440 eConnectionState_Associated) {
9441 sta_connected = true;
9442 break;
9443 }
9444 }
9445 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009446 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009447 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
9448 bApActive == true) {
9449 ap_connected = true;
9450 break;
9451 }
9452 }
9453 status = hdd_get_next_adapter(hdd_ctx,
9454 adapterNode,
9455 &pNext);
9456 adapterNode = pNext;
9457 }
9458 }
9459
9460 if (ap_connected == true || sta_connected == true) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009461 hdd_notice("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009462 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009463 }
Jeff Johnson68755312017-02-10 11:46:55 -08009464
9465 if (sme_set_auto_shutdown_timer(hal_handle,
9466 hdd_ctx->config->WlanAutoShutdown)
9467 != QDF_STATUS_SUCCESS)
9468 hdd_err("Failed to start wlan auto shutdown timer");
9469 else
9470 hdd_notice("Auto Shutdown timer for %d seconds enabled",
9471 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009472}
9473#endif
9474
9475hdd_adapter_t *hdd_get_con_sap_adapter(hdd_adapter_t *this_sap_adapter,
9476 bool check_start_bss)
9477{
9478 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
9479 hdd_adapter_t *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309480 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009481 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
9482
9483 con_sap_adapter = NULL;
9484
9485 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309486 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009487 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009488 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
9489 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009490 adapter != this_sap_adapter) {
9491 if (check_start_bss) {
9492 if (test_bit(SOFTAP_BSS_STARTED,
9493 &adapter->event_flags)) {
9494 con_sap_adapter = adapter;
9495 break;
9496 }
9497 } else {
9498 con_sap_adapter = adapter;
9499 break;
9500 }
9501 }
9502 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
9503 adapterNode = pNext;
9504 }
9505
9506 return con_sap_adapter;
9507}
9508
9509#ifdef MSM_PLATFORM
9510void hdd_start_bus_bw_compute_timer(hdd_adapter_t *adapter)
9511{
9512 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9513
Dustin Brownfce08d12017-01-17 16:29:38 -08009514 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
9515 if (!hdd_ctx->bus_bw_timer_running) {
9516 hdd_ctx->bus_bw_timer_running = true;
9517 qdf_timer_start(&hdd_ctx->bus_bw_timer,
9518 hdd_ctx->config->busBandwidthComputeInterval);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009519
Dustin Brownfce08d12017-01-17 16:29:38 -08009520 }
9521 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
9522
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009523}
9524
9525void hdd_stop_bus_bw_compute_timer(hdd_adapter_t *adapter)
9526{
9527 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309528 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009529 bool can_stop = true;
9530 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9531
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309532 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brownfce08d12017-01-17 16:29:38 -08009533 if (!hdd_ctx->bus_bw_timer_running) {
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309534 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009535 /* trying to stop timer, when not running is not good */
Srinivas Girigowda0ee96442016-08-17 19:10:56 -07009536 hdd_info("bus band width compute timer is not running");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009537 return;
9538 }
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309539 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009540
9541 if (cds_concurrent_open_sessions_running()) {
9542 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9543
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309544 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009545 adapter = adapterNode->pAdapter;
9546 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009547 && (adapter->device_mode == QDF_STA_MODE
9548 || adapter->device_mode == QDF_P2P_CLIENT_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009549 && WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
9550 conn_info.connState ==
9551 eConnectionState_Associated) {
9552 can_stop = false;
9553 break;
9554 }
9555 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009556 && (adapter->device_mode == QDF_SAP_MODE
9557 || adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009558 && WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive ==
9559 true) {
9560 can_stop = false;
9561 break;
9562 }
9563 status = hdd_get_next_adapter(hdd_ctx,
9564 adapterNode,
9565 &pNext);
9566 adapterNode = pNext;
9567 }
9568 }
9569
Ravi Joshib89e7f72016-09-07 13:43:15 -07009570 if (can_stop == true) {
Chris Guoc0c95bf2016-11-10 14:28:25 +08009571 /* reset the ipa perf level */
9572 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
Dustin Brownfce08d12017-01-17 16:29:38 -08009573 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05309574 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08009575 hdd_ctx->bus_bw_timer_running = false;
9576 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Ravi Joshib89e7f72016-09-07 13:43:15 -07009577 hdd_reset_tcp_delack(hdd_ctx);
9578 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009579}
9580#endif
9581
9582/**
9583 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
9584 * and sta's operating channel.
9585 * @sta_adapter: Describe the first argument to foobar.
9586 * @ap_adapter: Describe the second argument to foobar.
9587 * @roam_profile: Roam profile of AP to which STA wants to connect.
9588 * @concurrent_chnl_same: If both SAP and STA channels are same then
9589 * set this flag to true else false.
9590 *
9591 * This function checks the sap's operating channel and sta's operating channel.
9592 * if both are same then it will return false else it will restart the sap in
9593 * sta's channel and return true.
9594 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309595 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009596 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309597QDF_STATUS wlan_hdd_check_custom_con_channel_rules(hdd_adapter_t *sta_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009598 hdd_adapter_t *ap_adapter,
9599 tCsrRoamProfile *roam_profile,
9600 tScanResultHandle *scan_cache,
9601 bool *concurrent_chnl_same)
9602{
9603 hdd_ap_ctx_t *hdd_ap_ctx;
9604 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309605 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009606 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009607 *concurrent_chnl_same = true;
9608
9609 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
9610 status =
9611 sme_get_ap_channel_from_scan_cache(WLAN_HDD_GET_HAL_CTX(sta_adapter),
9612 roam_profile,
9613 scan_cache,
9614 &channel_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309615 if ((QDF_STATUS_SUCCESS == status)) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009616 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009617 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
9618 if (hdd_ap_ctx->operatingChannel != channel_id) {
9619 *concurrent_chnl_same = false;
Jeff Johnson28f8a772016-08-15 15:30:36 -07009620 hdd_info("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009621 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009622 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009623 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
9624 if (hdd_ap_ctx->operatingChannel != channel_id) {
9625 *concurrent_chnl_same = false;
Jeff Johnson28f8a772016-08-15 15:30:36 -07009626 hdd_info("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009627 }
9628 }
9629 } else {
9630 /*
9631 * Lets handle worst case scenario here, Scan cache lookup is
9632 * failed so we have to stop the SAP to avoid any channel
9633 * discrepancy between SAP's channel and STA's channel.
9634 * Return the status as failure so caller function could know
9635 * that scan look up is failed.
9636 */
Jeff Johnson28f8a772016-08-15 15:30:36 -07009637 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309638 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009639 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309640 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009641}
9642
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009643/**
9644 * wlan_hdd_stop_sap() - This function stops bss of SAP.
9645 * @ap_adapter: SAP adapter
9646 *
9647 * This function will process the stopping of sap adapter.
9648 *
9649 * Return: None
9650 */
9651void wlan_hdd_stop_sap(hdd_adapter_t *ap_adapter)
9652{
9653 hdd_ap_ctx_t *hdd_ap_ctx;
9654 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +05309655 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009656 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009657
9658 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009659 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009660 return;
9661 }
9662
9663 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
9664 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05309665 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009666 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05309667
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009668 mutex_lock(&hdd_ctx->sap_lock);
9669 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -08009670 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009671 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
9672 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnson28f8a772016-08-15 15:30:36 -07009673 hdd_info("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309674 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309675 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009676 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +05309677 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08009678 qdf_stop_bss_event,
9679 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +05309680 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009681 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -07009682 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009683 return;
9684 }
9685 }
9686 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyya4adb3682016-01-07 15:07:12 -08009687 cds_decr_session_set_pcl(ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009688 ap_adapter->sessionId);
Jeff Johnson28f8a772016-08-15 15:30:36 -07009689 hdd_info("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009690 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009691 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009692 }
9693 mutex_unlock(&hdd_ctx->sap_lock);
9694 return;
9695}
9696
9697/**
9698 * wlan_hdd_start_sap() - this function starts bss of SAP.
9699 * @ap_adapter: SAP adapter
9700 *
9701 * This function will process the starting of sap adapter.
9702 *
9703 * Return: None
9704 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05309705void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009706{
9707 hdd_ap_ctx_t *hdd_ap_ctx;
9708 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +05309709 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009710 hdd_context_t *hdd_ctx;
9711 tsap_Config_t *sap_config;
9712
9713 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009714 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009715 return;
9716 }
9717
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009718 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -07009719 hdd_err("SoftAp role has not been enabled");
9720 return;
9721 }
9722
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009723 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
9724 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
9725 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
9726 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
9727
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009728 mutex_lock(&hdd_ctx->sap_lock);
9729 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
9730 goto end;
9731
9732 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009733 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009734 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
9735 goto end;
9736 }
9737
Wei Song2f76f642016-11-18 16:32:53 +08009738 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009739 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
9740 &hdd_ap_ctx->sapConfig,
9741 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309742 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009743 goto end;
9744
Jeff Johnson28f8a772016-08-15 15:30:36 -07009745 hdd_info("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309746 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08009747 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +05309748 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009749 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009750 goto end;
9751 }
Jeff Johnson28f8a772016-08-15 15:30:36 -07009752 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009753 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -08009754 if (hostapd_state->bssState == BSS_START)
9755 cds_incr_active_session(ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009756 ap_adapter->sessionId);
9757 hostapd_state->bCommit = true;
9758
9759end:
9760 mutex_unlock(&hdd_ctx->sap_lock);
9761 return;
9762}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009763
9764/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -08009765 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
9766 * mac scan config
9767 * @status: Status of set antenna mode
9768 *
9769 * Callback on setting the dual mac configuration
9770 *
9771 * Return: None
9772 */
9773void wlan_hdd_soc_set_antenna_mode_cb(
9774 enum set_antenna_mode_status status)
9775{
9776 hdd_context_t *hdd_ctx;
9777
9778 hdd_info("Status: %d", status);
9779
9780 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9781 if (0 != wlan_hdd_validate_context(hdd_ctx))
9782 return;
9783
9784 /* Signal the completion of set dual mac config */
9785 complete(&hdd_ctx->set_antenna_mode_cmpl);
9786}
9787
9788/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009789 * hdd_get_fw_version() - Get FW version
9790 * @hdd_ctx: pointer to HDD context.
9791 * @major_spid: FW version - major spid.
9792 * @minor_spid: FW version - minor spid
9793 * @ssid: FW version - ssid
9794 * @crmid: FW version - crmid
9795 *
9796 * This function is called to get the firmware build version stored
9797 * as part of the HDD context
9798 *
9799 * Return: None
9800 */
9801void hdd_get_fw_version(hdd_context_t *hdd_ctx,
9802 uint32_t *major_spid, uint32_t *minor_spid,
9803 uint32_t *siid, uint32_t *crmid)
9804{
9805 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
9806 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
9807 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
9808 *crmid = hdd_ctx->target_fw_version & 0x7fff;
9809}
9810
9811#ifdef QCA_CONFIG_SMP
9812/**
9813 * wlan_hdd_get_cpu() - get cpu_index
9814 *
9815 * Return: cpu_index
9816 */
9817int wlan_hdd_get_cpu(void)
9818{
9819 int cpu_index = get_cpu();
9820 put_cpu();
9821 return cpu_index;
9822}
9823#endif
9824
9825/**
9826 * hdd_get_fwpath() - get framework path
9827 *
9828 * This function is used to get the string written by
9829 * userspace to start the wlan driver
9830 *
9831 * Return: string
9832 */
9833const char *hdd_get_fwpath(void)
9834{
9835 return fwpath.string;
9836}
9837
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009838/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009839 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009840 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009841 * This function initilizes CDS global context with the help of cds_init. This
9842 * has to be the first function called after probe to get a valid global
9843 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009844 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009845 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009846 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009847int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009848{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009849 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009850 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009851
Houston Hoffman9e06e542016-12-12 12:06:26 -08009852 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009853#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9854 wlan_logging_sock_init_svc();
9855#endif
9856
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009857 if (p_cds_context == NULL) {
9858 hdd_alert("Failed to allocate CDS context");
9859 ret = -ENOMEM;
9860 goto err_out;
9861 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009862
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009863 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309864 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009865
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009866err_out:
9867 return ret;
9868}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009869
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009870/**
9871 * hdd_deinit() - Deinitialize Driver
9872 *
9873 * This function frees CDS global context with the help of cds_deinit. This
9874 * has to be the last function call in remove callback to free the global
9875 * context.
9876 */
9877void hdd_deinit(void)
9878{
9879 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009880
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009881#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9882 wlan_logging_sock_deinit_svc();
9883#endif
9884}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009885
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009886#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009887
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009888/**
9889 * __hdd_module_init - Module init helper
9890 *
9891 * Module init helper function used by both module and static driver.
9892 *
9893 * Return: 0 for success, errno on failure
9894 */
9895static int __hdd_module_init(void)
9896{
9897 int ret = 0;
Arun Khandavalli13cb5da2017-01-19 15:43:52 +05309898 unsigned long rc;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009899
Arun Khandavallifae92942016-08-01 13:31:08 +05309900 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009901 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009902
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -07009903 pld_init();
9904
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309905 ret = hdd_init();
9906 if (ret) {
9907 pr_err("hdd_init failed %x\n", ret);
9908 goto err_hdd_init;
9909 }
9910
Rajeev Kumar97767a02016-11-30 11:20:40 -08009911 dispatcher_init();
9912
Anurag Chouhana37b5b72016-02-21 14:53:42 +05309913 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009914
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009915 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009916
Arun Khandavalli13cb5da2017-01-19 15:43:52 +05309917 init_completion(&wlan_start_comp);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009918 ret = wlan_hdd_register_driver();
9919 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -07009920 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
9921 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009922 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009923 }
9924
Arun Khandavalli13cb5da2017-01-19 15:43:52 +05309925 rc = wait_for_completion_timeout(&wlan_start_comp,
9926 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
9927
9928 if (!rc) {
9929 hdd_alert("Timed-out waiting for wlan_hdd_register_driver");
9930 QDF_BUG(0);
9931 goto out;
9932 }
9933
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05309934 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009935
9936 return 0;
9937out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05309938 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -08009939 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309940 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -08009941
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309942err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -07009943 pld_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -08009944
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009945 return ret;
9946}
9947
9948/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +05309949 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
9950 *
9951 * Block the unloading of the driver until the cds recovery is completed
9952 *
9953 * Return: None
9954 */
9955static void hdd_wait_for_recovery_completion(void)
9956{
9957 int retry = 0;
9958
9959 /* Wait for recovery to complete */
9960 while (cds_is_driver_recovering()) {
9961 hdd_alert("Recovery in progress; wait here!!!");
9962 msleep(1000);
9963 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
9964 hdd_alert("SSR never completed, fatal error");
9965 QDF_BUG(0);
9966 }
9967 }
9968}
9969
9970/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009971 * __hdd_module_exit - Module exit helper
9972 *
9973 * Module exit helper function used by both module and static driver.
9974 */
9975static void __hdd_module_exit(void)
9976{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05309977 int qdf_print_idx = -1;
9978
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009979 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
9980 QWLAN_VERSIONSTR);
9981
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +05309982 hdd_wait_for_recovery_completion();
9983
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009984 wlan_hdd_unregister_driver();
9985
Anurag Chouhana37b5b72016-02-21 14:53:42 +05309986 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009987
Rajeev Kumar97767a02016-11-30 11:20:40 -08009988 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +05309989 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -07009990 pld_deinit();
9991
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05309992 qdf_print_idx = qdf_get_pidx();
9993 qdf_print_ctrl_cleanup(qdf_print_idx);
9994
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009995 return;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009996}
9997
Arun Khandavallifae92942016-08-01 13:31:08 +05309998#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -08009999/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010000 * wlan_boot_cb() - Wlan boot callback
10001 * @kobj: object whose directory we're creating the link in.
10002 * @attr: attribute the user is interacting with
10003 * @buff: the buffer containing the user data
10004 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010005 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010006 * This callback is invoked when the fs is ready to start the
10007 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010008 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010009 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010010 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010011static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010012 struct kobj_attribute *attr,
10013 const char *buf,
10014 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010015{
Arun Khandavallifae92942016-08-01 13:31:08 +053010016
Arun Khandavallifae92942016-08-01 13:31:08 +053010017 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010018 pr_err("%s: wlan driver already initialized\n", __func__);
10019 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053010020 }
10021
Arun Khandavallifae92942016-08-01 13:31:08 +053010022 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010023 pr_err("%s: wlan driver initialization failed\n", __func__);
10024 return -EIO;
10025 }
10026
10027 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053010028
10029 return count;
10030
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010031}
Arun Khandavallifae92942016-08-01 13:31:08 +053010032
10033/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010034 * hdd_sysfs_cleanup() - cleanup sysfs
10035 *
10036 * Return: None
10037 *
10038 */
10039static void hdd_sysfs_cleanup(void)
10040{
10041
10042 /* remove from group */
10043 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
10044 sysfs_remove_group(wlan_loader->boot_wlan_obj,
10045 wlan_loader->attr_group);
10046
10047 /* unlink the object from parent */
10048 kobject_del(wlan_loader->boot_wlan_obj);
10049
10050 /* free the object */
10051 kobject_put(wlan_loader->boot_wlan_obj);
10052
10053 kfree(wlan_loader->attr_group);
10054 kfree(wlan_loader);
10055
10056 wlan_loader = NULL;
10057}
10058
10059/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010060 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
10061 * ready
10062 *
10063 * This is creates the syfs entry boot_wlan. Which shall be invoked
10064 * when the filesystem is ready.
10065 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010066 * QDF API cannot be used here since this function is called even before
10067 * initializing WLAN driver.
10068 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070010069 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053010070 */
10071static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010072{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010073 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053010074
10075 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
10076 if (!wlan_loader) {
10077 pr_err("%s: memory alloc failed\n", __func__);
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010078 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053010079 }
10080
10081 wlan_loader->boot_wlan_obj = NULL;
10082 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
10083 GFP_KERNEL);
10084 if (!wlan_loader->attr_group) {
10085 pr_err("%s: malloc attr_group failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053010086 goto error_return;
10087 }
10088
10089 wlan_loader->loaded_state = 0;
10090 wlan_loader->attr_group->attrs = attrs;
10091
10092 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
10093 kernel_kobj);
10094 if (!wlan_loader->boot_wlan_obj) {
10095 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053010096 goto error_return;
10097 }
10098
10099 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
10100 wlan_loader->attr_group);
10101 if (ret) {
10102 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
10103 goto error_return;
10104 }
10105
10106 return 0;
10107
10108error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010109 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053010110
10111 return ret;
10112}
10113
10114/**
10115 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
10116 *
10117 * Return: 0 on success or errno on failure
10118 */
10119static int wlan_deinit_sysfs(void)
10120{
Arun Khandavallifae92942016-08-01 13:31:08 +053010121 if (!wlan_loader) {
10122 hdd_alert("wlan loader context is Null!");
10123 return -EINVAL;
10124 }
10125
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010126 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010127 return 0;
10128}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010129
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010130#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053010131
10132#ifdef MODULE
10133/**
10134 * __hdd_module_init - Module init helper
10135 *
10136 * Module init helper function used by both module and static driver.
10137 *
10138 * Return: 0 for success, errno on failure
10139 */
10140static int hdd_module_init(void)
10141{
10142 int ret = 0;
10143
10144 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
10145 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
10146
10147 if (__hdd_module_init()) {
10148 pr_err("%s: Failed to register handler\n", __func__);
10149 ret = -EINVAL;
10150 }
10151
10152 return ret;
10153}
10154#else
10155static int __init hdd_module_init(void)
10156{
10157 int ret = -EINVAL;
10158
10159 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070010160 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053010161 pr_err("Failed to create sysfs entry for loading wlan");
10162
10163 return ret;
10164}
10165#endif
10166
10167
10168#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010169/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010170 * hdd_module_exit() - Exit function
10171 *
10172 * This is the driver exit point (invoked when module is unloaded using rmmod)
10173 *
10174 * Return: None
10175 */
10176static void __exit hdd_module_exit(void)
10177{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010178 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010179}
Arun Khandavallifae92942016-08-01 13:31:08 +053010180#else
10181static void __exit hdd_module_exit(void)
10182{
10183 __hdd_module_exit();
10184 wlan_deinit_sysfs();
10185}
10186#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010187
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010188static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
10189{
10190 return param_set_copystring(kmessage, kp);
10191}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010192
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010193/**
10194 * is_con_mode_valid() check con mode is valid or not
10195 * @mode: global con mode
10196 *
10197 * Return: TRUE on success FALSE on failure
10198 */
10199static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
10200{
10201 switch (mode) {
10202 case QDF_GLOBAL_MONITOR_MODE:
10203 case QDF_GLOBAL_FTM_MODE:
10204 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010205 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010206 return true;
10207 default:
10208 return false;
10209 }
10210}
10211
10212/**
10213 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
10214 * @mode: global con mode
10215 *
10216 * Return: adapter mode
10217 */
10218static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
10219 enum tQDF_GLOBAL_CON_MODE mode)
10220{
10221
10222 switch (mode) {
10223 case QDF_GLOBAL_MISSION_MODE:
10224 return QDF_STA_MODE;
10225 case QDF_GLOBAL_MONITOR_MODE:
10226 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010227 case QDF_GLOBAL_EPPING_MODE:
10228 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010229 case QDF_GLOBAL_FTM_MODE:
10230 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010231 case QDF_GLOBAL_QVIT_MODE:
10232 return QDF_QVIT_MODE;
10233 default:
10234 return QDF_MAX_NO_OF_MODE;
10235 }
10236}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010237
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010238static void hdd_cleanup_present_mode(hdd_context_t *hdd_ctx,
10239 enum tQDF_GLOBAL_CON_MODE curr_mode)
10240{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053010241 int driver_status;
10242
10243 driver_status = hdd_ctx->driver_status;
10244
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010245 switch (curr_mode) {
10246 case QDF_GLOBAL_MISSION_MODE:
10247 case QDF_GLOBAL_MONITOR_MODE:
10248 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053010249 if (driver_status != DRIVER_MODULES_CLOSED) {
10250 hdd_abort_mac_scan_all_adapters(hdd_ctx);
10251 hdd_stop_all_adapters(hdd_ctx);
10252 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010253 hdd_deinit_all_adapters(hdd_ctx, false);
10254 hdd_close_all_adapters(hdd_ctx, false);
10255 break;
10256 case QDF_GLOBAL_EPPING_MODE:
10257 epping_disable();
10258 epping_close();
10259 break;
10260 default:
10261 return;
10262 }
10263}
10264
10265static int hdd_register_req_mode(hdd_context_t *hdd_ctx,
10266 enum tQDF_GLOBAL_CON_MODE mode)
10267{
10268 hdd_adapter_t *adapter;
10269 int ret = 0;
10270 bool rtnl_held;
10271 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10272 QDF_STATUS status;
10273
10274 if (!qdf_dev) {
10275 hdd_err("qdf device context is Null return!");
10276 return -EINVAL;
10277 }
10278
10279 rtnl_held = hdd_hold_rtnl_lock();
10280 switch (mode) {
10281 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080010282 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10283 if (ret)
10284 hdd_alert("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010285 break;
10286 case QDF_GLOBAL_FTM_MODE:
10287 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
10288 wlan_hdd_get_intf_addr(hdd_ctx),
10289 NET_NAME_UNKNOWN, rtnl_held);
10290 if (adapter == NULL)
10291 ret = -EINVAL;
10292 break;
10293 case QDF_GLOBAL_MONITOR_MODE:
10294 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
10295 wlan_hdd_get_intf_addr(hdd_ctx),
10296 NET_NAME_UNKNOWN, rtnl_held);
10297 if (adapter == NULL)
10298 ret = -EINVAL;
10299 break;
10300 case QDF_GLOBAL_EPPING_MODE:
10301 status = epping_open();
10302 if (status != QDF_STATUS_SUCCESS) {
10303 hdd_err("Failed to open in eeping mode: %d", status);
10304 ret = -EINVAL;
10305 break;
10306 }
10307 ret = epping_enable(qdf_dev->dev);
10308 if (ret) {
10309 hdd_err("Failed to enable in epping mode : %d", ret);
10310 epping_close();
10311 }
10312 break;
10313 default:
10314 hdd_info("Mode not supported");
10315 ret = -ENOTSUPP;
10316 break;
10317 }
10318 hdd_release_rtnl_lock();
10319 rtnl_held = false;
10320 return ret;
10321}
10322
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010323/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010324 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010325 * @kmessage: con mode name on which driver to be bring up
10326 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010327 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010328 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010329 * This function is invoked when user updates con mode using sys entry,
10330 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010331 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010332 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010333 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010334static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
10335 hdd_context_t *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010336{
10337 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010338 hdd_adapter_t *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010339 enum tQDF_GLOBAL_CON_MODE curr_mode;
10340 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010341
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010342 ret = wlan_hdd_validate_context(hdd_ctx);
10343 if (ret)
10344 return ret;
10345
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010346 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010347
Arun Khandavallifae92942016-08-01 13:31:08 +053010348 hdd_info("con_mode handler: %s", kmessage);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010349 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053010350
Arun Khandavallifae92942016-08-01 13:31:08 +053010351
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010352
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010353 if (!(is_con_mode_valid(con_mode))) {
10354 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010355 ret = -EINVAL;
10356 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010357 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010358
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010359 curr_mode = hdd_get_conparam();
10360 if (curr_mode == con_mode) {
10361 hdd_err("curr mode: %d is same as user triggered mode %d",
10362 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010363 ret = 0;
10364 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010365 }
10366
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010367 /* Cleanup present mode before switching to new mode */
10368 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +053010369
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -070010370 ret = hdd_wlan_stop_modules(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010371 if (ret) {
10372 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010373 goto reset_flags;
10374 }
10375
10376 hdd_set_conparam(con_mode);
10377
10378 /* Register for new con_mode & then kick_start modules again */
10379 ret = hdd_register_req_mode(hdd_ctx, con_mode);
10380 if (ret) {
10381 hdd_err("Failed to register for new mode");
10382 goto reset_flags;
10383 }
10384
10385 adapter_mode = hdd_get_adpter_mode(con_mode);
10386 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
10387 hdd_err("invalid adapter");
10388 ret = -EINVAL;
10389 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010390 }
10391
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010392 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053010393 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010394 hdd_err("Failed to get adapter:%d", adapter_mode);
10395 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010396 }
10397
10398 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
10399 if (ret) {
10400 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010401 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010402 }
10403
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010404 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
10405 con_mode == QDF_GLOBAL_FTM_MODE) {
10406 if (hdd_start_adapter(adapter)) {
10407 hdd_err("Failed to start %s adapter", kmessage);
10408 ret = -EINVAL;
10409 goto reset_flags;
10410 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010411 }
10412
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010413 hdd_info("Mode successfully changed to %s", kmessage);
10414 ret = 0;
10415
10416reset_flags:
10417 cds_set_load_in_progress(false);
10418 return ret;
10419}
10420
10421
10422static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
10423{
10424 int ret;
10425 hdd_context_t *hdd_ctx;
10426
10427 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10428 ret = wlan_hdd_validate_context(hdd_ctx);
10429 if (ret)
10430 return ret;
10431
10432 cds_ssr_protect(__func__);
10433 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
10434 cds_ssr_unprotect(__func__);
10435
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010436 return ret;
10437}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010438
10439/**
10440 * hdd_get_conparam() - driver exit point
10441 *
10442 * This is the driver exit point (invoked when module is unloaded using rmmod)
10443 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053010444 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010445 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053010446enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010447{
Anurag Chouhan6d760662016-02-20 16:05:43 +053010448 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010449}
10450
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080010451void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010452{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080010453 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010454}
10455
Komal Seelamc11bb222016-01-27 18:57:10 +053010456/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053010457 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
10458 * @hdd_ctx: HDD context
10459 *
10460 * Cleans up the pre cac interface, if it exists
10461 *
10462 * Return: None
10463 */
10464void hdd_clean_up_pre_cac_interface(hdd_context_t *hdd_ctx)
10465{
10466 uint8_t session_id;
10467 QDF_STATUS status;
10468 struct hdd_adapter_s *precac_adapter;
10469
10470 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
10471 if (QDF_IS_STATUS_ERROR(status)) {
10472 hdd_err("failed to get pre cac vdev id");
10473 return;
10474 }
10475
10476 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
10477 if (!precac_adapter) {
10478 hdd_err("invalid pre cac adapater");
10479 return;
10480 }
10481
10482 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
10483 wlan_hdd_sap_pre_cac_failure,
10484 (void *)precac_adapter);
10485 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
10486
10487}
10488
10489/**
Komal Seelamec702b02016-02-24 18:42:16 +053010490 * hdd_update_ol_config - API to update ol configuration parameters
10491 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053010492 *
Komal Seelamc11bb222016-01-27 18:57:10 +053010493 * Return: void
10494 */
Komal Seelamec702b02016-02-24 18:42:16 +053010495static void hdd_update_ol_config(hdd_context_t *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053010496{
Komal Seelamec702b02016-02-24 18:42:16 +053010497 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053010498 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053010499
Komal Seelamec702b02016-02-24 18:42:16 +053010500 if (!ol_ctx)
10501 return;
10502
10503 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
10504 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
10505 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
10506 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070010507 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053010508
10509 ol_init_ini_config(ol_ctx, &cfg);
10510}
10511
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070010512#ifdef FEATURE_RUNTIME_PM
10513/**
10514 * hdd_populate_runtime_cfg() - populate runtime configuration
10515 * @hdd_ctx: hdd context
10516 * @cfg: pointer to the configuration memory being populated
10517 *
10518 * Return: void
10519 */
10520static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
10521 struct hif_config_info *cfg)
10522{
10523 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
10524 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
10525}
10526#else
10527static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
10528 struct hif_config_info *cfg)
10529{
10530}
10531#endif
10532
Komal Seelamec702b02016-02-24 18:42:16 +053010533/**
10534 * hdd_update_hif_config - API to update HIF configuration parameters
10535 * @hdd_ctx: HDD Context
10536 *
10537 * Return: void
10538 */
10539static void hdd_update_hif_config(hdd_context_t *hdd_ctx)
10540{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053010541 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053010542 struct hif_config_info cfg;
10543
10544 if (!scn)
10545 return;
10546
10547 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070010548 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053010549 hif_init_ini_config(scn, &cfg);
10550}
10551
10552/**
10553 * hdd_update_config() - Initialize driver per module ini parameters
10554 * @hdd_ctx: HDD Context
10555 *
10556 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010557 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053010558 */
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010559int hdd_update_config(hdd_context_t *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053010560{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010561 int ret;
10562
Komal Seelamec702b02016-02-24 18:42:16 +053010563 hdd_update_ol_config(hdd_ctx);
10564 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010565 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
10566 ret = hdd_update_cds_config_ftm(hdd_ctx);
10567 else
10568 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080010569 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053010570
10571 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053010572}
10573
Mukul Sharma9d797a02017-01-05 20:26:03 +053010574#ifdef FEATURE_WLAN_RA_FILTERING
10575/**
10576 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
10577 * @psoc_cfg: pmo psoc Configuration
10578 * @hdd_ctx: Pointer to hdd context
10579 *
10580 * Return: none
10581 */
10582static inline void hdd_ra_populate_pmo_config(
10583 struct pmo_psoc_cfg *psoc_cfg,
10584 hdd_context_t *hdd_ctx)
10585{
10586 psoc_cfg->ra_ratelimit_interval =
10587 hdd_ctx->config->RArateLimitInterval;
10588 psoc_cfg->ra_ratelimit_enable =
10589 hdd_ctx->config->IsRArateLimitEnabled;
10590}
10591#else
10592static inline void hdd_ra_populate_pmo_config(
10593 struct cds_config_info *cds_cfg,
10594 hdd_context_t *hdd_ctx)
10595{
10596}
10597#endif
10598/**
10599 * hdd_update_pmo_config - API to update pmo configuration parameters
10600 * @hdd_ctx: HDD context
10601 *
10602 * Return: void
10603 */
10604static int hdd_update_pmo_config(hdd_context_t *hdd_ctx)
10605{
10606 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
10607 struct pmo_psoc_cfg psoc_cfg;
10608 QDF_STATUS status;
10609
10610 /*
10611 * Value of hdd_ctx->wowEnable can be,
10612 * 0 - Disable both magic pattern match and pattern byte match.
10613 * 1 - Enable magic pattern match on all interfaces.
10614 * 2 - Enable pattern byte match on all interfaces.
10615 * 3 - Enable both magic patter and pattern byte match on
10616 * all interfaces.
10617 */
10618 psoc_cfg.magic_ptrn_enable =
10619 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
10620 psoc_cfg.ptrn_match_enable_all_vdev =
10621 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
10622 psoc_cfg.bpf_enable =
10623 hdd_ctx->config->bpf_packet_filter_enable;
10624 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
10625 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
10626 if (hdd_ctx->config->fhostNSOffload)
10627 psoc_cfg.ns_offload_enable_dynamic = true;
10628 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
10629 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
10630 psoc_cfg.active_mode_offload =
10631 hdd_ctx->config->active_mode_offload;
10632 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
10633 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053010634 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
10635 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
10636 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
10637 psoc_cfg.power_save_mode =
10638 hdd_ctx->config->enablePowersaveOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053010639
10640 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053010641 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
10642 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053010643 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
10644 if (status != QDF_STATUS_SUCCESS) {
10645 hdd_err("failed pmo psoc configuration");
10646 return -EINVAL;
10647 }
10648
10649 return 0;
10650}
10651
Abhishek Singh257a9482017-03-06 16:52:39 +053010652#ifdef NAPIER_SCAN
10653/**
10654 * hdd_update_scan_config - API to update scan configuration parameters
10655 * @hdd_ctx: HDD context
10656 *
10657 * Return: 0 if success else err
10658 */
10659static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
10660{
10661 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
10662 struct scan_user_cfg scan_cfg;
10663 struct hdd_config *cfg = hdd_ctx->config;
10664 QDF_STATUS status;
10665
10666 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
10667 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
10668 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
10669 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
10670 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
10671 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
10672 scan_cfg.conc_idle_time = cfg->idle_time_conc;
10673 scan_cfg.scan_cache_aging_time = cfg->scanAgingTimeout;
10674 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
10675
10676 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
10677 if (status != QDF_STATUS_SUCCESS) {
10678 hdd_err("failed pmo psoc configuration");
10679 return -EINVAL;
10680 }
10681
10682 return 0;
10683}
10684#else
10685static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
10686{
10687 return 0;
10688}
10689#endif
10690
Mukul Sharma9d797a02017-01-05 20:26:03 +053010691int hdd_update_components_config(hdd_context_t *hdd_ctx)
10692{
10693 int ret;
10694
10695 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053010696 if (ret)
10697 return ret;
10698 ret = hdd_update_scan_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053010699
10700 return ret;
10701}
10702
Agrawal Ashish65634612016-08-18 13:24:32 +053010703/**
10704 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
10705 * @mode : cfg80211 DFS mode
10706 *
10707 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
10708 */
10709enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
10710{
10711 switch (mode) {
10712 case DFS_MODE_ENABLE:
10713 return ACS_DFS_MODE_ENABLE;
10714 break;
10715 case DFS_MODE_DISABLE:
10716 return ACS_DFS_MODE_DISABLE;
10717 break;
10718 case DFS_MODE_DEPRIORITIZE:
10719 return ACS_DFS_MODE_DEPRIORITIZE;
10720 break;
10721 default:
10722 hdd_err("ACS dfs mode is NONE");
10723 return ACS_DFS_MODE_NONE;
10724 }
10725}
10726
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010727/**
10728 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
10729 * @hddctx: pointer to hdd context
10730 * @set_value: enable/disable
10731 *
10732 * When Host sends vendor command enable, FW will send *ONE* CA ind to
10733 * Host(even though it is duplicate). When Host send vendor command
10734 * disable,FW doesn't perform any action. Whenever any change in
10735 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
10736 *
10737 * return - 0 on success, appropriate error values on failure.
10738 */
10739int hdd_enable_disable_ca_event(hdd_context_t *hddctx, uint8_t set_value)
10740{
10741 QDF_STATUS status;
10742
10743 if (0 != wlan_hdd_validate_context(hddctx)) {
10744 return -EAGAIN;
10745 }
10746
10747 if (!hddctx->config->goptimize_chan_avoid_event) {
10748 hdd_warn("goptimize_chan_avoid_event ini param disabled");
10749 return -EINVAL;
10750 }
10751
10752 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
10753 if (!QDF_IS_STATUS_SUCCESS(status)) {
10754 hdd_err("Failed to send chan avoid command to SME");
10755 return -EINVAL;
10756 }
10757 return 0;
10758}
Agrawal Ashish65634612016-08-18 13:24:32 +053010759
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010760/**
10761 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
10762 * @value: value to set
10763 *
10764 * This function will set the passed value to roaming in progress flag.
10765 *
10766 * Return: None
10767 */
10768void hdd_set_roaming_in_progress(bool value)
10769{
10770 hdd_context_t *hdd_ctx;
10771
10772 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10773 if (!hdd_ctx) {
10774 hdd_err("HDD context is NULL");
10775 return;
10776 }
10777
10778 hdd_ctx->roaming_in_progress = value;
10779 hdd_info("Roaming in Progress set to %d", value);
10780}
10781
10782/**
10783 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080010784 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010785 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080010786 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010787 */
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080010788bool hdd_is_roaming_in_progress(hdd_adapter_t *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010789{
10790 hdd_context_t *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080010791 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010792
10793 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10794 if (!hdd_ctx) {
10795 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080010796 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010797 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080010798 hdd_info("dev mode = %d, roaming_in_progress = %d",
10799 adapter->device_mode, hdd_ctx->roaming_in_progress);
10800 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
10801 hdd_ctx->roaming_in_progress);
10802
10803 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080010804}
10805
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010806/* Register the module init/exit functions */
10807module_init(hdd_module_init);
10808module_exit(hdd_module_exit);
10809
10810MODULE_LICENSE("Dual BSD/GPL");
10811MODULE_AUTHOR("Qualcomm Atheros, Inc.");
10812MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
10813
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
10815 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010816
10817module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
10818 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
10819
10820module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
10821
10822module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
10823
10824module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);