blob: b5bf74cd2d47852b0e6619773bcb850999e8957d [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Poddar, Siddartha78cac32016-12-29 20:08:34 +05302 * 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_power.c
30 *
31 * WLAN power management functions
32 *
33 */
34
35/* Include files */
36
37#include <linux/pm.h>
38#include <linux/wait.h>
39#include <linux/cpu.h>
40#include <wlan_hdd_includes.h>
41#if defined(WLAN_OPEN_SOURCE) && defined(CONFIG_HAS_WAKELOCK)
42#include <linux/wakelock.h>
43#endif
Anurag Chouhan6d760662016-02-20 16:05:43 +053044#include "qdf_types.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080045#include "sme_api.h"
46#include <cds_api.h>
47#include <cds_sched.h>
48#include <mac_init_api.h>
49#include <wlan_qct_sys.h>
50#include <wlan_hdd_main.h>
51#include <wlan_hdd_assoc.h>
52#include <wlan_nlink_srv.h>
53#include <wlan_hdd_misc.h>
54#include <wlan_hdd_power.h>
Jeff Johnsonc8d0c252016-10-05 16:19:50 -070055#include <wlan_hdd_host_offload.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080056#include <dbglog_host.h>
57#include <wlan_hdd_trace.h>
Masti, Narayanraddi3e26de62016-08-19 14:33:22 +053058#include <wlan_hdd_p2p.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
60#include <linux/semaphore.h>
61#include <wlan_hdd_hostapd.h>
62#include "cfg_api.h"
63
64#include <linux/inetdevice.h>
65#include <wlan_hdd_cfg.h>
Sandeep Puligillae390be52016-02-08 17:07:05 -080066#include <wlan_hdd_scan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080067#include <wlan_hdd_cfg80211.h>
68#include <net/addrconf.h>
69#include <wlan_hdd_ipa.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070070#include <wlan_hdd_lpass.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080071
72#include <wma_types.h>
Poddar, Siddartha78cac32016-12-29 20:08:34 +053073#include <ol_txrx_osif_api.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080074#include "hif.h"
75#include "sme_power_save_api.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080076#include "wlan_policy_mgr_api.h"
Dhanashri Atreb08959a2016-03-01 17:28:03 -080077#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu13738502016-04-06 17:41:37 -070078#include "pld_common.h"
Rajeev Kumar9bb2e852016-09-24 12:29:25 -070079#include "wlan_hdd_driver_ops.h"
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +053080#include <wlan_logging_sock_svc.h>
Krunal Sonid32c6bc2016-10-18 18:00:21 -070081#include "scheduler_api.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +053082#include "cds_utils.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083
84/* Preprocessor definitions and constants */
Yue Ma5fe30dd2017-05-02 15:47:40 -070085#ifdef QCA_WIFI_NAPIER_EMULATION
86#define HDD_SSR_BRING_UP_TIME 3000000
87#else
Yue Ma4ea4f052015-10-27 12:25:27 -070088#define HDD_SSR_BRING_UP_TIME 30000
Yue Ma5fe30dd2017-05-02 15:47:40 -070089#endif
Sreelakshmi Konamki22528532016-09-06 16:34:50 +053090#define HDD_WAKE_LOCK_RESUME_DURATION 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091
92/* Type declarations */
93
Abhishek Singhbaea27d2016-04-27 13:29:30 +053094#ifdef FEATURE_WLAN_DIAG_SUPPORT
95/**
96 * hdd_wlan_suspend_resume_event()- send suspend/resume state
97 * @state: suspend/resume state
98 *
99 * This Function send send suspend resume state diag event
100 *
101 * Return: void.
102 */
103void hdd_wlan_suspend_resume_event(uint8_t state)
104{
105 WLAN_HOST_DIAG_EVENT_DEF(suspend_state, struct host_event_suspend);
106 qdf_mem_zero(&suspend_state, sizeof(suspend_state));
107
108 suspend_state.state = state;
109 WLAN_HOST_DIAG_EVENT_REPORT(&suspend_state, EVENT_WLAN_SUSPEND_RESUME);
110}
Abhishek Singh4aad0f72016-04-27 13:43:29 +0530111
112/**
113 * hdd_wlan_offload_event()- send offloads event
114 * @type: offload type
115 * @state: enabled or disabled
116 *
117 * This Function send offloads enable/disable diag event
118 *
119 * Return: void.
120 */
121
122void hdd_wlan_offload_event(uint8_t type, uint8_t state)
123{
124 WLAN_HOST_DIAG_EVENT_DEF(host_offload, struct host_event_offload_req);
125 qdf_mem_zero(&host_offload, sizeof(host_offload));
126
127 host_offload.offload_type = type;
128 host_offload.state = state;
129
130 WLAN_HOST_DIAG_EVENT_REPORT(&host_offload, EVENT_WLAN_OFFLOAD_REQ);
131}
Abhishek Singhbaea27d2016-04-27 13:29:30 +0530132#endif
133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800134/* Function and variables declarations */
135
136extern struct notifier_block hdd_netdev_notifier;
137
138static struct timer_list ssr_timer;
139static bool ssr_timer_started;
Mukul Sharma3d36c392017-01-18 18:39:12 +0530140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800141/**
Mukul Sharma3d36c392017-01-18 18:39:12 +0530142 * hdd_enable_gtk_offload() - enable GTK offload
143 * @adapter: pointer to the adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800144 *
Mukul Sharma3d36c392017-01-18 18:39:12 +0530145 * Central function to enable GTK offload.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800146 *
147 * Return: nothing
148 */
Mukul Sharma3d36c392017-01-18 18:39:12 +0530149static void hdd_enable_gtk_offload(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800150{
Mukul Sharma3d36c392017-01-18 18:39:12 +0530151 QDF_STATUS status;
152 status = pmo_ucfg_enable_gtk_offload_in_fwr(adapter->hdd_vdev);
153 if (status != QDF_STATUS_SUCCESS)
154 hdd_info("Failed to enable gtk offload");
155}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156
Mukul Sharma3d36c392017-01-18 18:39:12 +0530157/**
158 * hdd_disable_gtk_offload() - disable GTK offload
159 * @pAdapter: pointer to the adapter
160 *
161 * Central function to disable GTK offload.
162 *
163 * Return: nothing
164 */
165static void hdd_disable_gtk_offload(hdd_adapter_t *adapter)
166{
167 struct pmo_gtk_rsp_req gtk_rsp_request;
168 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800169
Mukul Sharma3d36c392017-01-18 18:39:12 +0530170 /* ensure to get gtk rsp first before disable it*/
171 gtk_rsp_request.callback =
172 wlan_hdd_cfg80211_update_replay_counter_callback;
173 /* Passing as void* as PMO does not know legacy HDD adapter type */
174 gtk_rsp_request.callback_context =
175 (void *)adapter;
176 status = pmo_ucfg_get_gtk_rsp(adapter->hdd_vdev,
177 &gtk_rsp_request);
178 if (status != QDF_STATUS_SUCCESS) {
179 hdd_err("Failed to send get gtk rsp status:%d", status);
180 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800181 }
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800182 hdd_debug("send get_gtk_rsp successful");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530183 status = pmo_ucfg_disable_gtk_offload_in_fwr(adapter->hdd_vdev);
184 if (status != QDF_STATUS_SUCCESS)
185 hdd_info("Failed to disable gtk offload");
186
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800187}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800188
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800190/**
191 * __wlan_hdd_ipv6_changed() - IPv6 notifier callback function
192 * @nb: notifier block that was registered with the kernel
193 * @data: (unused) generic data that was registered with the kernel
194 * @arg: (unused) generic argument that was registered with the kernel
195 *
196 * This is a callback function that is registered with the kernel via
197 * register_inet6addr_notifier() which allows the driver to be
198 * notified when there is an IPv6 address change.
199 *
200 * Return: NOTIFY_DONE to indicate we don't care what happens with
201 * other callbacks
202 */
203static int __wlan_hdd_ipv6_changed(struct notifier_block *nb,
Dustin Brownf13b8c32017-05-19 17:23:08 -0700204 unsigned long data, void *arg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800205{
206 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
207 struct net_device *ndev = ifa->idev->dev;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700208 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
209 hdd_context_t *hdd_ctx;
210 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800211
Jeff Johnson158c8d02016-10-31 13:11:48 -0700212 ENTER_DEV(ndev);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530213
Dustin Brownf13b8c32017-05-19 17:23:08 -0700214 errno = hdd_validate_adapter(adapter);
215 if (errno)
216 goto exit;
217
218 if (adapter->dev == ndev &&
219 (adapter->device_mode == QDF_STA_MODE ||
220 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
221 adapter->device_mode == QDF_NDI_MODE)) {
222 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
223 errno = wlan_hdd_validate_context(hdd_ctx);
224 if (errno)
225 goto exit;
226
227 hdd_debug("invoking sme_dhcp_done_ind");
228 sme_dhcp_done_ind(hdd_ctx->hHal, adapter->sessionId);
229 schedule_work(&adapter->ipv6NotifierWorkQueue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800230 }
231
Dustin Brownf13b8c32017-05-19 17:23:08 -0700232exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530233 EXIT();
Dustin Brownf13b8c32017-05-19 17:23:08 -0700234
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800235 return NOTIFY_DONE;
236}
237
238/**
239 * wlan_hdd_ipv6_changed() - IPv6 change notifier callback
240 * @nb: pointer to notifier block
241 * @data: data
242 * @arg: arg
243 *
244 * This is the IPv6 notifier callback function gets invoked
245 * if any change in IP and then invoke the function @__wlan_hdd_ipv6_changed
246 * to reconfigure the offload parameters.
247 *
248 * Return: 0 on success, error number otherwise.
249 */
250int wlan_hdd_ipv6_changed(struct notifier_block *nb,
251 unsigned long data, void *arg)
252{
253 int ret;
254
255 cds_ssr_protect(__func__);
256 ret = __wlan_hdd_ipv6_changed(nb, data, arg);
257 cds_ssr_unprotect(__func__);
258
259 return ret;
260}
261
262/**
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530263 * hdd_fill_ipv6_uc_addr() - fill IPv6 unicast addresses
264 * @idev: pointer to net device
265 * @ipv6addr: destination array to fill IPv6 addresses
266 * @ipv6addr_type: IPv6 Address type
267 * @count: number of IPv6 addresses
268 *
269 * This is the IPv6 utility function to populate unicast addresses.
270 *
271 * Return: 0 on success, error number otherwise.
272 */
273static int hdd_fill_ipv6_uc_addr(struct inet6_dev *idev,
274 uint8_t ipv6_uc_addr[][SIR_MAC_IPV6_ADDR_LEN],
275 uint8_t *ipv6addr_type, uint32_t *count)
276{
277 struct inet6_ifaddr *ifa;
278 struct list_head *p;
279 uint32_t scope;
280
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700281 read_lock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530282 list_for_each(p, &idev->addr_list) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530283 if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) {
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700284 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530285 return -EINVAL;
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700286 }
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530287 ifa = list_entry(p, struct inet6_ifaddr, if_list);
288 if (ifa->flags & IFA_F_DADFAILED)
289 continue;
290 scope = ipv6_addr_src_scope(&ifa->addr);
291 switch (scope) {
292 case IPV6_ADDR_SCOPE_GLOBAL:
293 case IPV6_ADDR_SCOPE_LINKLOCAL:
294 qdf_mem_copy(ipv6_uc_addr[*count], &ifa->addr.s6_addr,
295 sizeof(ifa->addr.s6_addr));
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530296 ipv6addr_type[*count] = PMO_IPV6_ADDR_UC_TYPE;
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800297 hdd_debug("Index %d scope = %s UC-Address: %pI6",
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530298 *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ?
299 "LINK LOCAL" : "GLOBAL", ipv6_uc_addr[*count]);
300 *count += 1;
301 break;
302 default:
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800303 hdd_warn("The Scope %d is not supported", scope);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530304 }
305 }
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700306
307 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530308 return 0;
309}
310
311/**
312 * hdd_fill_ipv6_ac_addr() - fill IPv6 anycast addresses
313 * @idev: pointer to net device
314 * @ipv6addr: destination array to fill IPv6 addresses
315 * @ipv6addr_type: IPv6 Address type
316 * @count: number of IPv6 addresses
317 *
318 * This is the IPv6 utility function to populate anycast addresses.
319 *
320 * Return: 0 on success, error number otherwise.
321 */
322static int hdd_fill_ipv6_ac_addr(struct inet6_dev *idev,
323 uint8_t ipv6_ac_addr[][SIR_MAC_IPV6_ADDR_LEN],
324 uint8_t *ipv6addr_type, uint32_t *count)
325{
326 struct ifacaddr6 *ifaca;
327 uint32_t scope;
328
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700329 read_lock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530330 for (ifaca = idev->ac_list; ifaca; ifaca = ifaca->aca_next) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530331 if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) {
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700332 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530333 return -EINVAL;
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700334 }
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530335 /* For anycast addr no DAD */
336 scope = ipv6_addr_src_scope(&ifaca->aca_addr);
337 switch (scope) {
338 case IPV6_ADDR_SCOPE_GLOBAL:
339 case IPV6_ADDR_SCOPE_LINKLOCAL:
340 qdf_mem_copy(ipv6_ac_addr[*count], &ifaca->aca_addr,
341 sizeof(ifaca->aca_addr));
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530342 ipv6addr_type[*count] = PMO_IPV6_ADDR_AC_TYPE;
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800343 hdd_debug("Index %d scope = %s AC-Address: %pI6",
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530344 *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ?
345 "LINK LOCAL" : "GLOBAL", ipv6_ac_addr[*count]);
346 *count += 1;
347 break;
348 default:
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800349 hdd_warn("The Scope %d is not supported", scope);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530350 }
351 }
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700352
353 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530354 return 0;
355}
356
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530357void hdd_enable_ns_offload(hdd_adapter_t *adapter,
358 enum pmo_offload_trigger trigger)
Dustin Brown2444ee62016-09-06 17:20:36 -0700359{
360 struct inet6_dev *in6_dev;
Dustin Brown2444ee62016-09-06 17:20:36 -0700361 QDF_STATUS status;
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530362 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
363 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
364 struct pmo_ns_req *ns_req = NULL;
365 int err;
366
367 ENTER();
368 if (!psoc) {
369 hdd_err("psoc is NULL");
370 goto out;
371 }
Dustin Brown2444ee62016-09-06 17:20:36 -0700372
373 in6_dev = __in6_dev_get(adapter->dev);
374 if (NULL == in6_dev) {
375 hdd_err("IPv6 dev does not exist. Failed to request NSOffload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530376 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700377 }
378
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530379 ns_req = qdf_mem_malloc(sizeof(*ns_req));
380 if (!ns_req) {
381 hdd_err("fail to allocate ns_req");
382 goto out;
383 }
384
385 ns_req->psoc = psoc;
386 ns_req->vdev_id = adapter->sessionId;
387 ns_req->trigger = trigger;
388 ns_req->count = 0;
389
Dustin Brown2444ee62016-09-06 17:20:36 -0700390 /* Unicast Addresses */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530391 err = hdd_fill_ipv6_uc_addr(in6_dev, ns_req->ipv6_addr,
392 ns_req->ipv6_addr_type, &ns_req->count);
Dustin Brown2444ee62016-09-06 17:20:36 -0700393 if (err) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530394 hdd_disable_ns_offload(adapter, trigger);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800395 hdd_debug("Reached max supported addresses and not enabling "
Dustin Brown2444ee62016-09-06 17:20:36 -0700396 "NS offload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530397 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700398 }
399
400 /* Anycast Addresses */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530401 err = hdd_fill_ipv6_ac_addr(in6_dev, ns_req->ipv6_addr,
402 ns_req->ipv6_addr_type, &ns_req->count);
Dustin Brown2444ee62016-09-06 17:20:36 -0700403 if (err) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530404 hdd_disable_ns_offload(adapter, trigger);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800405 hdd_debug("Reached max supported addresses and not enabling "
Dustin Brown2444ee62016-09-06 17:20:36 -0700406 "NS offload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530407 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700408 }
409
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530410 /* cache ns request */
411 status = pmo_ucfg_cache_ns_offload_req(ns_req);
412 if (status != QDF_STATUS_SUCCESS) {
413 hdd_err("Failed to cache ns request status: %d", status);
414 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700415 }
416
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530417 /* enable ns request */
418 status = pmo_ucfg_enable_ns_offload_in_fwr(adapter->hdd_vdev, trigger);
419 if (status != QDF_STATUS_SUCCESS)
Dustin Brown2444ee62016-09-06 17:20:36 -0700420 hdd_err("Failed to enable HostOffload feature with status: %d",
421 status);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530422 else
423 hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD, SIR_OFFLOAD_ENABLE);
424out:
425 if (ns_req)
426 qdf_mem_free(ns_req);
427 EXIT();
428
Dustin Brown2444ee62016-09-06 17:20:36 -0700429}
430
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530431void hdd_disable_ns_offload(hdd_adapter_t *adapter,
432 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433{
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530434 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800435
436 ENTER();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530437 status = pmo_ucfg_flush_ns_offload_req(adapter->hdd_vdev);
438 if (status != QDF_STATUS_SUCCESS) {
439 hdd_err("Failed to flush NS Offload");
440 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800441 }
442
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530443 status = pmo_ucfg_disable_ns_offload_in_fwr(adapter->hdd_vdev, trigger);
444 if (status != QDF_STATUS_SUCCESS)
445 hdd_err("Failed to disable NS Offload");
Dustin Brown2444ee62016-09-06 17:20:36 -0700446 else
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530447 hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD,
448 SIR_OFFLOAD_DISABLE);
449out:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800450 EXIT();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800452}
453
454/**
455 * __hdd_ipv6_notifier_work_queue() - IPv6 notification work function
456 * @work: registered work item
457 *
458 * This function performs the work initially trigged by a callback
459 * from the IPv6 netdev notifier. Since this means there has been a
460 * change in IPv6 state for the interface, the NS offload is
461 * reconfigured.
462 *
463 * Return: None
464 */
Jeff Johnsonc8d0c252016-10-05 16:19:50 -0700465static void __hdd_ipv6_notifier_work_queue(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800466{
Dustin Brownf13b8c32017-05-19 17:23:08 -0700467 hdd_context_t *hdd_ctx;
468 hdd_adapter_t *adapter;
469 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800470
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530471 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800472
Dustin Brownf13b8c32017-05-19 17:23:08 -0700473 adapter = container_of(work, hdd_adapter_t, ipv6NotifierWorkQueue);
474 errno = hdd_validate_adapter(adapter);
475 if (errno)
476 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477
Dustin Brownf13b8c32017-05-19 17:23:08 -0700478 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
479 errno = wlan_hdd_validate_context(hdd_ctx);
480 if (errno)
481 goto exit;
482
483 hdd_enable_ns_offload(adapter, pmo_ipv6_change_notify);
484
485exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530486 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800487}
488
489/**
490 * hdd_ipv6_notifier_work_queue() - IP V6 change notifier work handler
491 * @work: Pointer to work context
492 *
493 * Return: none
494 */
495void hdd_ipv6_notifier_work_queue(struct work_struct *work)
496{
497 cds_ssr_protect(__func__);
498 __hdd_ipv6_notifier_work_queue(work);
499 cds_ssr_unprotect(__func__);
500}
501
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530502void hdd_enable_host_offloads(hdd_adapter_t *adapter,
503 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800504{
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530505 ENTER();
506
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530507 if (!pmo_ucfg_is_vdev_supports_offload(adapter->hdd_vdev)) {
508 hdd_info("offload is not supported on this vdev opmode: %d",
509 adapter->device_mode);
510 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511 }
512
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530513 if (!pmo_ucfg_is_vdev_connected(adapter->hdd_vdev)) {
514 hdd_info("vdev is not connected");
515 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800516 }
517
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530518 hdd_info("enable offloads");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530519 hdd_enable_gtk_offload(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530520 hdd_enable_arp_offload(adapter, trigger);
521 hdd_enable_ns_offload(adapter, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530522 hdd_enable_mc_addr_filtering(adapter, trigger);
Ravi Kumar Bokka794fd712017-03-21 20:52:46 +0530523 hdd_enable_non_arp_hw_broadcast_filter(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530524out:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530525 EXIT();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530526
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800527}
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530528
529void hdd_disable_host_offloads(hdd_adapter_t *adapter,
530 enum pmo_offload_trigger trigger)
531{
532 ENTER();
533
534 if (!pmo_ucfg_is_vdev_supports_offload(adapter->hdd_vdev)) {
535 hdd_info("offload is not supported on this vdev opmode: %d",
536 adapter->device_mode);
537 goto out;
538 }
539
540 if (!pmo_ucfg_is_vdev_connected(adapter->hdd_vdev)) {
541 hdd_info("vdev is not connected");
542 goto out;
543 }
544
545 hdd_info("disable offloads");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530546 hdd_disable_gtk_offload(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530547 hdd_disable_arp_offload(adapter, trigger);
548 hdd_disable_ns_offload(adapter, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530549 hdd_disable_mc_addr_filtering(adapter, trigger);
Ravi Kumar Bokka794fd712017-03-21 20:52:46 +0530550 hdd_disable_non_arp_hw_broadcast_filter(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530551out:
552 EXIT();
553
554}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800555
556/**
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800557 * hdd_lookup_ifaddr() - Lookup interface address data by name
558 * @adapter: the adapter whose name should be searched for
559 *
560 * return in_ifaddr pointer on success, NULL for failure
561 */
562static struct in_ifaddr *hdd_lookup_ifaddr(hdd_adapter_t *adapter)
563{
564 struct in_ifaddr *ifa;
565 struct in_device *in_dev;
566
567 if (!adapter) {
568 hdd_err("adapter is null");
569 return NULL;
570 }
571
572 in_dev = __in_dev_get_rtnl(adapter->dev);
573 if (!in_dev) {
574 hdd_err("Failed to get in_device");
575 return NULL;
576 }
577
578 /* lookup address data by interface name */
579 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
580 if (!strcmp(adapter->dev->name, ifa->ifa_label))
581 return ifa;
582 }
583
584 return NULL;
585}
586
587/**
588 * hdd_populate_ipv4_addr() - Populates the adapter's IPv4 address
589 * @adapter: the adapter whose IPv4 address is desired
590 * @ipv4_addr: the address of the array to copy the IPv4 address into
591 *
592 * return: zero for success; non-zero for failure
593 */
594static int hdd_populate_ipv4_addr(hdd_adapter_t *adapter, uint8_t *ipv4_addr)
595{
596 struct in_ifaddr *ifa;
597 int i;
598
599 if (!adapter) {
600 hdd_err("adapter is null");
601 return -EINVAL;
602 }
603
604 if (!ipv4_addr) {
605 hdd_err("ipv4_addr is null");
606 return -EINVAL;
607 }
608
609 ifa = hdd_lookup_ifaddr(adapter);
610 if (!ifa || !ifa->ifa_local) {
611 hdd_err("ipv4 address not found");
612 return -EINVAL;
613 }
614
615 /* convert u32 to byte array */
616 for (i = 0; i < 4; i++)
617 ipv4_addr[i] = (ifa->ifa_local >> i * 8) & 0xff;
618
619 return 0;
620}
621
622/**
623 * hdd_set_grat_arp_keepalive() - Enable grat APR keepalive
624 * @adapter: the HDD adapter to configure
625 *
626 * This configures gratuitous APR keepalive based on the adapter's current
627 * connection information, specifically IPv4 address and BSSID
628 *
629 * return: zero for success, non-zero for failure
630 */
631static int hdd_set_grat_arp_keepalive(hdd_adapter_t *adapter)
632{
633 QDF_STATUS status;
634 int exit_code;
635 hdd_context_t *hdd_ctx;
636 hdd_station_ctx_t *sta_ctx;
637 tSirKeepAliveReq req = {
638 .packetType = SIR_KEEP_ALIVE_UNSOLICIT_ARP_RSP,
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800639 .dest_macaddr = QDF_MAC_ADDR_BROADCAST_INITIALIZER,
640 };
641
642 if (!adapter) {
643 hdd_err("adapter is null");
644 return -EINVAL;
645 }
646
647 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
648 if (!hdd_ctx) {
649 hdd_err("hdd_ctx is null");
650 return -EINVAL;
651 }
652
653 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
654 if (!sta_ctx) {
655 hdd_err("sta_ctx is null");
656 return -EINVAL;
657 }
658
659 exit_code = hdd_populate_ipv4_addr(adapter, req.hostIpv4Addr);
660 if (exit_code) {
661 hdd_err("Failed to populate ipv4 address");
662 return exit_code;
663 }
664
Dustin Brown6b4643d2017-02-09 12:19:28 -0800665 /* according to RFC5227, sender/target ip address should be the same */
666 qdf_mem_copy(&req.destIpv4Addr, &req.hostIpv4Addr,
667 sizeof(req.destIpv4Addr));
668
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800669 qdf_copy_macaddr(&req.bssid, &sta_ctx->conn_info.bssId);
670 req.timePeriod = hdd_ctx->config->infraStaKeepAlivePeriod;
671 req.sessionId = adapter->sessionId;
672
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800673 hdd_debug("Setting gratuitous ARP keepalive; ipv4_addr:%u.%u.%u.%u",
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800674 req.hostIpv4Addr[0], req.hostIpv4Addr[1],
675 req.hostIpv4Addr[2], req.hostIpv4Addr[3]);
676
677 status = sme_set_keep_alive(hdd_ctx->hHal, req.sessionId, &req);
678 if (QDF_IS_STATUS_ERROR(status)) {
679 hdd_err("Failed to set keepalive");
680 return qdf_status_to_os_return(status);
681 }
682
683 return 0;
684}
685
686/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800687 * __hdd_ipv4_notifier_work_queue() - IPv4 notification work function
688 * @work: registered work item
689 *
690 * This function performs the work initially trigged by a callback
691 * from the IPv4 netdev notifier. Since this means there has been a
692 * change in IPv4 state for the interface, the ARP offload is
693 * reconfigured.
694 *
695 * Return: None
696 */
Jeff Johnsonc8d0c252016-10-05 16:19:50 -0700697static void __hdd_ipv4_notifier_work_queue(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698{
Dustin Brownb6b0f182017-03-08 13:08:27 -0800699 hdd_context_t *hdd_ctx;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700700 hdd_adapter_t *adapter;
701 int errno;
Dustin Brownb6b0f182017-03-08 13:08:27 -0800702
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530703 ENTER();
Dustin Brownb6b0f182017-03-08 13:08:27 -0800704
705 adapter = container_of(work, hdd_adapter_t, ipv4NotifierWorkQueue);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700706 errno = hdd_validate_adapter(adapter);
707 if (errno)
708 goto exit;
Dustin Brownb6b0f182017-03-08 13:08:27 -0800709
710 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700711 errno = wlan_hdd_validate_context(hdd_ctx);
712 if (errno)
713 goto exit;
714
715 hdd_enable_arp_offload(adapter, pmo_ipv4_change_notify);
716
Dustin Brownb6b0f182017-03-08 13:08:27 -0800717 if (hdd_ctx->config->sta_keepalive_method == HDD_STA_KEEPALIVE_GRAT_ARP)
718 hdd_set_grat_arp_keepalive(adapter);
719
Dustin Brownf13b8c32017-05-19 17:23:08 -0700720exit:
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530721 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800722}
723
724/**
725 * hdd_ipv4_notifier_work_queue() - IP V4 change notifier work handler
726 * @work: Pointer to work context
727 *
728 * Return: none
729 */
730void hdd_ipv4_notifier_work_queue(struct work_struct *work)
731{
732 cds_ssr_protect(__func__);
733 __hdd_ipv4_notifier_work_queue(work);
734 cds_ssr_unprotect(__func__);
735}
736
737/**
738 * __wlan_hdd_ipv4_changed() - IPv4 notifier callback function
739 * @nb: notifier block that was registered with the kernel
740 * @data: (unused) generic data that was registered with the kernel
741 * @arg: (unused) generic argument that was registered with the kernel
742 *
743 * This is a callback function that is registered with the kernel via
744 * register_inetaddr_notifier() which allows the driver to be
745 * notified when there is an IPv4 address change.
746 *
747 * Return: NOTIFY_DONE to indicate we don't care what happens with
748 * other callbacks
749 */
750static int __wlan_hdd_ipv4_changed(struct notifier_block *nb,
751 unsigned long data, void *arg)
752{
753 struct in_ifaddr *ifa = (struct in_ifaddr *)arg;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754 struct net_device *ndev = ifa->ifa_dev->dev;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700755 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
756 hdd_context_t *hdd_ctx;
757 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758
Jeff Johnson158c8d02016-10-31 13:11:48 -0700759 ENTER_DEV(ndev);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530760
Dustin Brownf13b8c32017-05-19 17:23:08 -0700761 errno = hdd_validate_adapter(adapter);
762 if (errno)
763 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764
Dustin Brownf13b8c32017-05-19 17:23:08 -0700765 if (adapter->dev == ndev &&
766 (adapter->device_mode == QDF_STA_MODE ||
767 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
768 adapter->device_mode == QDF_NDI_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769
Dustin Brownf13b8c32017-05-19 17:23:08 -0700770 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
771 errno = wlan_hdd_validate_context(hdd_ctx);
772 if (errno)
773 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774
Padma, Santhosh Kumar8392fb42017-03-17 12:35:27 +0530775 hdd_debug("invoking sme_dhcp_done_ind");
Dustin Brownf13b8c32017-05-19 17:23:08 -0700776 sme_dhcp_done_ind(hdd_ctx->hHal, adapter->sessionId);
Abhishek Singhca408032016-09-13 15:26:12 +0530777
Dustin Brownf13b8c32017-05-19 17:23:08 -0700778 if (!hdd_ctx->config->fhostArpOffload) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800779 hdd_debug("Offload not enabled ARPOffload=%d",
Dustin Brownf13b8c32017-05-19 17:23:08 -0700780 hdd_ctx->config->fhostArpOffload);
781 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782 }
783
Dustin Brownf13b8c32017-05-19 17:23:08 -0700784 ifa = hdd_lookup_ifaddr(adapter);
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800785 if (ifa && ifa->ifa_local)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700786 schedule_work(&adapter->ipv4NotifierWorkQueue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787 }
Dustin Brownf13b8c32017-05-19 17:23:08 -0700788
789exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530790 EXIT();
Dustin Brownf13b8c32017-05-19 17:23:08 -0700791
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 return NOTIFY_DONE;
793}
794
795/**
796 * wlan_hdd_ipv4_changed() - IPv4 change notifier callback
797 * @nb: pointer to notifier block
798 * @data: data
799 * @arg: arg
800 *
801 * This is the IPv4 notifier callback function gets invoked
802 * if any change in IP and then invoke the function @__wlan_hdd_ipv4_changed
803 * to reconfigure the offload parameters.
804 *
805 * Return: 0 on success, error number otherwise.
806 */
807int wlan_hdd_ipv4_changed(struct notifier_block *nb,
808 unsigned long data, void *arg)
809{
810 int ret;
811
812 cds_ssr_protect(__func__);
813 ret = __wlan_hdd_ipv4_changed(nb, data, arg);
814 cds_ssr_unprotect(__func__);
815
816 return ret;
817}
818
819/**
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530820 * hdd_get_ipv4_local_interface() - get ipv4 local interafce from iface list
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 * @pAdapter: Adapter context for which ARP offload is to be configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800822 *
823 * Return:
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530824 * ifa - on successful operation,
825 * NULL - on failure of operation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530827static struct in_ifaddr *hdd_get_ipv4_local_interface(
828 hdd_adapter_t *pAdapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829{
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530830 struct in_ifaddr **ifap = NULL;
831 struct in_ifaddr *ifa = NULL;
832 struct in_device *in_dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800833
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530834 in_dev = __in_dev_get_rtnl(pAdapter->dev);
835 if (in_dev) {
836 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
837 ifap = &ifa->ifa_next) {
838 if (!strcmp(pAdapter->dev->name, ifa->ifa_label)) {
839 /* if match break */
840 return ifa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 }
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530843 }
844 ifa = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530846 return ifa;
847}
848
849void hdd_enable_arp_offload(hdd_adapter_t *adapter,
850 enum pmo_offload_trigger trigger)
851{
852 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
853 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
854 QDF_STATUS status;
855 struct pmo_arp_req *arp_req = NULL;
856 struct in_ifaddr *ifa = NULL;
857
858 ENTER();
859 arp_req = qdf_mem_malloc(sizeof(*arp_req));
860 if (!arp_req) {
861 hdd_err("cannot allocate arp_req");
862 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 }
Jeff Johnson68755312017-02-10 11:46:55 -0800864
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530865 arp_req->psoc = psoc;
866 arp_req->vdev_id = adapter->sessionId;
867 arp_req->trigger = trigger;
Jeff Johnson68755312017-02-10 11:46:55 -0800868
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530869 ifa = hdd_get_ipv4_local_interface(adapter);
870 if (ifa && ifa->ifa_local) {
871 arp_req->ipv4_addr = (uint32_t)ifa->ifa_local;
872 status = pmo_ucfg_cache_arp_offload_req(arp_req);
873 if (status == QDF_STATUS_SUCCESS) {
874 status = pmo_ucfg_enable_arp_offload_in_fwr(
875 adapter->hdd_vdev, trigger);
876 if (status == QDF_STATUS_SUCCESS)
877 hdd_wlan_offload_event(
878 PMO_IPV4_ARP_REPLY_OFFLOAD,
879 PMO_OFFLOAD_ENABLE);
880 else
881 hdd_info("fail to enable arp offload in fwr");
882 } else
883 hdd_info("fail to cache arp offload request");
884 } else {
885 hdd_notice("IP Address is not assigned");
886 status = QDF_STATUS_NOT_INITIALIZED;
887 }
888out:
889 if (arp_req)
890 qdf_mem_free(arp_req);
891 EXIT();
892
893}
894
895void hdd_disable_arp_offload(hdd_adapter_t *adapter,
896 enum pmo_offload_trigger trigger)
897{
898 QDF_STATUS status;
899
900 ENTER();
901 status = pmo_ucfg_flush_arp_offload_req(adapter->hdd_vdev);
902 if (status != QDF_STATUS_SUCCESS) {
903 hdd_err("Failed to flush arp Offload");
904 goto out;
Jeff Johnson68755312017-02-10 11:46:55 -0800905 }
906
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530907 status = pmo_ucfg_disable_arp_offload_in_fwr(adapter->hdd_vdev, trigger);
908 if (status == QDF_STATUS_SUCCESS)
909 hdd_wlan_offload_event(PMO_IPV4_ARP_REPLY_OFFLOAD,
910 PMO_OFFLOAD_DISABLE);
911 else
912 hdd_info("fail to disable arp offload");
913out:
914 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915}
916
Ravi Kumar Bokka794fd712017-03-21 20:52:46 +0530917void hdd_enable_non_arp_hw_broadcast_filter(hdd_adapter_t *adapter)
918{
919 QDF_STATUS status;
920
921 ENTER();
922
923 status = pmo_ucfg_enable_non_arp_bcast_filter_in_fwr(
924 adapter->hdd_vdev);
925
926 if (status != QDF_STATUS_SUCCESS)
927 hdd_info("Failed to enable broadcast filter");
928
929 EXIT();
930}
931
932void hdd_disable_non_arp_hw_broadcast_filter(hdd_adapter_t *adapter)
933{
934 QDF_STATUS status;
935
936 ENTER();
937
938 status = pmo_ucfg_disable_non_arp_bcast_filter_in_fwr(
939 adapter->hdd_vdev);
940 if (status != QDF_STATUS_SUCCESS)
941 hdd_info("Failed to disable broadcast filter");
942
943 EXIT();
944}
945
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530946void hdd_enable_mc_addr_filtering(hdd_adapter_t *adapter,
947 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948{
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530949 hdd_context_t *hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
950 QDF_STATUS status;
951 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952
Ravi Joshi24477b72016-07-19 15:45:09 -0700953 ENTER();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530954 if (wlan_hdd_validate_context(hdd_ctx))
955 goto out;
Ravi Joshi24477b72016-07-19 15:45:09 -0700956
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530957 status = pmo_ucfg_enable_mc_addr_filtering_in_fwr(psoc,
958 adapter->sessionId, trigger);
959 if (status != QDF_STATUS_SUCCESS)
960 hdd_info("failed to enable mc list status %d", status);
961out:
Ravi Joshi24477b72016-07-19 15:45:09 -0700962 EXIT();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964}
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530965
966void hdd_disable_mc_addr_filtering(hdd_adapter_t *adapter,
967 enum pmo_offload_trigger trigger)
968{
969 hdd_context_t *hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
970 QDF_STATUS status = QDF_STATUS_SUCCESS;
971 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
972
973 ENTER();
974 if (wlan_hdd_validate_context(hdd_ctx))
975 goto out;
976
977 status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc,
978 adapter->sessionId, trigger);
979 if (status != QDF_STATUS_SUCCESS)
980 hdd_info("failed to disable mc list status %d", status);
981out:
982 EXIT();
983
984}
985
986int hdd_cache_mc_addr_list(struct pmo_mc_addr_list_params *mc_list_config)
987{
988 QDF_STATUS status;
989 int ret = 0;
990
991 ENTER();
992 /* cache mc addr list */
993 status = pmo_ucfg_cache_mc_addr_list(mc_list_config);
994 if (status != QDF_STATUS_SUCCESS) {
995 hdd_info("fail to cache mc list status %d", status);
996 ret = -EINVAL;
997 }
998 EXIT();
999
1000 return ret;
1001}
1002
1003void hdd_disable_and_flush_mc_addr_list(hdd_adapter_t *adapter,
1004 enum pmo_offload_trigger trigger)
1005{
1006 hdd_context_t *hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
1007 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1008 QDF_STATUS status = QDF_STATUS_SUCCESS;
1009
1010 ENTER();
1011 /* disable mc list first */
1012 status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc,
1013 adapter->sessionId, trigger);
1014 if (status != QDF_STATUS_SUCCESS)
1015 hdd_info("fail to disable mc list");
1016
1017 /* flush mc list */
1018 status = pmo_ucfg_flush_mc_addr_list(psoc, adapter->sessionId);
1019 if (status != QDF_STATUS_SUCCESS)
1020 hdd_info("fail to flush mc list status %d", status);
1021 EXIT();
1022
1023 return;
1024
1025}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026
1027/**
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001028 * hdd_update_conn_state_mask(): record info needed by wma_suspend_req
1029 * @adapter: adapter to get info from
1030 * @conn_state_mask: mask of connection info
1031 *
1032 * currently only need to send connection info.
1033 */
1034static void
1035hdd_update_conn_state_mask(hdd_adapter_t *adapter, uint32_t *conn_state_mask)
1036{
1037
1038 eConnectionState connState;
1039 hdd_station_ctx_t *sta_ctx;
1040 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1041 connState = sta_ctx->conn_info.connState;
1042
1043 if (connState == eConnectionState_Associated ||
1044 connState == eConnectionState_IbssConnected)
1045 *conn_state_mask |= (1 << adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046}
1047
1048/**
1049 * hdd_suspend_wlan() - Driver suspend function
1050 * @callback: Callback function to invoke when driver is ready to suspend
1051 * @callbackContext: Context to pass back to @callback function
1052 *
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301053 * Return: 0 on success else error code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301055static int
1056hdd_suspend_wlan(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057{
1058 hdd_context_t *pHddCtx;
1059
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301060 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 hdd_adapter_t *pAdapter = NULL;
1062 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001063 uint32_t conn_state_mask = 0;
Jeff Johnsonc3273322016-07-06 15:28:17 -07001064 hdd_info("WLAN being suspended by OS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065
Anurag Chouhan6d760662016-02-20 16:05:43 +05301066 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 if (!pHddCtx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001068 hdd_err("HDD context is Null");
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301069 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 }
1071
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001072 if (cds_is_driver_recovering()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001073 hdd_info("Recovery in Progress. State: 0x%x Ignore suspend!!!",
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001074 cds_get_driver_state());
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301075 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 }
1077
1078 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301079 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080 pAdapter = pAdapterNode->pAdapter;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301081 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
1082 hdd_err("invalid session id: %d", pAdapter->sessionId);
1083 goto next_adapter;
1084 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085
1086 /* stop all TX queues before suspend */
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001087 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05301088 wlan_hdd_netif_queue_control(pAdapter,
1089 WLAN_STOP_ALL_NETIF_QUEUE,
1090 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001092 /* Configure supported OffLoads */
Mukul Sharma3ba26b82017-01-12 21:59:41 +05301093 hdd_enable_host_offloads(pAdapter, pmo_apps_suspend);
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001094 hdd_update_conn_state_mask(pAdapter, &conn_state_mask);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301095next_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001096 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1097 pAdapterNode = pNext;
1098 }
1099
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301100 status = pmo_ucfg_psoc_user_space_suspend_req(pHddCtx->hdd_psoc,
1101 QDF_SYSTEM_SUSPEND);
1102 if (status != QDF_STATUS_SUCCESS)
1103 return -EAGAIN;
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 pHddCtx->hdd_wlan_suspended = true;
Abhishek Singhbaea27d2016-04-27 13:29:30 +05301106 hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_SUSPEND);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301108 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109}
1110
1111/**
1112 * hdd_resume_wlan() - Driver resume function
1113 *
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301114 * Return: 0 on success else error code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301116static int hdd_resume_wlan(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117{
1118 hdd_context_t *pHddCtx;
1119 hdd_adapter_t *pAdapter = NULL;
1120 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301121 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122
Dustin Brown2d228232016-09-22 15:06:19 -07001123 hdd_info("WLAN being resumed by OS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124
Anurag Chouhan6d760662016-02-20 16:05:43 +05301125 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001126 if (!pHddCtx) {
Dustin Brown2d228232016-09-22 15:06:19 -07001127 hdd_err("HDD context is Null");
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301128 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 }
1130
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001131 if (cds_is_driver_recovering()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001132 hdd_info("Recovery in Progress. State: 0x%x Ignore resume!!!",
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001133 cds_get_driver_state());
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301134 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 }
1136
1137 pHddCtx->hdd_wlan_suspended = false;
Abhishek Singhbaea27d2016-04-27 13:29:30 +05301138 hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_RESUME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001139
1140 /*loop through all adapters. Concurrency */
1141 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
1142
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301143 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 pAdapter = pAdapterNode->pAdapter;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301145 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
1146 hdd_err("invalid session id: %d", pAdapter->sessionId);
1147 goto next_adapter;
1148 }
1149 /* Disable supported OffLoads */
1150 hdd_disable_host_offloads(pAdapter, pmo_apps_resume);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151
1152 /* wake the tx queues */
Dustin Brown2d228232016-09-22 15:06:19 -07001153 hdd_info("Enabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154 wlan_hdd_netif_queue_control(pAdapter,
1155 WLAN_WAKE_ALL_NETIF_QUEUE,
1156 WLAN_CONTROL_PATH);
1157
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301158next_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1160 pAdapterNode = pNext;
1161 }
1162 hdd_ipa_resume(pHddCtx);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301163 status = pmo_ucfg_psoc_user_space_resume_req(pHddCtx->hdd_psoc,
1164 QDF_SYSTEM_SUSPEND);
1165 if (status != QDF_STATUS_SUCCESS)
1166 return -EAGAIN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001167
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301168 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169}
1170
1171/**
1172 * DOC: SSR Timer
1173 *
1174 * When SSR is initiated, an SSR timer is started. Under normal
1175 * circumstances SSR should complete amd the timer should be deleted
1176 * before it fires. If the SSR timer does fire, it indicates SSR has
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301177 * taken too long, and our only recourse is to invoke the QDF_BUG()
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 * API which can allow a crashdump to be captured.
1179 */
1180
1181/**
1182 * hdd_ssr_timer_init() - Initialize SSR Timer
1183 *
1184 * Return: None.
1185 */
1186static void hdd_ssr_timer_init(void)
1187{
1188 init_timer(&ssr_timer);
1189}
1190
1191/**
1192 * hdd_ssr_timer_del() - Delete SSR Timer
1193 *
1194 * Return: None.
1195 */
1196static void hdd_ssr_timer_del(void)
1197{
1198 del_timer(&ssr_timer);
1199 ssr_timer_started = false;
1200}
1201
1202/**
1203 * hdd_ssr_timer_cb() - SSR Timer callback function
1204 * @data: opaque data registered with timer infrastructure
1205 *
1206 * Return: None.
1207 */
1208static void hdd_ssr_timer_cb(unsigned long data)
1209{
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001210 hdd_info("HDD SSR timer expired!");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301211 QDF_BUG(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212}
1213
1214/**
1215 * hdd_ssr_timer_start() - Start SSR Timer
1216 * @msec: Timer timeout value in milliseconds
1217 *
1218 * Return: None.
1219 */
1220static void hdd_ssr_timer_start(int msec)
1221{
1222 if (ssr_timer_started) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001223 hdd_debug("Trying to start SSR timer when " "it's running!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001224 }
1225 ssr_timer.expires = jiffies + msecs_to_jiffies(msec);
1226 ssr_timer.function = hdd_ssr_timer_cb;
1227 add_timer(&ssr_timer);
1228 ssr_timer_started = true;
1229}
1230
1231/**
Komal Seelam78ff65a2016-08-18 15:25:24 +05301232 * hdd_svc_fw_shutdown_ind() - API to send FW SHUTDOWN IND to Userspace
1233 *
1234 * @dev: Device Pointer
1235 *
1236 * Return: None
1237 */
1238void hdd_svc_fw_shutdown_ind(struct device *dev)
1239{
1240 hdd_context_t *hdd_ctx;
1241 v_CONTEXT_t g_context;
1242
1243 g_context = cds_get_global_context();
1244
1245 if (!g_context)
1246 return;
1247
1248 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1249
1250 hdd_ctx ? wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
1251 WLAN_SVC_FW_SHUTDOWN_IND,
1252 NULL, 0) : 0;
1253}
1254
1255/**
Arun Khandavallicc544b32017-01-30 19:52:16 +05301256 * hdd_ssr_restart_sap() - restart sap on SSR
1257 * @hdd_ctx: hdd context
1258 *
1259 * Return: nothing
1260 */
1261static void hdd_ssr_restart_sap(hdd_context_t *hdd_ctx)
1262{
1263 QDF_STATUS status;
1264 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
1265 hdd_adapter_t *adapter;
1266
1267 ENTER();
1268
1269 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1270 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
1271 adapter = adapter_node->pAdapter;
1272 if (adapter && adapter->device_mode == QDF_SAP_MODE) {
Manikandan Mohan0a0ac952017-02-16 15:49:31 -08001273 if (test_bit(SOFTAP_INIT_DONE, &adapter->event_flags)) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001274 hdd_debug("Restart prev SAP session");
Manikandan Mohan0a0ac952017-02-16 15:49:31 -08001275 wlan_hdd_start_sap(adapter, true);
1276 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05301277 }
1278 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
1279 adapter_node = next;
1280 }
1281
1282 EXIT();
1283}
1284
1285/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286 * hdd_wlan_shutdown() - HDD SSR shutdown function
1287 *
1288 * This function is called by the HIF to shutdown the driver during SSR.
1289 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301290 * Return: QDF_STATUS_SUCCESS if the driver was shut down,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291 * or an error status otherwise
1292 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301293QDF_STATUS hdd_wlan_shutdown(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001294{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001295 v_CONTEXT_t p_cds_context = NULL;
1296 hdd_context_t *pHddCtx;
1297 p_cds_sched_context cds_sched_context = NULL;
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07001298 QDF_STATUS qdf_status;
Manikandan Mohan8b4e2012017-03-22 11:15:55 -07001299 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001300
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001301 hdd_info("WLAN driver shutting down!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001303 /* If SSR never completes, then do kernel panic. */
1304 hdd_ssr_timer_init();
1305 hdd_ssr_timer_start(HDD_SSR_BRING_UP_TIME);
1306
1307 /* Get the global CDS context. */
1308 p_cds_context = cds_get_global_context();
1309 if (!p_cds_context) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001310 hdd_err("Global CDS context is Null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301311 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312 }
1313
1314 /* Get the HDD context. */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301315 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001316 if (!pHddCtx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001317 hdd_err("HDD context is Null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301318 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 }
1320
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08001321 policy_mgr_clear_concurrent_session_count(pHddCtx->hdd_psoc);
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +05301322
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001323 hdd_debug("Invoking packetdump deregistration API");
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +05301324 wlan_deregister_txrx_packetdump();
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07001325 wlan_cfg80211_cleanup_scan_queue(pHddCtx->hdd_pdev);
Govind Singh9c58eba2016-09-02 16:23:06 +05301326 hdd_ipa_uc_ssr_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001327 hdd_reset_all_adapters(pHddCtx);
1328
Poddar, Siddarth1ab0a3d2016-09-29 18:58:45 +05301329 /* Flush cached rx frame queue */
Manikandan Mohan8b4e2012017-03-22 11:15:55 -07001330 if (soc)
1331 cdp_flush_cache_rx_queue(soc);
Poddar, Siddarth1ab0a3d2016-09-29 18:58:45 +05301332
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301333 /* De-register the HDD callbacks */
1334 hdd_deregister_cb(pHddCtx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001335
1336 cds_sched_context = get_cds_sched_ctxt();
1337
Rajeev Kumareada0d02016-12-08 17:44:17 -08001338 if (pHddCtx->is_scheduler_suspended) {
Rajeev Kumar0b732952016-12-08 17:51:39 -08001339 scheduler_resume();
Rajeev Kumareada0d02016-12-08 17:44:17 -08001340 pHddCtx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001341 }
1342#ifdef QCA_CONFIG_SMP
1343 if (true == pHddCtx->is_ol_rx_thread_suspended) {
1344 complete(&cds_sched_context->ol_resume_rx_event);
1345 pHddCtx->is_ol_rx_thread_suspended = false;
1346 }
1347#endif
1348
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07001349 qdf_status = cds_sched_close(p_cds_context);
1350 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
1351 hdd_err("Failed to close CDS Scheduler");
1352 QDF_ASSERT(false);
1353 }
1354
Nitesh Shah61c10d92016-10-19 19:29:15 +05301355 qdf_mc_timer_stop(&pHddCtx->tdls_source_timer);
1356
Prashanth Bhattaab004382016-10-11 16:08:11 -07001357 hdd_bus_bandwidth_destroy(pHddCtx);
1358
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07001359 hdd_wlan_stop_modules(pHddCtx, false);
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05301360
Jeff Johnsonf7f66f02016-09-23 14:50:11 -07001361 hdd_lpass_notify_stop(pHddCtx);
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07001362
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001363 hdd_info("WLAN driver shutdown complete");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301364 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365}
1366
Sen, Devendra154b3c42017-02-13 20:44:15 +05301367#ifdef FEATURE_WLAN_DIAG_SUPPORT
1368/**
1369* hdd_wlan_ssr_reinit_event()- send ssr reinit state
1370*
1371* This Function send send ssr reinit state diag event
1372*
1373* Return: void.
1374*/
1375static void hdd_wlan_ssr_reinit_event(void)
1376{
1377 WLAN_HOST_DIAG_EVENT_DEF(ssr_reinit, struct host_event_wlan_ssr_reinit);
1378 qdf_mem_zero(&ssr_reinit, sizeof(ssr_reinit));
1379 ssr_reinit.status = SSR_SUB_SYSTEM_REINIT;
1380 WLAN_HOST_DIAG_EVENT_REPORT(&ssr_reinit,
1381 EVENT_WLAN_SSR_REINIT_SUBSYSTEM);
1382}
1383#else
1384static inline void hdd_wlan_ssr_reinit_event(void)
1385{
1386
1387}
1388#endif
1389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390/**
1391 * hdd_wlan_re_init() - HDD SSR re-init function
1392 *
1393 * This function is called by the HIF to re-initialize the driver after SSR.
1394 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301395 * Return: QDF_STATUS_SUCCESS if the driver was re-initialized,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396 * or an error status otherwise
1397 */
Arun Khandavallifae92942016-08-01 13:31:08 +05301398QDF_STATUS hdd_wlan_re_init(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399{
Arun Khandavallifae92942016-08-01 13:31:08 +05301400
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 v_CONTEXT_t p_cds_context = NULL;
1402 hdd_context_t *pHddCtx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 hdd_adapter_t *pAdapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05301404 int ret;
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301405 bool bug_on_reinit_failure = CFG_BUG_ON_REINIT_FAILURE_DEFAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406
1407 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
1408
1409 /* Get the CDS context */
1410 p_cds_context = cds_get_global_context();
1411 if (p_cds_context == NULL) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001412 hdd_err("Failed cds_get_global_context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 goto err_re_init;
1414 }
1415
1416 /* Get the HDD context */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301417 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418 if (!pHddCtx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001419 hdd_err("HDD context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420 goto err_re_init;
1421 }
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301422 bug_on_reinit_failure = pHddCtx->config->bug_on_reinit_failure;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001424 /* The driver should always be initialized in STA mode after SSR */
1425 hdd_set_conparam(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426 /* Try to get an adapter from mode ID */
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001427 pAdapter = hdd_get_adapter(pHddCtx, QDF_STA_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 if (!pAdapter) {
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001429 pAdapter = hdd_get_adapter(pHddCtx, QDF_SAP_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430 if (!pAdapter) {
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001431 pAdapter = hdd_get_adapter(pHddCtx, QDF_IBSS_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001432 if (!pAdapter) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001433 hdd_err("Failed to get Adapter!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 }
1435 }
1436 }
1437
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05301438 if (pHddCtx->config->enable_dp_trace)
1439 qdf_dp_trace_init();
1440
Prashanth Bhattaab004382016-10-11 16:08:11 -07001441 hdd_bus_bandwidth_init(pHddCtx);
1442
Arun Khandavallicc544b32017-01-30 19:52:16 +05301443
Arun Khandavallifae92942016-08-01 13:31:08 +05301444 ret = hdd_wlan_start_modules(pHddCtx, pAdapter, true);
1445 if (ret) {
1446 hdd_err("Failed to start wlan after error");
1447 goto err_wiphy_unregister;
1448 }
1449
Arun Khandavallia96c2c02016-05-17 19:15:34 +05301450 hdd_wlan_get_version(pHddCtx, NULL, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451
Wu Gao36717432016-11-21 15:09:48 +08001452 wlan_hdd_send_svc_nlink_msg(pHddCtx->radio_index,
1453 WLAN_SVC_FW_CRASHED_IND, NULL, 0);
1454
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455 /* Restart all adapters */
1456 hdd_start_all_adapters(pHddCtx);
1457
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05301458 pHddCtx->last_scan_reject_session_id = 0xFF;
1459 pHddCtx->last_scan_reject_reason = 0;
1460 pHddCtx->last_scan_reject_timestamp = 0;
1461
Selvaraj, Sridhar1c487562017-04-19 14:29:07 +05301462 hdd_set_roaming_in_progress(false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001463 pHddCtx->btCoexModeSet = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465 /* Allow the phone to go to sleep */
1466 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
1467
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301468 ret = hdd_register_cb(pHddCtx);
1469 if (ret) {
1470 hdd_err("Failed to register HDD callbacks!");
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05301471 goto err_cds_disable;
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301472 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001473
Jeff Johnson9afc5012016-09-23 13:56:27 -07001474 hdd_lpass_notify_start(pHddCtx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001475
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001476 hdd_info("WLAN host driver reinitiation completed!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001477 goto success;
1478
1479err_cds_disable:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07001480 hdd_wlan_stop_modules(pHddCtx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481
Arun Khandavallifae92942016-08-01 13:31:08 +05301482err_wiphy_unregister:
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05301483 if (bug_on_reinit_failure)
1484 QDF_BUG(0);
1485
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 if (pHddCtx) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05301487 /* Unregister the Notifier's */
1488 hdd_unregister_notifiers(pHddCtx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001489 ptt_sock_deactivate_svc();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 nl_srv_exit();
1491
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05301492 hdd_close_all_adapters(pHddCtx, false);
1493 wlan_hdd_cfg80211_deinit(pHddCtx->wiphy);
1494 hdd_lpass_notify_stop(pHddCtx);
Nirav Shahed34b212016-04-25 10:59:16 +05301495 wlan_hdd_deinit_tx_rx_histogram(pHddCtx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 wiphy_unregister(pHddCtx->wiphy);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05301497
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001498 }
1499
1500err_re_init:
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05301501 hdd_ssr_timer_del();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001502 /* Allow the phone to go to sleep */
1503 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301504 if (bug_on_reinit_failure)
1505 QDF_BUG(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001506 return -EPERM;
1507
1508success:
Arun Khandavallicc544b32017-01-30 19:52:16 +05301509 if (pHddCtx->config->sap_internal_restart)
1510 hdd_ssr_restart_sap(pHddCtx);
Srinivas Girigowda02c084d2016-10-18 15:27:21 -07001511 hdd_ssr_timer_del();
Sen, Devendra154b3c42017-02-13 20:44:15 +05301512 hdd_wlan_ssr_reinit_event();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301513 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514}
1515
1516/**
1517 * wlan_hdd_set_powersave() - Set powersave mode
1518 * @adapter: adapter upon which the request was received
Dustin Brownf660fb42016-09-09 12:04:00 -07001519 * @allow_power_save: is wlan allowed to go into power save mode
1520 * @timeout: timeout period in ms
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521 *
1522 * Return: 0 on success, non-zero on any error
1523 */
Dustin Brownf660fb42016-09-09 12:04:00 -07001524static int wlan_hdd_set_powersave(hdd_adapter_t *adapter,
1525 bool allow_power_save, uint32_t timeout)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526{
1527 tHalHandle hal;
1528 hdd_context_t *hdd_ctx;
1529
1530 if (NULL == adapter) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001531 hdd_err("Adapter NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 return -ENODEV;
1533 }
1534
1535 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1536 if (!hdd_ctx) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001537 hdd_err("hdd context is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001538 return -EINVAL;
1539 }
1540
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001541 hdd_debug("Allow power save: %d", allow_power_save);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 hal = WLAN_HDD_GET_HAL_CTX(adapter);
1543
Dustin Brownf660fb42016-09-09 12:04:00 -07001544 if (allow_power_save) {
1545 if (QDF_STA_MODE == adapter->device_mode ||
1546 QDF_P2P_CLIENT_MODE == adapter->device_mode) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001547 hdd_debug("Disabling Auto Power save timer");
Dustin Brownf660fb42016-09-09 12:04:00 -07001548 sme_ps_disable_auto_ps_timer(
1549 WLAN_HDD_GET_HAL_CTX(adapter),
1550 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001551 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553 if (hdd_ctx->config && hdd_ctx->config->is_ps_enabled) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001554 hdd_debug("Wlan driver Entering Power save");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555
1556 /*
1557 * Enter Power Save command received from GUI
1558 * this means DHCP is completed
1559 */
1560 sme_ps_enable_disable(hal, adapter->sessionId,
1561 SME_PS_ENABLE);
1562 } else {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001563 hdd_debug("Power Save is not enabled in the cfg");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001564 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001565 } else {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001566 hdd_debug("Wlan driver Entering Full Power");
Dustin Brownf660fb42016-09-09 12:04:00 -07001567
1568 /*
1569 * Enter Full power command received from GUI
1570 * this means we are disconnected
1571 */
1572 sme_ps_disable_auto_ps_timer(WLAN_HDD_GET_HAL_CTX(adapter),
1573 adapter->sessionId);
1574 sme_ps_enable_disable(hal, adapter->sessionId, SME_PS_DISABLE);
1575 sme_ps_enable_auto_ps_timer(WLAN_HDD_GET_HAL_CTX(adapter),
1576 adapter->sessionId, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001578
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 return 0;
1580}
1581
Dustin Brown105d7902016-10-03 16:27:59 -07001582static void wlan_hdd_print_suspend_fail_stats(hdd_context_t *hdd_ctx)
1583{
Dustin Brownd9322482017-01-09 12:46:03 -08001584 struct suspend_resume_stats *stats = &hdd_ctx->suspend_resume_stats;
Dustin Brown105d7902016-10-03 16:27:59 -07001585 hdd_err("ipa:%d, radar:%d, roam:%d, scan:%d, initial_wakeup:%d",
Dustin Brownd9322482017-01-09 12:46:03 -08001586 stats->suspend_fail[SUSPEND_FAIL_IPA],
1587 stats->suspend_fail[SUSPEND_FAIL_RADAR],
1588 stats->suspend_fail[SUSPEND_FAIL_ROAM],
1589 stats->suspend_fail[SUSPEND_FAIL_SCAN],
1590 stats->suspend_fail[SUSPEND_FAIL_INITIAL_WAKEUP]);
Dustin Brown105d7902016-10-03 16:27:59 -07001591}
1592
1593void wlan_hdd_inc_suspend_stats(hdd_context_t *hdd_ctx,
1594 enum suspend_fail_reason reason)
1595{
1596 wlan_hdd_print_suspend_fail_stats(hdd_ctx);
Dustin Brownd9322482017-01-09 12:46:03 -08001597 hdd_ctx->suspend_resume_stats.suspend_fail[reason]++;
Dustin Brown105d7902016-10-03 16:27:59 -07001598 wlan_hdd_print_suspend_fail_stats(hdd_ctx);
1599}
1600
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001601/**
1602 * __wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback
1603 * @wiphy: Pointer to wiphy
1604 *
1605 * This API is called when cfg80211 driver resumes driver updates
1606 * latest sched_scan scan result(if any) to cfg80211 database
1607 *
1608 * Return: integer status
1609 */
1610static int __wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
1611{
1612 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
1613 hdd_adapter_t *pAdapter;
1614 hdd_adapter_list_node_t *pAdapterNode, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301615 QDF_STATUS status = QDF_STATUS_SUCCESS;
Dustin Brownd9322482017-01-09 12:46:03 -08001616 int exit_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001617 p_cds_sched_context cds_sched_context = get_cds_sched_ctxt();
1618
1619 ENTER();
1620
Dustin Brownd9322482017-01-09 12:46:03 -08001621 if (cds_is_driver_recovering()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001622 hdd_debug("Driver is recovering; Skipping resume");
Dustin Brownd9322482017-01-09 12:46:03 -08001623 exit_code = 0;
1624 goto exit_with_code;
1625 }
Prashanth Bhatta697dd0c2016-10-20 18:42:41 -07001626
Anurag Chouhan6d760662016-02-20 16:05:43 +05301627 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001628 hdd_err("Command not allowed in FTM mode");
Dustin Brownd9322482017-01-09 12:46:03 -08001629 exit_code = -EINVAL;
1630 goto exit_with_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 }
1632
Dustin Brownd9322482017-01-09 12:46:03 -08001633 exit_code = wlan_hdd_validate_context(pHddCtx);
1634 if (exit_code) {
1635 hdd_err("Invalid HDD context");
1636 goto exit_with_code;
1637 }
Arun Khandavallifae92942016-08-01 13:31:08 +05301638
1639 mutex_lock(&pHddCtx->iface_change_lock);
1640 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
1641 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001642 hdd_debug("Driver is not enabled; Skipping resume");
Dustin Brownd9322482017-01-09 12:46:03 -08001643 exit_code = 0;
1644 goto exit_with_code;
Arun Khandavallifae92942016-08-01 13:31:08 +05301645 }
1646 mutex_unlock(&pHddCtx->iface_change_lock);
Dustin Brownd9322482017-01-09 12:46:03 -08001647
Yuanyuan Liu13738502016-04-06 17:41:37 -07001648 pld_request_bus_bandwidth(pHddCtx->parent_dev, PLD_BUS_WIDTH_MEDIUM);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301650 status = hdd_resume_wlan();
1651 if (status != QDF_STATUS_SUCCESS) {
1652 exit_code = 0;
1653 goto exit_with_code;
1654 }
Rajeev Kumareada0d02016-12-08 17:44:17 -08001655 /* Resume control path scheduler */
1656 if (pHddCtx->is_scheduler_suspended) {
Rajeev Kumar0b732952016-12-08 17:51:39 -08001657 scheduler_resume();
Rajeev Kumareada0d02016-12-08 17:44:17 -08001658 pHddCtx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659 }
1660#ifdef QCA_CONFIG_SMP
1661 /* Resume tlshim Rx thread */
1662 if (pHddCtx->is_ol_rx_thread_suspended) {
1663 complete(&cds_sched_context->ol_resume_rx_event);
1664 pHddCtx->is_ol_rx_thread_suspended = false;
1665 }
1666#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301668 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05301669 TRACE_CODE_HDD_CFG80211_RESUME_WLAN,
1670 NO_SESSION, pHddCtx->isWiphySuspended));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301671 qdf_spin_lock(&pHddCtx->sched_scan_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 pHddCtx->isWiphySuspended = false;
1673 if (true != pHddCtx->isSchedScanUpdatePending) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301674 qdf_spin_unlock(&pHddCtx->sched_scan_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001675 hdd_debug("Return resume is not due to PNO indication");
Dustin Brownd9322482017-01-09 12:46:03 -08001676 goto exit_with_success;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001677 }
1678 /* Reset flag to avoid updatating cfg80211 data old results again */
1679 pHddCtx->isSchedScanUpdatePending = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301680 qdf_spin_unlock(&pHddCtx->sched_scan_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001681
1682 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301683 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 pAdapter = pAdapterNode->pAdapter;
1685 if ((NULL != pAdapter) &&
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001686 (QDF_STA_MODE == pAdapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001687 if (0 !=
1688 wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy,
1689 pAdapter, 0)) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001690 hdd_warn("NO SCAN result");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 } else {
1692 /* Acquire wakelock to handle the case where
1693 * APP's tries to suspend immediately after
1694 * updating the scan results. Whis results in
1695 * app's is in suspended state and not able to
1696 * process the connect request to AP
1697 */
Sreelakshmi Konamki22528532016-09-06 16:34:50 +05301698 hdd_prevent_suspend_timeout(
1699 HDD_WAKE_LOCK_RESUME_DURATION,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700 WIFI_POWER_EVENT_WAKELOCK_RESUME_WLAN);
1701 cfg80211_sched_scan_results(pHddCtx->wiphy);
1702 }
1703
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001704 hdd_debug("cfg80211 scan result database updated");
Dustin Brownd9322482017-01-09 12:46:03 -08001705 goto exit_with_success;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706 }
1707 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1708 pAdapterNode = pNext;
1709 }
1710
Dustin Brownd9322482017-01-09 12:46:03 -08001711exit_with_success:
1712 pHddCtx->suspend_resume_stats.resumes++;
1713 exit_code = 0;
1714
1715exit_with_code:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301716 EXIT();
Dustin Brownd9322482017-01-09 12:46:03 -08001717 return exit_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718}
1719
1720/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001721 * wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback
1722 * @wiphy: Pointer to wiphy
1723 *
1724 * This API is called when cfg80211 driver resumes driver updates
1725 * latest sched_scan scan result(if any) to cfg80211 database
1726 *
1727 * Return: integer status
1728 */
1729int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
1730{
1731 int ret;
1732
1733 cds_ssr_protect(__func__);
1734 ret = __wlan_hdd_cfg80211_resume_wlan(wiphy);
1735 cds_ssr_unprotect(__func__);
1736
1737 return ret;
1738}
1739
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001740static void hdd_suspend_cb(void)
1741{
1742 hdd_context_t *hdd_ctx;
1743
1744 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1745 if (!hdd_ctx) {
1746 cds_err("HDD context is NULL");
1747 return;
1748 }
1749
1750 complete(&hdd_ctx->mc_sus_event_var);
1751}
1752
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753/**
1754 * __wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback
1755 * @wiphy: Pointer to wiphy
1756 * @wow: Pointer to wow
1757 *
1758 * This API is called when cfg80211 driver suspends
1759 *
1760 * Return: integer status
1761 */
1762static int __wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
1763 struct cfg80211_wowlan *wow)
1764{
1765#ifdef QCA_CONFIG_SMP
1766#define RX_TLSHIM_SUSPEND_TIMEOUT 200 /* msecs */
1767#endif
1768 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
1769 p_cds_sched_context cds_sched_context = get_cds_sched_ctxt();
1770 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
1771 hdd_adapter_t *pAdapter;
1772 hdd_scaninfo_t *pScanInfo;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301773 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001774 int rc;
1775
1776 ENTER();
1777
Anurag Chouhan6d760662016-02-20 16:05:43 +05301778 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001779 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780 return -EINVAL;
1781 }
1782
1783 rc = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301784 if (0 != rc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001785 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786
Arun Khandavallifae92942016-08-01 13:31:08 +05301787 mutex_lock(&pHddCtx->iface_change_lock);
1788 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
1789 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001790 hdd_debug("Driver Modules not Enabled ");
Arun Khandavallifae92942016-08-01 13:31:08 +05301791 return 0;
1792 }
1793 mutex_unlock(&pHddCtx->iface_change_lock);
1794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001795 /* If RADAR detection is in progress (HDD), prevent suspend. The flag
1796 * "dfs_cac_block_tx" is set to true when RADAR is found and stay true
1797 * until CAC is done for a SoftAP which is in started state.
1798 */
1799 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301800 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001801 pAdapter = pAdapterNode->pAdapter;
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301802
1803 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
1804 hdd_err("invalid session id: %d", pAdapter->sessionId);
1805 goto next_adapter;
1806 }
1807
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001808 if (QDF_SAP_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001809 if (BSS_START ==
1810 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter)->bssState &&
1811 true ==
1812 WLAN_HDD_GET_AP_CTX_PTR(pAdapter)->
1813 dfs_cac_block_tx) {
Dustin Brown2d228232016-09-22 15:06:19 -07001814 hdd_err("RADAR detection in progress, do not allow suspend");
Dustin Brown105d7902016-10-03 16:27:59 -07001815 wlan_hdd_inc_suspend_stats(pHddCtx,
1816 SUSPEND_FAIL_RADAR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001817 return -EAGAIN;
1818 } else if (!pHddCtx->config->enableSapSuspend) {
1819 /* return -EOPNOTSUPP if SAP does not support
1820 * suspend
1821 */
Jeff Johnsonc3273322016-07-06 15:28:17 -07001822 hdd_err("SAP does not support suspend!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001823 return -EOPNOTSUPP;
1824 }
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001825 } else if (QDF_P2P_GO_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001826 if (!pHddCtx->config->enableSapSuspend) {
1827 /* return -EOPNOTSUPP if GO does not support
1828 * suspend
1829 */
Jeff Johnsonc3273322016-07-06 15:28:17 -07001830 hdd_err("GO does not support suspend!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001831 return -EOPNOTSUPP;
1832 }
1833 }
Masti, Narayanraddi3e26de62016-08-19 14:33:22 +05301834 if (pAdapter->is_roc_inprogress)
1835 wlan_hdd_cleanup_remain_on_channel_ctx(pAdapter);
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301836next_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001837 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1838 pAdapterNode = pNext;
1839 }
1840
1841 /* Stop ongoing scan on each interface */
1842 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301843 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001844 pAdapter = pAdapterNode->pAdapter;
1845 pScanInfo = &pAdapter->scan_info;
1846
Sandeep Puligillaf8527122016-11-16 18:35:16 -08001847 if (sme_neighbor_middle_of_roaming
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848 (pHddCtx->hHal, pAdapter->sessionId)) {
Dustin Brown2d228232016-09-22 15:06:19 -07001849 hdd_err("Roaming in progress, do not allow suspend");
Dustin Brown105d7902016-10-03 16:27:59 -07001850 wlan_hdd_inc_suspend_stats(pHddCtx,
1851 SUSPEND_FAIL_ROAM);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852 return -EAGAIN;
1853 }
1854
Abhishek Singh69ccb512017-04-25 11:58:16 +05301855 if (pScanInfo->mScanPending)
1856 wlan_abort_scan(pHddCtx->hdd_pdev, INVAL_PDEV_ID,
1857 pAdapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001858 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1859 pAdapterNode = pNext;
1860 }
1861
1862 /*
1863 * Suspend IPA early before proceeding to suspend other entities like
1864 * firmware to avoid any race conditions.
1865 */
1866 if (hdd_ipa_suspend(pHddCtx)) {
Dustin Brown2d228232016-09-22 15:06:19 -07001867 hdd_err("IPA not ready to suspend!");
Dustin Brown105d7902016-10-03 16:27:59 -07001868 wlan_hdd_inc_suspend_stats(pHddCtx, SUSPEND_FAIL_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869 return -EAGAIN;
1870 }
1871
Rajeev Kumareada0d02016-12-08 17:44:17 -08001872 /* Suspend control path scheduler */
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001873 scheduler_register_hdd_suspend_callback(hdd_suspend_cb);
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301874 scheduler_set_event_mask(MC_SUSPEND_EVENT);
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001875 scheduler_wake_up_controller_thread();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001876
Rajeev Kumareada0d02016-12-08 17:44:17 -08001877 /* Wait for suspend confirmation from scheduler */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 rc = wait_for_completion_timeout(&pHddCtx->mc_sus_event_var,
1879 msecs_to_jiffies(WLAN_WAIT_TIME_MCTHREAD_SUSPEND));
1880 if (!rc) {
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301881 scheduler_clear_event_mask(MC_SUSPEND_EVENT);
Jeff Johnsonc3273322016-07-06 15:28:17 -07001882 hdd_err("Failed to stop mc thread");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001883 goto resume_tx;
1884 }
Rajeev Kumareada0d02016-12-08 17:44:17 -08001885 pHddCtx->is_scheduler_suspended = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001886
1887#ifdef QCA_CONFIG_SMP
1888 /* Suspend tlshim rx thread */
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301889 set_bit(RX_SUSPEND_EVENT, &cds_sched_context->ol_rx_event_flag);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890 wake_up_interruptible(&cds_sched_context->ol_rx_wait_queue);
1891 rc = wait_for_completion_timeout(&cds_sched_context->
1892 ol_suspend_rx_event,
1893 msecs_to_jiffies
1894 (RX_TLSHIM_SUSPEND_TIMEOUT));
1895 if (!rc) {
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301896 clear_bit(RX_SUSPEND_EVENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001897 &cds_sched_context->ol_rx_event_flag);
Jeff Johnsonc3273322016-07-06 15:28:17 -07001898 hdd_err("Failed to stop tl_shim rx thread");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 goto resume_all;
1900 }
1901 pHddCtx->is_ol_rx_thread_suspended = true;
1902#endif
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301903 if (hdd_suspend_wlan() < 0)
1904 goto resume_all;
1905
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301906 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05301907 TRACE_CODE_HDD_CFG80211_SUSPEND_WLAN,
1908 NO_SESSION, pHddCtx->isWiphySuspended));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909 pHddCtx->isWiphySuspended = true;
1910
Yuanyuan Liu13738502016-04-06 17:41:37 -07001911 pld_request_bus_bandwidth(pHddCtx->parent_dev, PLD_BUS_WIDTH_NONE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912
1913 EXIT();
1914 return 0;
1915
1916#ifdef QCA_CONFIG_SMP
1917resume_all:
1918
Rajeev Kumar0b732952016-12-08 17:51:39 -08001919 scheduler_resume();
Rajeev Kumareada0d02016-12-08 17:44:17 -08001920 pHddCtx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001921#endif
1922
1923resume_tx:
1924
1925 hdd_resume_wlan();
1926 return -ETIME;
1927
1928}
1929
1930/**
1931 * wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback
1932 * @wiphy: Pointer to wiphy
1933 * @wow: Pointer to wow
1934 *
1935 * This API is called when cfg80211 driver suspends
1936 *
1937 * Return: integer status
1938 */
1939int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
1940 struct cfg80211_wowlan *wow)
1941{
1942 int ret;
1943
1944 cds_ssr_protect(__func__);
1945 ret = __wlan_hdd_cfg80211_suspend_wlan(wiphy, wow);
1946 cds_ssr_unprotect(__func__);
1947
1948 return ret;
1949}
1950
1951/**
Komal Seelama89be8d2016-09-29 11:09:26 +05301952 * hdd_stop_dhcp_ind() - API to stop DHCP sequence
1953 * @adapter: Adapter on which DHCP needs to be stopped
1954 *
1955 * Release the wakelock held for DHCP process and allow
1956 * the runtime pm to continue
1957 *
1958 * Return: None
1959 */
1960static void hdd_stop_dhcp_ind(hdd_adapter_t *adapter)
1961{
1962 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1963
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08001964 hdd_debug("DHCP stop indicated through power save");
Komal Seelama89be8d2016-09-29 11:09:26 +05301965 sme_dhcp_stop_ind(hdd_ctx->hHal, adapter->device_mode,
1966 adapter->macAddressCurrent.bytes,
1967 adapter->sessionId);
1968 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DHCP);
1969 qdf_runtime_pm_allow_suspend(adapter->connect_rpm_ctx.connect);
1970}
1971
1972/**
1973 * hdd_start_dhcp_ind() - API to start DHCP sequence
1974 * @adapter: Adapter on which DHCP needs to be stopped
1975 *
1976 * Prevent APPS suspend and the runtime suspend during
1977 * DHCP sequence
1978 *
1979 * Return: None
1980 */
1981static void hdd_start_dhcp_ind(hdd_adapter_t *adapter)
1982{
1983 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1984
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001985 hdd_debug("DHCP start indicated through power save");
Komal Seelama89be8d2016-09-29 11:09:26 +05301986 qdf_runtime_pm_prevent_suspend(adapter->connect_rpm_ctx.connect);
1987 hdd_prevent_suspend_timeout(1000, WIFI_POWER_EVENT_WAKELOCK_DHCP);
1988 sme_dhcp_start_ind(hdd_ctx->hHal, adapter->device_mode,
1989 adapter->macAddressCurrent.bytes,
1990 adapter->sessionId);
1991}
1992
1993/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001994 * __wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config
1995 * @wiphy: Pointer to wiphy
1996 * @dev: Pointer to network device
Dustin Brownf660fb42016-09-09 12:04:00 -07001997 * @allow_power_save: is wlan allowed to go into power save mode
1998 * @timeout: Timeout value in ms
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999 *
2000 * Return: 0 for success, non-zero for failure
2001 */
2002static int __wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Dustin Brownf660fb42016-09-09 12:04:00 -07002003 struct net_device *dev,
2004 bool allow_power_save,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005 int timeout)
2006{
2007 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2008 hdd_context_t *pHddCtx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009 int status;
2010
Dustin Brownecfce632016-09-13 10:41:45 -07002011 ENTER();
2012
Dustin Brownf660fb42016-09-09 12:04:00 -07002013 if (timeout < 0) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002014 hdd_debug("User space timeout: %d; Using default instead: %d",
Dustin Brownf660fb42016-09-09 12:04:00 -07002015 timeout, AUTO_PS_ENTRY_USER_TIMER_DEFAULT_VALUE);
2016 timeout = AUTO_PS_ENTRY_USER_TIMER_DEFAULT_VALUE;
2017 }
2018
Anurag Chouhan6d760662016-02-20 16:05:43 +05302019 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002020 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002021 return -EINVAL;
2022 }
2023
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05302024 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
2025 hdd_err("invalid session id: %d", pAdapter->sessionId);
2026 return -EINVAL;
2027 }
2028
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302029 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030 TRACE_CODE_HDD_CFG80211_SET_POWER_MGMT,
2031 pAdapter->sessionId, timeout));
2032
2033 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2034 status = wlan_hdd_validate_context(pHddCtx);
2035
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302036 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038
Arun Khandavalli99286452016-08-22 12:13:41 +05302039 mutex_lock(&pHddCtx->iface_change_lock);
2040 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
2041 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002042 hdd_debug("Driver Module not enabled return success");
Arun Khandavalli99286452016-08-22 12:13:41 +05302043 return 0;
2044 }
2045 mutex_unlock(&pHddCtx->iface_change_lock);
2046
Dustin Brownf660fb42016-09-09 12:04:00 -07002047 status = wlan_hdd_set_powersave(pAdapter, allow_power_save, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002048
Komal Seelama89be8d2016-09-29 11:09:26 +05302049 allow_power_save ? hdd_stop_dhcp_ind(pAdapter) :
2050 hdd_start_dhcp_ind(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051
2052 EXIT();
2053 return status;
2054}
2055
2056/**
2057 * wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config
2058 * @wiphy: Pointer to wiphy
2059 * @dev: Pointer to network device
Dustin Brownf660fb42016-09-09 12:04:00 -07002060 * @allow_power_save: is wlan allowed to go into power save mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061 * @timeout: Timeout value
2062 *
2063 * Return: 0 for success, non-zero for failure
2064 */
2065int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Dustin Brownf660fb42016-09-09 12:04:00 -07002066 struct net_device *dev,
2067 bool allow_power_save,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068 int timeout)
2069{
2070 int ret;
2071
2072 cds_ssr_protect(__func__);
Dustin Brownf660fb42016-09-09 12:04:00 -07002073 ret = __wlan_hdd_cfg80211_set_power_mgmt(wiphy, dev,
2074 allow_power_save, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002075 cds_ssr_unprotect(__func__);
2076
2077 return ret;
2078}
2079
2080/**
2081 * __wlan_hdd_cfg80211_set_txpower() - set TX power
2082 * @wiphy: Pointer to wiphy
2083 * @wdev: Pointer to network device
2084 * @type: TX power setting type
2085 * @dbm: TX power in dbm
2086 *
2087 * Return: 0 for success, non-zero for failure
2088 */
2089static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002090 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002091 enum nl80211_tx_power_setting type,
2092 int dbm)
2093{
2094 hdd_context_t *pHddCtx = (hdd_context_t *) wiphy_priv(wiphy);
2095 tHalHandle hHal = NULL;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302096 struct qdf_mac_addr bssid = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
2097 struct qdf_mac_addr selfMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002098 int status;
2099
2100 ENTER();
2101
Anurag Chouhan6d760662016-02-20 16:05:43 +05302102 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002103 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104 return -EINVAL;
2105 }
2106
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302107 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002108 TRACE_CODE_HDD_CFG80211_SET_TXPOWER,
2109 NO_SESSION, type));
2110
2111 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302112 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002113 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114
2115 hHal = pHddCtx->hHal;
2116
2117 if (0 != sme_cfg_set_int(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL, dbm)) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002118 hdd_err("sme_cfg_set_int failed for tx power %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119 dbm);
2120 return -EIO;
2121 }
2122
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002123 hdd_debug("Set tx power level %d dbm", dbm);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002124
2125 switch (type) {
2126 /* Automatically determine transmit power */
2127 case NL80211_TX_POWER_AUTOMATIC:
2128 /* Fall through */
2129 case NL80211_TX_POWER_LIMITED: /* Limit TX power by the mBm parameter */
2130 if (sme_set_max_tx_power(hHal, bssid, selfMac, dbm) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302131 QDF_STATUS_SUCCESS) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002132 hdd_err("Setting maximum tx power failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002133 return -EIO;
2134 }
2135 break;
2136
2137 case NL80211_TX_POWER_FIXED: /* Fix TX power to the mBm parameter */
Jeff Johnsonc3273322016-07-06 15:28:17 -07002138 hdd_err("NL80211_TX_POWER_FIXED not supported");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139 return -EOPNOTSUPP;
2140 break;
2141
2142 default:
Jeff Johnsonc3273322016-07-06 15:28:17 -07002143 hdd_err("Invalid power setting type %d", type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002144 return -EIO;
2145 }
2146
2147 EXIT();
2148 return 0;
2149}
2150
2151/**
2152 * wlan_hdd_cfg80211_set_txpower() - set TX power
2153 * @wiphy: Pointer to wiphy
2154 * @wdev: Pointer to network device
2155 * @type: TX power setting type
2156 * @dbm: TX power in dbm
2157 *
2158 * Return: 0 for success, non-zero for failure
2159 */
2160int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002161 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002162 enum nl80211_tx_power_setting type,
2163 int dbm)
2164{
2165 int ret;
2166 cds_ssr_protect(__func__);
2167 ret = __wlan_hdd_cfg80211_set_txpower(wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002168 wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002169 type, dbm);
2170 cds_ssr_unprotect(__func__);
2171
2172 return ret;
2173}
2174
2175/**
2176 * __wlan_hdd_cfg80211_get_txpower() - get TX power
2177 * @wiphy: Pointer to wiphy
2178 * @wdev: Pointer to network device
2179 * @dbm: Pointer to TX power in dbm
2180 *
2181 * Return: 0 for success, non-zero for failure
2182 */
2183static int __wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002184 struct wireless_dev *wdev,
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002185 int *dbm)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002186{
2187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188 hdd_context_t *pHddCtx = (hdd_context_t *) wiphy_priv(wiphy);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002189 struct net_device *ndev = wdev->netdev;
2190 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002191 int status;
2192
2193 ENTER();
2194
Anurag Chouhan6d760662016-02-20 16:05:43 +05302195 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002196 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002197 return -EINVAL;
2198 }
2199
2200 status = wlan_hdd_validate_context(pHddCtx);
2201 if (0 != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002202 *dbm = 0;
2203 return status;
2204 }
2205
Arun Khandavalli99286452016-08-22 12:13:41 +05302206 /* Validate adapter sessionId */
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05302207 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2208 hdd_err("invalid session id: %d", adapter->sessionId);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002209 return -EINVAL;
Arun Khandavalli99286452016-08-22 12:13:41 +05302210 }
2211
2212 mutex_lock(&pHddCtx->iface_change_lock);
2213 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
2214 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002215 hdd_debug("Driver Module not enabled return success");
Arun Khandavalli99286452016-08-22 12:13:41 +05302216 /* Send cached data to upperlayer*/
2217 *dbm = adapter->hdd_stats.ClassA_stat.max_pwr;
2218 return 0;
2219 }
2220 mutex_unlock(&pHddCtx->iface_change_lock);
2221
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302222 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05302223 TRACE_CODE_HDD_CFG80211_GET_TXPOWER,
Arun Khandavalli99286452016-08-22 12:13:41 +05302224 adapter->sessionId, adapter->device_mode));
2225 wlan_hdd_get_class_astats(adapter);
2226 *dbm = adapter->hdd_stats.ClassA_stat.max_pwr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002227
2228 EXIT();
2229 return 0;
2230}
2231
2232/**
2233 * wlan_hdd_cfg80211_get_txpower() - cfg80211 get power handler function
2234 * @wiphy: Pointer to wiphy structure.
2235 * @wdev: Pointer to wireless_dev structure.
2236 * @dbm: dbm
2237 *
2238 * This is the cfg80211 get txpower handler function which invokes
2239 * the internal function @__wlan_hdd_cfg80211_get_txpower with
2240 * SSR protection.
2241 *
2242 * Return: 0 for success, error number on failure.
2243 */
2244int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002245 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002246 int *dbm)
2247{
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002248 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002249
2250 cds_ssr_protect(__func__);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002251 ret = __wlan_hdd_cfg80211_get_txpower(wiphy, wdev, dbm);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002252 cds_ssr_unprotect(__func__);
2253
2254 return ret;
2255}
Kapil Gupta6213c012016-09-02 19:39:09 +05302256
2257/**
2258 * hdd_set_qpower_config() - set qpower config to firmware
2259 * @adapter: HDD adapter
2260 * @qpower: new qpower config value
2261 *
2262 * Return: 0 on success; Errno on failure
2263 */
2264int hdd_set_qpower_config(hdd_context_t *hddctx, hdd_adapter_t *adapter,
Dustin Brown10a7b712016-10-07 10:31:16 -07002265 u8 qpower)
Kapil Gupta6213c012016-09-02 19:39:09 +05302266{
Dustin Brown10a7b712016-10-07 10:31:16 -07002267 QDF_STATUS status;
Kapil Gupta6213c012016-09-02 19:39:09 +05302268
2269 if (!hddctx->config->enablePowersaveOffload) {
2270 hdd_err("qpower is disabled in configuration");
2271 return -EINVAL;
2272 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002273
Kapil Gupta6213c012016-09-02 19:39:09 +05302274 if (qpower > PS_DUTY_CYCLING_QPOWER ||
2275 qpower < PS_LEGACY_NODEEPSLEEP) {
Dustin Brown10a7b712016-10-07 10:31:16 -07002276 hdd_err("invalid qpower value: %d", qpower);
Kapil Gupta6213c012016-09-02 19:39:09 +05302277 return -EINVAL;
2278 }
Kapil Gupta6213c012016-09-02 19:39:09 +05302279
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08002280 if (hddctx->config->nMaxPsPoll) {
2281 if ((qpower == PS_QPOWER_NODEEPSLEEP) ||
2282 (qpower == PS_LEGACY_NODEEPSLEEP))
2283 qpower = PS_LEGACY_NODEEPSLEEP;
2284 else
2285 qpower = PS_LEGACY_DEEPSLEEP;
2286 hdd_info("Qpower disabled, %d", qpower);
2287 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002288 status = wma_set_qpower_config(adapter->sessionId, qpower);
2289 if (status != QDF_STATUS_SUCCESS) {
2290 hdd_err("failed to configure qpower: %d", status);
2291 return -EINVAL;
Kapil Gupta6213c012016-09-02 19:39:09 +05302292 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002293
Kapil Gupta6213c012016-09-02 19:39:09 +05302294 return 0;
2295}
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002296
Dustin Brown54096432017-02-23 13:00:44 -08002297
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002298#ifdef WLAN_SUSPEND_RESUME_TEST
Dustin Brownbc81a472016-10-26 16:56:59 -07002299static struct net_device *g_dev;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002300static struct wiphy *g_wiphy;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002301static enum wow_resume_trigger g_resume_trigger;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002302
2303#define HDD_FA_SUSPENDED_BIT (0)
2304static unsigned long fake_apps_state;
2305
Dustin Brownd53d1a82016-10-03 12:57:33 -07002306/**
2307 * __hdd_wlan_fake_apps_resume() - The core logic for
2308 * hdd_wlan_fake_apps_resume() skipping the call to hif_fake_apps_resume(),
2309 * which is only need for non-irq resume
Dustin Brownbc81a472016-10-26 16:56:59 -07002310 * @wiphy: the kernel wiphy struct for the device being resumed
2311 * @dev: the kernel net_device struct for the device being resumed
Dustin Brownd53d1a82016-10-03 12:57:33 -07002312 *
Dustin Brownbc81a472016-10-26 16:56:59 -07002313 * Return: none, calls QDF_BUG() on failure
Dustin Brownd53d1a82016-10-03 12:57:33 -07002314 */
Dustin Brownbc81a472016-10-26 16:56:59 -07002315static void __hdd_wlan_fake_apps_resume(struct wiphy *wiphy,
2316 struct net_device *dev)
Dustin Brownd53d1a82016-10-03 12:57:33 -07002317{
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002318 struct hif_opaque_softc *hif_ctx;
Dustin Brownddb59702017-01-12 16:20:31 -08002319 qdf_device_t qdf_dev;
Dustin Brownd53d1a82016-10-03 12:57:33 -07002320
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002321 hdd_debug("Unit-test resume WLAN");
Dustin Brownddb59702017-01-12 16:20:31 -08002322
2323 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2324 if (!qdf_dev) {
2325 hdd_err("Failed to get QDF device context");
2326 QDF_BUG(0);
2327 return;
2328 }
2329
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002330 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2331 if (!hif_ctx) {
2332 hdd_err("Failed to get HIF context");
2333 return;
2334 }
2335
Dustin Brownd53d1a82016-10-03 12:57:33 -07002336 if (!test_and_clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002337 hdd_debug("Not unit-test suspended; Nothing to do");
Dustin Brownd53d1a82016-10-03 12:57:33 -07002338 return;
2339 }
2340
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002341 /* simulate kernel disable irqs */
2342 QDF_BUG(!hif_apps_wake_irq_disable(hif_ctx));
Dustin Brownd53d1a82016-10-03 12:57:33 -07002343
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002344 QDF_BUG(!wlan_hdd_bus_resume_noirq());
Dustin Brownd53d1a82016-10-03 12:57:33 -07002345
2346 /* simulate kernel enable irqs */
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002347 QDF_BUG(!hif_apps_irqs_enable(hif_ctx));
Dustin Brownd53d1a82016-10-03 12:57:33 -07002348
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002349 QDF_BUG(!wlan_hdd_bus_resume());
Dustin Brownd53d1a82016-10-03 12:57:33 -07002350
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002351 QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy));
2352
2353 if (g_resume_trigger == WOW_RESUME_TRIGGER_HTC_WAKEUP)
2354 hif_vote_link_down(hif_ctx);
Dustin Brownbc81a472016-10-26 16:56:59 -07002355
2356 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Dustin Brown562b9672016-12-22 15:25:33 -08002357
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002358 hdd_debug("Unit-test resume succeeded");
Dustin Brownd53d1a82016-10-03 12:57:33 -07002359}
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002360
2361/**
2362 * hdd_wlan_fake_apps_resume_irq_callback() - Irq callback function for resuming
2363 * from unit-test initiated suspend from irq wakeup signal
2364 * @val: interrupt val
2365 *
2366 * Resume wlan after getting very 1st CE interrupt from target
2367 *
2368 * Return: none
2369 */
2370static void hdd_wlan_fake_apps_resume_irq_callback(uint32_t val)
2371{
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002372 hdd_debug("Trigger unit-test resume WLAN; val: 0x%x", val);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002373
2374 QDF_BUG(g_wiphy);
Dustin Brownbc81a472016-10-26 16:56:59 -07002375 QDF_BUG(g_dev);
2376 __hdd_wlan_fake_apps_resume(g_wiphy, g_dev);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002377 g_wiphy = NULL;
Dustin Brownbc81a472016-10-26 16:56:59 -07002378 g_dev = NULL;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002379}
2380
Dustin Brown54096432017-02-23 13:00:44 -08002381int hdd_wlan_fake_apps_suspend(struct wiphy *wiphy, struct net_device *dev,
2382 enum wow_interface_pause pause_setting,
2383 enum wow_resume_trigger resume_setting)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002384{
Dustin Brownddb59702017-01-12 16:20:31 -08002385 qdf_device_t qdf_dev;
2386 struct hif_opaque_softc *hif_ctx;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002387 int errno;
Dustin Brown54096432017-02-23 13:00:44 -08002388 struct wow_enable_params wow_params = {
2389 .is_unit_test = true,
2390 .interface_pause = pause_setting,
2391 .resume_trigger = resume_setting
2392 };
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002393
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002394 hdd_debug("Unit-test suspend WLAN");
Dustin Brownddb59702017-01-12 16:20:31 -08002395
Dustin Brown54096432017-02-23 13:00:44 -08002396 if (pause_setting < WOW_INTERFACE_PAUSE_DEFAULT ||
2397 pause_setting >= WOW_INTERFACE_PAUSE_COUNT) {
2398 hdd_err("Invalid interface pause %d (expected range [0, 2])",
2399 pause_setting);
2400 return -EINVAL;
2401 }
2402
2403 if (resume_setting < WOW_RESUME_TRIGGER_DEFAULT ||
2404 resume_setting >= WOW_RESUME_TRIGGER_COUNT) {
2405 hdd_err("Invalid resume trigger %d (expected range [0, 2])",
2406 resume_setting);
2407 return -EINVAL;
2408 }
2409
Dustin Brownddb59702017-01-12 16:20:31 -08002410 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2411 if (!qdf_dev) {
2412 hdd_err("Failed to get QDF device context");
2413 return -EINVAL;
2414 }
2415
2416 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2417 if (!hif_ctx) {
2418 hdd_err("Failed to get HIF context");
2419 return -EINVAL;
2420 }
2421
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002422 if (test_and_set_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002423 hdd_debug("Already unit-test suspended; Nothing to do");
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002424 return 0;
2425 }
2426
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002427 /* pci link is needed to wakeup from HTC wakeup trigger */
2428 if (resume_setting == WOW_RESUME_TRIGGER_HTC_WAKEUP)
2429 hif_vote_link_up(hif_ctx);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002430
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002431 errno = wlan_hdd_cfg80211_suspend_wlan(wiphy, NULL);
2432 if (errno)
2433 goto link_down;
2434
2435 errno = wlan_hdd_unit_test_bus_suspend(wow_params);
2436 if (errno)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002437 goto cfg80211_resume;
2438
2439 /* simulate kernel disabling irqs */
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002440 errno = hif_apps_irqs_disable(hif_ctx);
2441 if (errno)
2442 goto bus_resume;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002443
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002444 errno = wlan_hdd_bus_suspend_noirq();
2445 if (errno)
2446 goto enable_irqs;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002447
Dustin Brownbc81a472016-10-26 16:56:59 -07002448 /* pass wiphy/dev to callback via global variables */
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002449 g_wiphy = wiphy;
Dustin Brownbc81a472016-10-26 16:56:59 -07002450 g_dev = dev;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002451 g_resume_trigger = resume_setting;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002452 hif_fake_apps_suspend(hif_ctx, hdd_wlan_fake_apps_resume_irq_callback);
2453
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002454 /* re-enable wake irq */
2455 errno = hif_apps_wake_irq_enable(hif_ctx);
2456 if (errno)
2457 goto fake_apps_resume;
2458
Dustin Brownbc81a472016-10-26 16:56:59 -07002459 /*
2460 * Tell the kernel not to worry if TX queues aren't moving. This is
2461 * expected since we are suspending the wifi hardware, but not APPS
2462 */
2463 dev->watchdog_timeo = INT_MAX;
2464
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002465 hdd_debug("Unit-test suspend succeeded");
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002466
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002467 return 0;
2468
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002469fake_apps_resume:
2470 hif_fake_apps_resume(hif_ctx);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002471
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002472enable_irqs:
2473 QDF_BUG(!hif_apps_irqs_enable(hif_ctx));
2474
2475bus_resume:
2476 QDF_BUG(!wlan_hdd_bus_resume());
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002477
2478cfg80211_resume:
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002479 QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy));
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002480
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002481link_down:
2482 hif_vote_link_down(hif_ctx);
2483
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002484 clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state);
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002485 hdd_err("Unit-test suspend failed: %d", errno);
2486
2487 return errno;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002488}
2489
Dustin Brownbc81a472016-10-26 16:56:59 -07002490int hdd_wlan_fake_apps_resume(struct wiphy *wiphy, struct net_device *dev)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002491{
Dustin Brownddb59702017-01-12 16:20:31 -08002492 struct hif_opaque_softc *hif_ctx;
2493
2494 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2495 if (!hif_ctx) {
2496 hdd_err("Failed to get HIF context");
2497 return -EINVAL;
2498 }
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002499
2500 hif_fake_apps_resume(hif_ctx);
Dustin Brownbc81a472016-10-26 16:56:59 -07002501 __hdd_wlan_fake_apps_resume(wiphy, dev);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002502
2503 return 0;
2504}
2505#endif