blob: 8dc4451647f2ac8f568a17e94e51ee3b0dc63db2 [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"
Dustin Brown0f8dc3d2017-06-01 14:37:26 -070075#include "hif_unit_test_suspend.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080076#include "sme_power_save_api.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080077#include "wlan_policy_mgr_api.h"
Dhanashri Atreb08959a2016-03-01 17:28:03 -080078#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu13738502016-04-06 17:41:37 -070079#include "pld_common.h"
Rajeev Kumar9bb2e852016-09-24 12:29:25 -070080#include "wlan_hdd_driver_ops.h"
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +053081#include <wlan_logging_sock_svc.h>
Krunal Sonid32c6bc2016-10-18 18:00:21 -070082#include "scheduler_api.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +053083#include "cds_utils.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080084
85/* Preprocessor definitions and constants */
Yue Ma5fe30dd2017-05-02 15:47:40 -070086#ifdef QCA_WIFI_NAPIER_EMULATION
87#define HDD_SSR_BRING_UP_TIME 3000000
88#else
Yue Ma4ea4f052015-10-27 12:25:27 -070089#define HDD_SSR_BRING_UP_TIME 30000
Yue Ma5fe30dd2017-05-02 15:47:40 -070090#endif
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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138/**
Mukul Sharma3d36c392017-01-18 18:39:12 +0530139 * hdd_enable_gtk_offload() - enable GTK offload
140 * @adapter: pointer to the adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800141 *
Mukul Sharma3d36c392017-01-18 18:39:12 +0530142 * Central function to enable GTK offload.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800143 *
144 * Return: nothing
145 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700146static void hdd_enable_gtk_offload(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800147{
Mukul Sharma3d36c392017-01-18 18:39:12 +0530148 QDF_STATUS status;
149 status = pmo_ucfg_enable_gtk_offload_in_fwr(adapter->hdd_vdev);
150 if (status != QDF_STATUS_SUCCESS)
151 hdd_info("Failed to enable gtk offload");
152}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800153
Mukul Sharma3d36c392017-01-18 18:39:12 +0530154/**
155 * hdd_disable_gtk_offload() - disable GTK offload
156 * @pAdapter: pointer to the adapter
157 *
158 * Central function to disable GTK offload.
159 *
160 * Return: nothing
161 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700162static void hdd_disable_gtk_offload(struct hdd_adapter *adapter)
Mukul Sharma3d36c392017-01-18 18:39:12 +0530163{
164 struct pmo_gtk_rsp_req gtk_rsp_request;
165 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800166
Mukul Sharma3d36c392017-01-18 18:39:12 +0530167 /* ensure to get gtk rsp first before disable it*/
168 gtk_rsp_request.callback =
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530169 wlan_hdd_cfg80211_update_replay_counter_cb;
Mukul Sharma3d36c392017-01-18 18:39:12 +0530170 /* Passing as void* as PMO does not know legacy HDD adapter type */
171 gtk_rsp_request.callback_context =
172 (void *)adapter;
173 status = pmo_ucfg_get_gtk_rsp(adapter->hdd_vdev,
174 &gtk_rsp_request);
175 if (status != QDF_STATUS_SUCCESS) {
176 hdd_err("Failed to send get gtk rsp status:%d", status);
177 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800178 }
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800179 hdd_debug("send get_gtk_rsp successful");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530180 status = pmo_ucfg_disable_gtk_offload_in_fwr(adapter->hdd_vdev);
181 if (status != QDF_STATUS_SUCCESS)
182 hdd_info("Failed to disable gtk offload");
183
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800184}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530186
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800187/**
188 * __wlan_hdd_ipv6_changed() - IPv6 notifier callback function
189 * @nb: notifier block that was registered with the kernel
190 * @data: (unused) generic data that was registered with the kernel
191 * @arg: (unused) generic argument that was registered with the kernel
192 *
193 * This is a callback function that is registered with the kernel via
194 * register_inet6addr_notifier() which allows the driver to be
195 * notified when there is an IPv6 address change.
196 *
197 * Return: NOTIFY_DONE to indicate we don't care what happens with
198 * other callbacks
199 */
200static int __wlan_hdd_ipv6_changed(struct notifier_block *nb,
Dustin Brownf13b8c32017-05-19 17:23:08 -0700201 unsigned long data, void *arg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800202{
203 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
204 struct net_device *ndev = ifa->idev->dev;
Jeff Johnson75b737d2017-08-29 14:24:41 -0700205 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700206 struct hdd_context *hdd_ctx;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700207 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208
Jeff Johnson158c8d02016-10-31 13:11:48 -0700209 ENTER_DEV(ndev);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530210
Dustin Brownf13b8c32017-05-19 17:23:08 -0700211 errno = hdd_validate_adapter(adapter);
212 if (errno)
213 goto exit;
214
215 if (adapter->dev == ndev &&
216 (adapter->device_mode == QDF_STA_MODE ||
217 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
218 adapter->device_mode == QDF_NDI_MODE)) {
219 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
220 errno = wlan_hdd_validate_context(hdd_ctx);
221 if (errno)
222 goto exit;
223
Nachiket Kukadec9045fe2017-06-19 15:14:43 +0530224 /* Ignore if the interface is down */
225 if (!(ndev->flags & IFF_UP)) {
226 hdd_err("Rcvd change addr request on %s(flags 0x%X)",
227 ndev->name, ndev->flags);
228 hdd_err("NETDEV Interface is down, ignoring...");
229 goto exit;
230 }
231
Dustin Brownf13b8c32017-05-19 17:23:08 -0700232 hdd_debug("invoking sme_dhcp_done_ind");
233 sme_dhcp_done_ind(hdd_ctx->hHal, adapter->sessionId);
234 schedule_work(&adapter->ipv6NotifierWorkQueue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800235 }
236
Dustin Brownf13b8c32017-05-19 17:23:08 -0700237exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530238 EXIT();
Dustin Brownf13b8c32017-05-19 17:23:08 -0700239
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800240 return NOTIFY_DONE;
241}
242
243/**
244 * wlan_hdd_ipv6_changed() - IPv6 change notifier callback
245 * @nb: pointer to notifier block
246 * @data: data
247 * @arg: arg
248 *
249 * This is the IPv6 notifier callback function gets invoked
250 * if any change in IP and then invoke the function @__wlan_hdd_ipv6_changed
251 * to reconfigure the offload parameters.
252 *
253 * Return: 0 on success, error number otherwise.
254 */
255int wlan_hdd_ipv6_changed(struct notifier_block *nb,
256 unsigned long data, void *arg)
257{
258 int ret;
259
260 cds_ssr_protect(__func__);
261 ret = __wlan_hdd_ipv6_changed(nb, data, arg);
262 cds_ssr_unprotect(__func__);
263
264 return ret;
265}
266
267/**
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530268 * hdd_fill_ipv6_uc_addr() - fill IPv6 unicast addresses
269 * @idev: pointer to net device
270 * @ipv6addr: destination array to fill IPv6 addresses
271 * @ipv6addr_type: IPv6 Address type
272 * @count: number of IPv6 addresses
273 *
274 * This is the IPv6 utility function to populate unicast addresses.
275 *
276 * Return: 0 on success, error number otherwise.
277 */
278static int hdd_fill_ipv6_uc_addr(struct inet6_dev *idev,
279 uint8_t ipv6_uc_addr[][SIR_MAC_IPV6_ADDR_LEN],
280 uint8_t *ipv6addr_type, uint32_t *count)
281{
282 struct inet6_ifaddr *ifa;
283 struct list_head *p;
284 uint32_t scope;
285
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700286 read_lock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530287 list_for_each(p, &idev->addr_list) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530288 if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) {
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700289 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530290 return -EINVAL;
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700291 }
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530292 ifa = list_entry(p, struct inet6_ifaddr, if_list);
293 if (ifa->flags & IFA_F_DADFAILED)
294 continue;
295 scope = ipv6_addr_src_scope(&ifa->addr);
296 switch (scope) {
297 case IPV6_ADDR_SCOPE_GLOBAL:
298 case IPV6_ADDR_SCOPE_LINKLOCAL:
299 qdf_mem_copy(ipv6_uc_addr[*count], &ifa->addr.s6_addr,
300 sizeof(ifa->addr.s6_addr));
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530301 ipv6addr_type[*count] = PMO_IPV6_ADDR_UC_TYPE;
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800302 hdd_debug("Index %d scope = %s UC-Address: %pI6",
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530303 *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ?
304 "LINK LOCAL" : "GLOBAL", ipv6_uc_addr[*count]);
305 *count += 1;
306 break;
307 default:
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800308 hdd_warn("The Scope %d is not supported", scope);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530309 }
310 }
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700311
312 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530313 return 0;
314}
315
316/**
317 * hdd_fill_ipv6_ac_addr() - fill IPv6 anycast addresses
318 * @idev: pointer to net device
319 * @ipv6addr: destination array to fill IPv6 addresses
320 * @ipv6addr_type: IPv6 Address type
321 * @count: number of IPv6 addresses
322 *
323 * This is the IPv6 utility function to populate anycast addresses.
324 *
325 * Return: 0 on success, error number otherwise.
326 */
327static int hdd_fill_ipv6_ac_addr(struct inet6_dev *idev,
328 uint8_t ipv6_ac_addr[][SIR_MAC_IPV6_ADDR_LEN],
329 uint8_t *ipv6addr_type, uint32_t *count)
330{
331 struct ifacaddr6 *ifaca;
332 uint32_t scope;
333
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700334 read_lock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530335 for (ifaca = idev->ac_list; ifaca; ifaca = ifaca->aca_next) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530336 if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) {
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700337 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530338 return -EINVAL;
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700339 }
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530340 /* For anycast addr no DAD */
341 scope = ipv6_addr_src_scope(&ifaca->aca_addr);
342 switch (scope) {
343 case IPV6_ADDR_SCOPE_GLOBAL:
344 case IPV6_ADDR_SCOPE_LINKLOCAL:
345 qdf_mem_copy(ipv6_ac_addr[*count], &ifaca->aca_addr,
346 sizeof(ifaca->aca_addr));
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530347 ipv6addr_type[*count] = PMO_IPV6_ADDR_AC_TYPE;
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800348 hdd_debug("Index %d scope = %s AC-Address: %pI6",
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530349 *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ?
350 "LINK LOCAL" : "GLOBAL", ipv6_ac_addr[*count]);
351 *count += 1;
352 break;
353 default:
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800354 hdd_warn("The Scope %d is not supported", scope);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530355 }
356 }
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700357
358 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530359 return 0;
360}
361
Jeff Johnson75b737d2017-08-29 14:24:41 -0700362void hdd_enable_ns_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530363 enum pmo_offload_trigger trigger)
Dustin Brown2444ee62016-09-06 17:20:36 -0700364{
365 struct inet6_dev *in6_dev;
Dustin Brown2444ee62016-09-06 17:20:36 -0700366 QDF_STATUS status;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700367 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530368 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
369 struct pmo_ns_req *ns_req = NULL;
370 int err;
371
372 ENTER();
373 if (!psoc) {
374 hdd_err("psoc is NULL");
375 goto out;
376 }
Dustin Brown2444ee62016-09-06 17:20:36 -0700377
378 in6_dev = __in6_dev_get(adapter->dev);
379 if (NULL == in6_dev) {
380 hdd_err("IPv6 dev does not exist. Failed to request NSOffload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530381 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700382 }
383
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530384 ns_req = qdf_mem_malloc(sizeof(*ns_req));
385 if (!ns_req) {
386 hdd_err("fail to allocate ns_req");
387 goto out;
388 }
389
390 ns_req->psoc = psoc;
391 ns_req->vdev_id = adapter->sessionId;
392 ns_req->trigger = trigger;
393 ns_req->count = 0;
394
Dustin Brown2444ee62016-09-06 17:20:36 -0700395 /* Unicast Addresses */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530396 err = hdd_fill_ipv6_uc_addr(in6_dev, ns_req->ipv6_addr,
397 ns_req->ipv6_addr_type, &ns_req->count);
Dustin Brown2444ee62016-09-06 17:20:36 -0700398 if (err) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530399 hdd_disable_ns_offload(adapter, trigger);
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530400 hdd_debug("Max supported addresses: disabling NS offload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530401 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700402 }
403
404 /* Anycast Addresses */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530405 err = hdd_fill_ipv6_ac_addr(in6_dev, ns_req->ipv6_addr,
406 ns_req->ipv6_addr_type, &ns_req->count);
Dustin Brown2444ee62016-09-06 17:20:36 -0700407 if (err) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530408 hdd_disable_ns_offload(adapter, trigger);
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530409 hdd_debug("Max supported addresses: disabling NS offload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530410 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700411 }
412
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530413 /* cache ns request */
414 status = pmo_ucfg_cache_ns_offload_req(ns_req);
415 if (status != QDF_STATUS_SUCCESS) {
416 hdd_err("Failed to cache ns request status: %d", status);
417 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700418 }
419
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530420 /* enable ns request */
421 status = pmo_ucfg_enable_ns_offload_in_fwr(adapter->hdd_vdev, trigger);
422 if (status != QDF_STATUS_SUCCESS)
Dustin Brown2444ee62016-09-06 17:20:36 -0700423 hdd_err("Failed to enable HostOffload feature with status: %d",
424 status);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530425 else
426 hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD, SIR_OFFLOAD_ENABLE);
427out:
428 if (ns_req)
429 qdf_mem_free(ns_req);
430 EXIT();
431
Dustin Brown2444ee62016-09-06 17:20:36 -0700432}
433
Jeff Johnson75b737d2017-08-29 14:24:41 -0700434void hdd_disable_ns_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530435 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800436{
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530437 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800438
439 ENTER();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530440 status = pmo_ucfg_flush_ns_offload_req(adapter->hdd_vdev);
441 if (status != QDF_STATUS_SUCCESS) {
442 hdd_err("Failed to flush NS Offload");
443 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800444 }
445
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530446 status = pmo_ucfg_disable_ns_offload_in_fwr(adapter->hdd_vdev, trigger);
447 if (status != QDF_STATUS_SUCCESS)
448 hdd_err("Failed to disable NS Offload");
Dustin Brown2444ee62016-09-06 17:20:36 -0700449 else
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530450 hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD,
451 SIR_OFFLOAD_DISABLE);
452out:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800453 EXIT();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530454
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800455}
456
457/**
458 * __hdd_ipv6_notifier_work_queue() - IPv6 notification work function
459 * @work: registered work item
460 *
461 * This function performs the work initially trigged by a callback
462 * from the IPv6 netdev notifier. Since this means there has been a
463 * change in IPv6 state for the interface, the NS offload is
464 * reconfigured.
465 *
466 * Return: None
467 */
Jeff Johnsonc8d0c252016-10-05 16:19:50 -0700468static void __hdd_ipv6_notifier_work_queue(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800469{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700470 struct hdd_context *hdd_ctx;
Jeff Johnson75b737d2017-08-29 14:24:41 -0700471 struct hdd_adapter *adapter;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700472 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800473
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530474 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800475
Jeff Johnson75b737d2017-08-29 14:24:41 -0700476 adapter = container_of(work, struct hdd_adapter, ipv6NotifierWorkQueue);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700477 errno = hdd_validate_adapter(adapter);
478 if (errno)
479 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800480
Dustin Brownf13b8c32017-05-19 17:23:08 -0700481 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
482 errno = wlan_hdd_validate_context(hdd_ctx);
483 if (errno)
484 goto exit;
485
486 hdd_enable_ns_offload(adapter, pmo_ipv6_change_notify);
487
488exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530489 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490}
491
492/**
493 * hdd_ipv6_notifier_work_queue() - IP V6 change notifier work handler
494 * @work: Pointer to work context
495 *
496 * Return: none
497 */
498void hdd_ipv6_notifier_work_queue(struct work_struct *work)
499{
500 cds_ssr_protect(__func__);
501 __hdd_ipv6_notifier_work_queue(work);
502 cds_ssr_unprotect(__func__);
503}
504
Jeff Johnson75b737d2017-08-29 14:24:41 -0700505static void hdd_enable_hw_filter(struct hdd_adapter *adapter)
Dustin Brown1224e212017-05-12 14:02:12 -0700506{
507 QDF_STATUS status;
508
509 ENTER();
510
511 status = pmo_ucfg_enable_hw_filter_in_fwr(adapter->hdd_vdev);
512 if (status != QDF_STATUS_SUCCESS)
513 hdd_info("Failed to enable hardware filter");
514
515 EXIT();
516}
517
Jeff Johnson75b737d2017-08-29 14:24:41 -0700518static void hdd_disable_hw_filter(struct hdd_adapter *adapter)
Dustin Brown1224e212017-05-12 14:02:12 -0700519{
520 QDF_STATUS status;
521
522 ENTER();
523
524 status = pmo_ucfg_disable_hw_filter_in_fwr(adapter->hdd_vdev);
525 if (status != QDF_STATUS_SUCCESS)
526 hdd_info("Failed to disable hardware filter");
527
528 EXIT();
529}
530
Jeff Johnson75b737d2017-08-29 14:24:41 -0700531void hdd_enable_host_offloads(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530532 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800533{
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530534 ENTER();
535
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530536 if (!pmo_ucfg_is_vdev_supports_offload(adapter->hdd_vdev)) {
537 hdd_info("offload is not supported on this vdev opmode: %d",
538 adapter->device_mode);
539 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800540 }
541
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530542 if (!pmo_ucfg_is_vdev_connected(adapter->hdd_vdev)) {
543 hdd_info("vdev is not connected");
544 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800545 }
546
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530547 hdd_info("enable offloads");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530548 hdd_enable_gtk_offload(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530549 hdd_enable_arp_offload(adapter, trigger);
550 hdd_enable_ns_offload(adapter, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530551 hdd_enable_mc_addr_filtering(adapter, trigger);
Dustin Brown1224e212017-05-12 14:02:12 -0700552 hdd_enable_hw_filter(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530553out:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530554 EXIT();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530555
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800556}
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530557
Jeff Johnson75b737d2017-08-29 14:24:41 -0700558void hdd_disable_host_offloads(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530559 enum pmo_offload_trigger trigger)
560{
561 ENTER();
562
563 if (!pmo_ucfg_is_vdev_supports_offload(adapter->hdd_vdev)) {
564 hdd_info("offload is not supported on this vdev opmode: %d",
565 adapter->device_mode);
566 goto out;
567 }
568
569 if (!pmo_ucfg_is_vdev_connected(adapter->hdd_vdev)) {
570 hdd_info("vdev is not connected");
571 goto out;
572 }
573
574 hdd_info("disable offloads");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530575 hdd_disable_gtk_offload(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530576 hdd_disable_arp_offload(adapter, trigger);
577 hdd_disable_ns_offload(adapter, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530578 hdd_disable_mc_addr_filtering(adapter, trigger);
Dustin Brown1224e212017-05-12 14:02:12 -0700579 hdd_disable_hw_filter(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530580out:
581 EXIT();
582
583}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584
585/**
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800586 * hdd_lookup_ifaddr() - Lookup interface address data by name
587 * @adapter: the adapter whose name should be searched for
588 *
589 * return in_ifaddr pointer on success, NULL for failure
590 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700591static struct in_ifaddr *hdd_lookup_ifaddr(struct hdd_adapter *adapter)
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800592{
593 struct in_ifaddr *ifa;
594 struct in_device *in_dev;
595
596 if (!adapter) {
597 hdd_err("adapter is null");
598 return NULL;
599 }
600
601 in_dev = __in_dev_get_rtnl(adapter->dev);
602 if (!in_dev) {
603 hdd_err("Failed to get in_device");
604 return NULL;
605 }
606
607 /* lookup address data by interface name */
608 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
609 if (!strcmp(adapter->dev->name, ifa->ifa_label))
610 return ifa;
611 }
612
613 return NULL;
614}
615
616/**
617 * hdd_populate_ipv4_addr() - Populates the adapter's IPv4 address
618 * @adapter: the adapter whose IPv4 address is desired
619 * @ipv4_addr: the address of the array to copy the IPv4 address into
620 *
621 * return: zero for success; non-zero for failure
622 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700623static int hdd_populate_ipv4_addr(struct hdd_adapter *adapter, uint8_t *ipv4_addr)
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800624{
625 struct in_ifaddr *ifa;
626 int i;
627
628 if (!adapter) {
629 hdd_err("adapter is null");
630 return -EINVAL;
631 }
632
633 if (!ipv4_addr) {
634 hdd_err("ipv4_addr is null");
635 return -EINVAL;
636 }
637
638 ifa = hdd_lookup_ifaddr(adapter);
639 if (!ifa || !ifa->ifa_local) {
640 hdd_err("ipv4 address not found");
641 return -EINVAL;
642 }
643
644 /* convert u32 to byte array */
645 for (i = 0; i < 4; i++)
646 ipv4_addr[i] = (ifa->ifa_local >> i * 8) & 0xff;
647
648 return 0;
649}
650
651/**
652 * hdd_set_grat_arp_keepalive() - Enable grat APR keepalive
653 * @adapter: the HDD adapter to configure
654 *
655 * This configures gratuitous APR keepalive based on the adapter's current
656 * connection information, specifically IPv4 address and BSSID
657 *
658 * return: zero for success, non-zero for failure
659 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700660static int hdd_set_grat_arp_keepalive(struct hdd_adapter *adapter)
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800661{
662 QDF_STATUS status;
663 int exit_code;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700664 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -0700665 struct hdd_station_ctx *sta_ctx;
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800666 tSirKeepAliveReq req = {
667 .packetType = SIR_KEEP_ALIVE_UNSOLICIT_ARP_RSP,
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800668 .dest_macaddr = QDF_MAC_ADDR_BROADCAST_INITIALIZER,
669 };
670
671 if (!adapter) {
672 hdd_err("adapter is null");
673 return -EINVAL;
674 }
675
676 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
677 if (!hdd_ctx) {
678 hdd_err("hdd_ctx is null");
679 return -EINVAL;
680 }
681
682 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
683 if (!sta_ctx) {
684 hdd_err("sta_ctx is null");
685 return -EINVAL;
686 }
687
688 exit_code = hdd_populate_ipv4_addr(adapter, req.hostIpv4Addr);
689 if (exit_code) {
690 hdd_err("Failed to populate ipv4 address");
691 return exit_code;
692 }
693
Dustin Brown6b4643d2017-02-09 12:19:28 -0800694 /* according to RFC5227, sender/target ip address should be the same */
695 qdf_mem_copy(&req.destIpv4Addr, &req.hostIpv4Addr,
696 sizeof(req.destIpv4Addr));
697
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800698 qdf_copy_macaddr(&req.bssid, &sta_ctx->conn_info.bssId);
699 req.timePeriod = hdd_ctx->config->infraStaKeepAlivePeriod;
700 req.sessionId = adapter->sessionId;
701
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800702 hdd_debug("Setting gratuitous ARP keepalive; ipv4_addr:%u.%u.%u.%u",
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800703 req.hostIpv4Addr[0], req.hostIpv4Addr[1],
704 req.hostIpv4Addr[2], req.hostIpv4Addr[3]);
705
706 status = sme_set_keep_alive(hdd_ctx->hHal, req.sessionId, &req);
707 if (QDF_IS_STATUS_ERROR(status)) {
708 hdd_err("Failed to set keepalive");
709 return qdf_status_to_os_return(status);
710 }
711
712 return 0;
713}
714
715/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800716 * __hdd_ipv4_notifier_work_queue() - IPv4 notification work function
717 * @work: registered work item
718 *
719 * This function performs the work initially trigged by a callback
720 * from the IPv4 netdev notifier. Since this means there has been a
721 * change in IPv4 state for the interface, the ARP offload is
722 * reconfigured.
723 *
724 * Return: None
725 */
Jeff Johnsonc8d0c252016-10-05 16:19:50 -0700726static void __hdd_ipv4_notifier_work_queue(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700728 struct hdd_context *hdd_ctx;
Jeff Johnson75b737d2017-08-29 14:24:41 -0700729 struct hdd_adapter *adapter;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700730 int errno;
Dustin Brownb6b0f182017-03-08 13:08:27 -0800731
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530732 ENTER();
Dustin Brownb6b0f182017-03-08 13:08:27 -0800733
Jeff Johnson75b737d2017-08-29 14:24:41 -0700734 adapter = container_of(work, struct hdd_adapter, ipv4NotifierWorkQueue);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700735 errno = hdd_validate_adapter(adapter);
736 if (errno)
737 goto exit;
Dustin Brownb6b0f182017-03-08 13:08:27 -0800738
739 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700740 errno = wlan_hdd_validate_context(hdd_ctx);
741 if (errno)
742 goto exit;
743
744 hdd_enable_arp_offload(adapter, pmo_ipv4_change_notify);
745
Dustin Brownb6b0f182017-03-08 13:08:27 -0800746 if (hdd_ctx->config->sta_keepalive_method == HDD_STA_KEEPALIVE_GRAT_ARP)
747 hdd_set_grat_arp_keepalive(adapter);
748
Dustin Brownf13b8c32017-05-19 17:23:08 -0700749exit:
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530750 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751}
752
753/**
754 * hdd_ipv4_notifier_work_queue() - IP V4 change notifier work handler
755 * @work: Pointer to work context
756 *
757 * Return: none
758 */
759void hdd_ipv4_notifier_work_queue(struct work_struct *work)
760{
761 cds_ssr_protect(__func__);
762 __hdd_ipv4_notifier_work_queue(work);
763 cds_ssr_unprotect(__func__);
764}
765
766/**
767 * __wlan_hdd_ipv4_changed() - IPv4 notifier callback function
768 * @nb: notifier block that was registered with the kernel
769 * @data: (unused) generic data that was registered with the kernel
770 * @arg: (unused) generic argument that was registered with the kernel
771 *
772 * This is a callback function that is registered with the kernel via
773 * register_inetaddr_notifier() which allows the driver to be
774 * notified when there is an IPv4 address change.
775 *
776 * Return: NOTIFY_DONE to indicate we don't care what happens with
777 * other callbacks
778 */
779static int __wlan_hdd_ipv4_changed(struct notifier_block *nb,
780 unsigned long data, void *arg)
781{
782 struct in_ifaddr *ifa = (struct in_ifaddr *)arg;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783 struct net_device *ndev = ifa->ifa_dev->dev;
Jeff Johnson75b737d2017-08-29 14:24:41 -0700784 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700785 struct hdd_context *hdd_ctx;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700786 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787
Jeff Johnson158c8d02016-10-31 13:11:48 -0700788 ENTER_DEV(ndev);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530789
Dustin Brownf13b8c32017-05-19 17:23:08 -0700790 errno = hdd_validate_adapter(adapter);
791 if (errno)
792 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793
Dustin Brownf13b8c32017-05-19 17:23:08 -0700794 if (adapter->dev == ndev &&
795 (adapter->device_mode == QDF_STA_MODE ||
796 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
797 adapter->device_mode == QDF_NDI_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800798
Dustin Brownf13b8c32017-05-19 17:23:08 -0700799 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
800 errno = wlan_hdd_validate_context(hdd_ctx);
801 if (errno)
802 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803
Nachiket Kukadec9045fe2017-06-19 15:14:43 +0530804 /* Ignore if the interface is down */
805 if (!(ndev->flags & IFF_UP)) {
806 hdd_err("Rcvd change addr request on %s(flags 0x%X)",
807 ndev->name, ndev->flags);
808 hdd_err("NETDEV Interface is down, ignoring...");
809 goto exit;
810 }
Padma, Santhosh Kumar8392fb42017-03-17 12:35:27 +0530811 hdd_debug("invoking sme_dhcp_done_ind");
Dustin Brownf13b8c32017-05-19 17:23:08 -0700812 sme_dhcp_done_ind(hdd_ctx->hHal, adapter->sessionId);
Abhishek Singhca408032016-09-13 15:26:12 +0530813
Dustin Brownf13b8c32017-05-19 17:23:08 -0700814 if (!hdd_ctx->config->fhostArpOffload) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800815 hdd_debug("Offload not enabled ARPOffload=%d",
Dustin Brownf13b8c32017-05-19 17:23:08 -0700816 hdd_ctx->config->fhostArpOffload);
817 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800818 }
819
Dustin Brownf13b8c32017-05-19 17:23:08 -0700820 ifa = hdd_lookup_ifaddr(adapter);
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800821 if (ifa && ifa->ifa_local)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700822 schedule_work(&adapter->ipv4NotifierWorkQueue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 }
Dustin Brownf13b8c32017-05-19 17:23:08 -0700824
825exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530826 EXIT();
Dustin Brownf13b8c32017-05-19 17:23:08 -0700827
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 return NOTIFY_DONE;
829}
830
831/**
832 * wlan_hdd_ipv4_changed() - IPv4 change notifier callback
833 * @nb: pointer to notifier block
834 * @data: data
835 * @arg: arg
836 *
837 * This is the IPv4 notifier callback function gets invoked
838 * if any change in IP and then invoke the function @__wlan_hdd_ipv4_changed
839 * to reconfigure the offload parameters.
840 *
841 * Return: 0 on success, error number otherwise.
842 */
843int wlan_hdd_ipv4_changed(struct notifier_block *nb,
844 unsigned long data, void *arg)
845{
846 int ret;
847
848 cds_ssr_protect(__func__);
849 ret = __wlan_hdd_ipv4_changed(nb, data, arg);
850 cds_ssr_unprotect(__func__);
851
852 return ret;
853}
854
855/**
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530856 * hdd_get_ipv4_local_interface() - get ipv4 local interafce from iface list
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 * @pAdapter: Adapter context for which ARP offload is to be configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 *
859 * Return:
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530860 * ifa - on successful operation,
861 * NULL - on failure of operation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530863static struct in_ifaddr *hdd_get_ipv4_local_interface(
Jeff Johnson75b737d2017-08-29 14:24:41 -0700864 struct hdd_adapter *pAdapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800865{
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530866 struct in_ifaddr **ifap = NULL;
867 struct in_ifaddr *ifa = NULL;
868 struct in_device *in_dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530870 in_dev = __in_dev_get_rtnl(pAdapter->dev);
871 if (in_dev) {
872 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
873 ifap = &ifa->ifa_next) {
874 if (!strcmp(pAdapter->dev->name, ifa->ifa_label)) {
875 /* if match break */
876 return ifa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878 }
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530879 }
880 ifa = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800881
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530882 return ifa;
883}
884
Jeff Johnson75b737d2017-08-29 14:24:41 -0700885void hdd_enable_arp_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530886 enum pmo_offload_trigger trigger)
887{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700888 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530889 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
890 QDF_STATUS status;
891 struct pmo_arp_req *arp_req = NULL;
892 struct in_ifaddr *ifa = NULL;
893
894 ENTER();
895 arp_req = qdf_mem_malloc(sizeof(*arp_req));
896 if (!arp_req) {
897 hdd_err("cannot allocate arp_req");
898 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899 }
Jeff Johnson68755312017-02-10 11:46:55 -0800900
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530901 arp_req->psoc = psoc;
902 arp_req->vdev_id = adapter->sessionId;
903 arp_req->trigger = trigger;
Jeff Johnson68755312017-02-10 11:46:55 -0800904
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530905 ifa = hdd_get_ipv4_local_interface(adapter);
906 if (ifa && ifa->ifa_local) {
907 arp_req->ipv4_addr = (uint32_t)ifa->ifa_local;
908 status = pmo_ucfg_cache_arp_offload_req(arp_req);
909 if (status == QDF_STATUS_SUCCESS) {
910 status = pmo_ucfg_enable_arp_offload_in_fwr(
911 adapter->hdd_vdev, trigger);
912 if (status == QDF_STATUS_SUCCESS)
913 hdd_wlan_offload_event(
914 PMO_IPV4_ARP_REPLY_OFFLOAD,
915 PMO_OFFLOAD_ENABLE);
916 else
917 hdd_info("fail to enable arp offload in fwr");
918 } else
919 hdd_info("fail to cache arp offload request");
920 } else {
921 hdd_notice("IP Address is not assigned");
922 status = QDF_STATUS_NOT_INITIALIZED;
923 }
924out:
925 if (arp_req)
926 qdf_mem_free(arp_req);
927 EXIT();
928
929}
930
Jeff Johnson75b737d2017-08-29 14:24:41 -0700931void hdd_disable_arp_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530932 enum pmo_offload_trigger trigger)
933{
934 QDF_STATUS status;
935
936 ENTER();
937 status = pmo_ucfg_flush_arp_offload_req(adapter->hdd_vdev);
938 if (status != QDF_STATUS_SUCCESS) {
939 hdd_err("Failed to flush arp Offload");
940 goto out;
Jeff Johnson68755312017-02-10 11:46:55 -0800941 }
942
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530943 status = pmo_ucfg_disable_arp_offload_in_fwr(adapter->hdd_vdev, trigger);
944 if (status == QDF_STATUS_SUCCESS)
945 hdd_wlan_offload_event(PMO_IPV4_ARP_REPLY_OFFLOAD,
946 PMO_OFFLOAD_DISABLE);
947 else
948 hdd_info("fail to disable arp offload");
949out:
950 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951}
952
Jeff Johnson75b737d2017-08-29 14:24:41 -0700953void hdd_enable_mc_addr_filtering(struct hdd_adapter *adapter,
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530954 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700956 struct hdd_context *hdd_ctx = (struct hdd_context *)adapter->pHddCtx;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530957 QDF_STATUS status;
958 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959
Ravi Joshi24477b72016-07-19 15:45:09 -0700960 ENTER();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530961 if (wlan_hdd_validate_context(hdd_ctx))
962 goto out;
Ravi Joshi24477b72016-07-19 15:45:09 -0700963
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530964 status = pmo_ucfg_enable_mc_addr_filtering_in_fwr(psoc,
965 adapter->sessionId, trigger);
966 if (status != QDF_STATUS_SUCCESS)
967 hdd_info("failed to enable mc list status %d", status);
968out:
Ravi Joshi24477b72016-07-19 15:45:09 -0700969 EXIT();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530970
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971}
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530972
Jeff Johnson75b737d2017-08-29 14:24:41 -0700973void hdd_disable_mc_addr_filtering(struct hdd_adapter *adapter,
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530974 enum pmo_offload_trigger trigger)
975{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700976 struct hdd_context *hdd_ctx = (struct hdd_context *)adapter->pHddCtx;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530977 QDF_STATUS status = QDF_STATUS_SUCCESS;
978 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
979
980 ENTER();
981 if (wlan_hdd_validate_context(hdd_ctx))
982 goto out;
983
984 status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc,
985 adapter->sessionId, trigger);
986 if (status != QDF_STATUS_SUCCESS)
987 hdd_info("failed to disable mc list status %d", status);
988out:
989 EXIT();
990
991}
992
993int hdd_cache_mc_addr_list(struct pmo_mc_addr_list_params *mc_list_config)
994{
995 QDF_STATUS status;
996 int ret = 0;
997
998 ENTER();
999 /* cache mc addr list */
1000 status = pmo_ucfg_cache_mc_addr_list(mc_list_config);
1001 if (status != QDF_STATUS_SUCCESS) {
1002 hdd_info("fail to cache mc list status %d", status);
1003 ret = -EINVAL;
1004 }
1005 EXIT();
1006
1007 return ret;
1008}
1009
Jeff Johnson75b737d2017-08-29 14:24:41 -07001010void hdd_disable_and_flush_mc_addr_list(struct hdd_adapter *adapter,
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05301011 enum pmo_offload_trigger trigger)
1012{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001013 struct hdd_context *hdd_ctx = (struct hdd_context *)adapter->pHddCtx;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05301014 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1015 QDF_STATUS status = QDF_STATUS_SUCCESS;
1016
1017 ENTER();
1018 /* disable mc list first */
1019 status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc,
1020 adapter->sessionId, trigger);
1021 if (status != QDF_STATUS_SUCCESS)
1022 hdd_info("fail to disable mc list");
1023
1024 /* flush mc list */
1025 status = pmo_ucfg_flush_mc_addr_list(psoc, adapter->sessionId);
1026 if (status != QDF_STATUS_SUCCESS)
1027 hdd_info("fail to flush mc list status %d", status);
1028 EXIT();
1029
1030 return;
1031
1032}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033
1034/**
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001035 * hdd_update_conn_state_mask(): record info needed by wma_suspend_req
1036 * @adapter: adapter to get info from
1037 * @conn_state_mask: mask of connection info
1038 *
1039 * currently only need to send connection info.
1040 */
1041static void
Jeff Johnson75b737d2017-08-29 14:24:41 -07001042hdd_update_conn_state_mask(struct hdd_adapter *adapter, uint32_t *conn_state_mask)
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001043{
1044
1045 eConnectionState connState;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07001046 struct hdd_station_ctx *sta_ctx;
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301047
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001048 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301049
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001050 connState = sta_ctx->conn_info.connState;
1051
1052 if (connState == eConnectionState_Associated ||
1053 connState == eConnectionState_IbssConnected)
1054 *conn_state_mask |= (1 << adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001055}
1056
1057/**
1058 * hdd_suspend_wlan() - Driver suspend function
1059 * @callback: Callback function to invoke when driver is ready to suspend
1060 * @callbackContext: Context to pass back to @callback function
1061 *
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301062 * Return: 0 on success else error code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301064static int
1065hdd_suspend_wlan(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001067 struct hdd_context *pHddCtx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301069 QDF_STATUS status;
Jeff Johnson75b737d2017-08-29 14:24:41 -07001070 struct hdd_adapter *pAdapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001072 uint32_t conn_state_mask = 0;
Jeff Johnsonc3273322016-07-06 15:28:17 -07001073 hdd_info("WLAN being suspended by OS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074
Anurag Chouhan6d760662016-02-20 16:05:43 +05301075 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 if (!pHddCtx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001077 hdd_err("HDD context is Null");
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301078 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 }
1080
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301081 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001082 hdd_info("Recovery in Progress. State: 0x%x Ignore suspend!!!",
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001083 cds_get_driver_state());
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301084 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 }
1086
1087 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301088 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001089 pAdapter = pAdapterNode->pAdapter;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301090 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
1091 hdd_err("invalid session id: %d", pAdapter->sessionId);
1092 goto next_adapter;
1093 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001094
1095 /* stop all TX queues before suspend */
Srinivas Girigowda6598eea2017-07-06 19:26:19 -07001096 hdd_info("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05301097 wlan_hdd_netif_queue_control(pAdapter,
1098 WLAN_STOP_ALL_NETIF_QUEUE,
1099 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001100
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001101 /* Configure supported OffLoads */
Mukul Sharma3ba26b82017-01-12 21:59:41 +05301102 hdd_enable_host_offloads(pAdapter, pmo_apps_suspend);
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001103 hdd_update_conn_state_mask(pAdapter, &conn_state_mask);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301104next_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1106 pAdapterNode = pNext;
1107 }
1108
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301109 status = pmo_ucfg_psoc_user_space_suspend_req(pHddCtx->hdd_psoc,
1110 QDF_SYSTEM_SUSPEND);
1111 if (status != QDF_STATUS_SUCCESS)
1112 return -EAGAIN;
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001113
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 pHddCtx->hdd_wlan_suspended = true;
Abhishek Singhbaea27d2016-04-27 13:29:30 +05301115 hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_SUSPEND);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001116
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301117 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001118}
1119
1120/**
1121 * hdd_resume_wlan() - Driver resume function
1122 *
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301123 * Return: 0 on success else error code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301125static int hdd_resume_wlan(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001126{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001127 struct hdd_context *pHddCtx;
Jeff Johnson75b737d2017-08-29 14:24:41 -07001128 struct hdd_adapter *pAdapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301130 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131
Dustin Brown2d228232016-09-22 15:06:19 -07001132 hdd_info("WLAN being resumed by OS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001133
Anurag Chouhan6d760662016-02-20 16:05:43 +05301134 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 if (!pHddCtx) {
Dustin Brown2d228232016-09-22 15:06:19 -07001136 hdd_err("HDD context is Null");
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301137 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 }
1139
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301140 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001141 hdd_info("Recovery in Progress. State: 0x%x Ignore resume!!!",
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001142 cds_get_driver_state());
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301143 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 }
1145
1146 pHddCtx->hdd_wlan_suspended = false;
Abhishek Singhbaea27d2016-04-27 13:29:30 +05301147 hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_RESUME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148
1149 /*loop through all adapters. Concurrency */
1150 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
1151
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301152 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001153 pAdapter = pAdapterNode->pAdapter;
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301154 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
1155 hdd_err("invalid session id: %d", pAdapter->sessionId);
1156 goto next_adapter;
1157 }
1158 /* Disable supported OffLoads */
1159 hdd_disable_host_offloads(pAdapter, pmo_apps_resume);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160
1161 /* wake the tx queues */
Dustin Brown2d228232016-09-22 15:06:19 -07001162 hdd_info("Enabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 wlan_hdd_netif_queue_control(pAdapter,
1164 WLAN_WAKE_ALL_NETIF_QUEUE,
1165 WLAN_CONTROL_PATH);
1166
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301167next_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001168 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1169 pAdapterNode = pNext;
1170 }
1171 hdd_ipa_resume(pHddCtx);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301172 status = pmo_ucfg_psoc_user_space_resume_req(pHddCtx->hdd_psoc,
1173 QDF_SYSTEM_SUSPEND);
1174 if (status != QDF_STATUS_SUCCESS)
1175 return -EAGAIN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301177 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178}
1179
1180/**
Komal Seelam78ff65a2016-08-18 15:25:24 +05301181 * hdd_svc_fw_shutdown_ind() - API to send FW SHUTDOWN IND to Userspace
1182 *
1183 * @dev: Device Pointer
1184 *
1185 * Return: None
1186 */
1187void hdd_svc_fw_shutdown_ind(struct device *dev)
1188{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001189 struct hdd_context *hdd_ctx;
Komal Seelam78ff65a2016-08-18 15:25:24 +05301190 v_CONTEXT_t g_context;
1191
1192 g_context = cds_get_global_context();
1193
1194 if (!g_context)
1195 return;
1196
1197 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1198
1199 hdd_ctx ? wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
1200 WLAN_SVC_FW_SHUTDOWN_IND,
1201 NULL, 0) : 0;
1202}
1203
1204/**
Arun Khandavallicc544b32017-01-30 19:52:16 +05301205 * hdd_ssr_restart_sap() - restart sap on SSR
1206 * @hdd_ctx: hdd context
1207 *
1208 * Return: nothing
1209 */
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001210static void hdd_ssr_restart_sap(struct hdd_context *hdd_ctx)
Arun Khandavallicc544b32017-01-30 19:52:16 +05301211{
1212 QDF_STATUS status;
1213 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson75b737d2017-08-29 14:24:41 -07001214 struct hdd_adapter *adapter;
Arun Khandavallicc544b32017-01-30 19:52:16 +05301215
1216 ENTER();
1217
1218 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1219 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
1220 adapter = adapter_node->pAdapter;
1221 if (adapter && adapter->device_mode == QDF_SAP_MODE) {
Manikandan Mohan0a0ac952017-02-16 15:49:31 -08001222 if (test_bit(SOFTAP_INIT_DONE, &adapter->event_flags)) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001223 hdd_debug("Restart prev SAP session");
Manikandan Mohan0a0ac952017-02-16 15:49:31 -08001224 wlan_hdd_start_sap(adapter, true);
1225 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05301226 }
1227 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
1228 adapter_node = next;
1229 }
1230
1231 EXIT();
1232}
1233
1234/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235 * hdd_wlan_shutdown() - HDD SSR shutdown function
1236 *
1237 * This function is called by the HIF to shutdown the driver during SSR.
1238 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301239 * Return: QDF_STATUS_SUCCESS if the driver was shut down,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 * or an error status otherwise
1241 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301242QDF_STATUS hdd_wlan_shutdown(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244 v_CONTEXT_t p_cds_context = NULL;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001245 struct hdd_context *pHddCtx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001246 p_cds_sched_context cds_sched_context = NULL;
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07001247 QDF_STATUS qdf_status;
Manikandan Mohan8b4e2012017-03-22 11:15:55 -07001248 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001250 hdd_info("WLAN driver shutting down!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252 /* Get the global CDS context. */
1253 p_cds_context = cds_get_global_context();
1254 if (!p_cds_context) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001255 hdd_err("Global CDS context is Null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301256 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001257 }
1258
1259 /* Get the HDD context. */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301260 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261 if (!pHddCtx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001262 hdd_err("HDD context is Null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301263 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264 }
1265
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08001266 policy_mgr_clear_concurrent_session_count(pHddCtx->hdd_psoc);
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +05301267
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001268 hdd_debug("Invoking packetdump deregistration API");
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +05301269 wlan_deregister_txrx_packetdump();
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07001270 wlan_cfg80211_cleanup_scan_queue(pHddCtx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 hdd_reset_all_adapters(pHddCtx);
1272
Poddar, Siddarth1ab0a3d2016-09-29 18:58:45 +05301273 /* Flush cached rx frame queue */
Manikandan Mohan8b4e2012017-03-22 11:15:55 -07001274 if (soc)
1275 cdp_flush_cache_rx_queue(soc);
Poddar, Siddarth1ab0a3d2016-09-29 18:58:45 +05301276
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301277 /* De-register the HDD callbacks */
1278 hdd_deregister_cb(pHddCtx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001279
1280 cds_sched_context = get_cds_sched_ctxt();
1281
Rajeev Kumareada0d02016-12-08 17:44:17 -08001282 if (pHddCtx->is_scheduler_suspended) {
Rajeev Kumar0b732952016-12-08 17:51:39 -08001283 scheduler_resume();
Rajeev Kumareada0d02016-12-08 17:44:17 -08001284 pHddCtx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285 }
1286#ifdef QCA_CONFIG_SMP
1287 if (true == pHddCtx->is_ol_rx_thread_suspended) {
1288 complete(&cds_sched_context->ol_resume_rx_event);
1289 pHddCtx->is_ol_rx_thread_suspended = false;
1290 }
1291#endif
1292
Prashanth Bhatta2ac92bd2016-10-11 16:08:00 -07001293 qdf_status = cds_sched_close(p_cds_context);
1294 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
1295 hdd_err("Failed to close CDS Scheduler");
1296 QDF_ASSERT(false);
1297 }
1298
Manikandan Mohan71844ea2017-07-05 21:51:08 -07001299 hdd_ipa_uc_ssr_deinit();
Nitesh Shah61c10d92016-10-19 19:29:15 +05301300 qdf_mc_timer_stop(&pHddCtx->tdls_source_timer);
1301
Prashanth Bhattaab004382016-10-11 16:08:11 -07001302 hdd_bus_bandwidth_destroy(pHddCtx);
1303
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07001304 hdd_wlan_stop_modules(pHddCtx, false);
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05301305
Jeff Johnsonf7f66f02016-09-23 14:50:11 -07001306 hdd_lpass_notify_stop(pHddCtx);
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07001307
Yue Ma2be12872017-06-02 13:06:58 -07001308 wlan_objmgr_print_ref_all_objects_per_psoc(pHddCtx->hdd_psoc);
1309
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001310 hdd_info("WLAN driver shutdown complete");
Yue Ma2be12872017-06-02 13:06:58 -07001311
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301312 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313}
1314
Sen, Devendra154b3c42017-02-13 20:44:15 +05301315#ifdef FEATURE_WLAN_DIAG_SUPPORT
1316/**
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301317 * hdd_wlan_ssr_reinit_event()- send ssr reinit state
1318 *
1319 * This Function send send ssr reinit state diag event
1320 *
1321 * Return: void.
1322 */
Sen, Devendra154b3c42017-02-13 20:44:15 +05301323static void hdd_wlan_ssr_reinit_event(void)
1324{
1325 WLAN_HOST_DIAG_EVENT_DEF(ssr_reinit, struct host_event_wlan_ssr_reinit);
1326 qdf_mem_zero(&ssr_reinit, sizeof(ssr_reinit));
1327 ssr_reinit.status = SSR_SUB_SYSTEM_REINIT;
1328 WLAN_HOST_DIAG_EVENT_REPORT(&ssr_reinit,
1329 EVENT_WLAN_SSR_REINIT_SUBSYSTEM);
1330}
1331#else
1332static inline void hdd_wlan_ssr_reinit_event(void)
1333{
1334
1335}
1336#endif
1337
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001338/**
1339 * hdd_wlan_re_init() - HDD SSR re-init function
1340 *
1341 * This function is called by the HIF to re-initialize the driver after SSR.
1342 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301343 * Return: QDF_STATUS_SUCCESS if the driver was re-initialized,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 * or an error status otherwise
1345 */
Arun Khandavallifae92942016-08-01 13:31:08 +05301346QDF_STATUS hdd_wlan_re_init(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347{
Arun Khandavallifae92942016-08-01 13:31:08 +05301348
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349 v_CONTEXT_t p_cds_context = NULL;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001350 struct hdd_context *pHddCtx = NULL;
Jeff Johnson75b737d2017-08-29 14:24:41 -07001351 struct hdd_adapter *pAdapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05301352 int ret;
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301353 bool bug_on_reinit_failure = CFG_BUG_ON_REINIT_FAILURE_DEFAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354
1355 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
1356
1357 /* Get the CDS context */
1358 p_cds_context = cds_get_global_context();
1359 if (p_cds_context == NULL) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001360 hdd_err("Failed cds_get_global_context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 goto err_re_init;
1362 }
1363
1364 /* Get the HDD context */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301365 pHddCtx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 if (!pHddCtx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001367 hdd_err("HDD context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368 goto err_re_init;
1369 }
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301370 bug_on_reinit_failure = pHddCtx->config->bug_on_reinit_failure;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001371
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001372 /* The driver should always be initialized in STA mode after SSR */
1373 hdd_set_conparam(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 /* Try to get an adapter from mode ID */
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001375 pAdapter = hdd_get_adapter(pHddCtx, QDF_STA_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 if (!pAdapter) {
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001377 pAdapter = hdd_get_adapter(pHddCtx, QDF_SAP_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378 if (!pAdapter) {
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001379 pAdapter = hdd_get_adapter(pHddCtx, QDF_IBSS_MODE);
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301380 if (!pAdapter)
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001381 hdd_err("Failed to get Adapter!");
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301382
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 }
1384 }
1385
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05301386 if (pHddCtx->config->enable_dp_trace)
1387 qdf_dp_trace_init();
1388
Prashanth Bhattaab004382016-10-11 16:08:11 -07001389 hdd_bus_bandwidth_init(pHddCtx);
1390
Arun Khandavallicc544b32017-01-30 19:52:16 +05301391
Arun Khandavallifae92942016-08-01 13:31:08 +05301392 ret = hdd_wlan_start_modules(pHddCtx, pAdapter, true);
1393 if (ret) {
1394 hdd_err("Failed to start wlan after error");
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301395 goto err_re_init;
Arun Khandavallifae92942016-08-01 13:31:08 +05301396 }
1397
Arun Khandavallia96c2c02016-05-17 19:15:34 +05301398 hdd_wlan_get_version(pHddCtx, NULL, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399
Wu Gao36717432016-11-21 15:09:48 +08001400 wlan_hdd_send_svc_nlink_msg(pHddCtx->radio_index,
1401 WLAN_SVC_FW_CRASHED_IND, NULL, 0);
1402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 /* Restart all adapters */
1404 hdd_start_all_adapters(pHddCtx);
1405
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05301406 pHddCtx->last_scan_reject_session_id = 0xFF;
1407 pHddCtx->last_scan_reject_reason = 0;
1408 pHddCtx->last_scan_reject_timestamp = 0;
Abhishek Singh00130682017-07-14 10:46:17 +05301409 pHddCtx->scan_reject_cnt = 0;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05301410
Selvaraj, Sridhar1c487562017-04-19 14:29:07 +05301411 hdd_set_roaming_in_progress(false);
Abhishek Singh533c9da2017-05-04 10:23:34 +05301412 complete(&pAdapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 pHddCtx->btCoexModeSet = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415 /* Allow the phone to go to sleep */
1416 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05301417 /* set chip power save failure detected callback */
1418 sme_set_chip_pwr_save_fail_cb(pHddCtx->hHal,
1419 hdd_chip_pwr_save_fail_detected_cb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301421 ret = hdd_register_cb(pHddCtx);
1422 if (ret) {
1423 hdd_err("Failed to register HDD callbacks!");
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05301424 goto err_cds_disable;
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301425 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426
Jeff Johnson9afc5012016-09-23 13:56:27 -07001427 hdd_lpass_notify_start(pHddCtx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001429 hdd_info("WLAN host driver reinitiation completed!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430 goto success;
1431
1432err_cds_disable:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07001433 hdd_wlan_stop_modules(pHddCtx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435err_re_init:
1436 /* Allow the phone to go to sleep */
1437 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301438 if (bug_on_reinit_failure)
1439 QDF_BUG(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 return -EPERM;
1441
1442success:
Arun Khandavallicc544b32017-01-30 19:52:16 +05301443 if (pHddCtx->config->sap_internal_restart)
1444 hdd_ssr_restart_sap(pHddCtx);
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301445
Sen, Devendra154b3c42017-02-13 20:44:15 +05301446 hdd_wlan_ssr_reinit_event();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301447 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448}
1449
Jeff Johnson75b737d2017-08-29 14:24:41 -07001450int wlan_hdd_set_powersave(struct hdd_adapter *adapter,
Dustin Brownf660fb42016-09-09 12:04:00 -07001451 bool allow_power_save, uint32_t timeout)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001452{
1453 tHalHandle hal;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001454 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455
1456 if (NULL == adapter) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001457 hdd_err("Adapter NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 return -ENODEV;
1459 }
1460
1461 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1462 if (!hdd_ctx) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001463 hdd_err("hdd context is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464 return -EINVAL;
1465 }
1466
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001467 hdd_debug("Allow power save: %d", allow_power_save);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 hal = WLAN_HDD_GET_HAL_CTX(adapter);
1469
Dustin Brown84411b02017-07-21 16:44:44 -07001470 /*
1471 * This is a workaround for defective AP's that send a disassoc
1472 * immediately after WPS connection completes. Defer powersave by a
1473 * small amount if the affected AP is detected.
1474 */
1475 if (allow_power_save &&
1476 adapter->device_mode == QDF_STA_MODE &&
Krunal Soni364e0872017-05-10 21:24:34 -07001477 !adapter->sessionCtx.station.ap_supports_immediate_power_save) {
1478 /* override user's requested flag */
Krunal Soni364e0872017-05-10 21:24:34 -07001479 allow_power_save = false;
Dustin Brown84411b02017-07-21 16:44:44 -07001480 timeout = AUTO_PS_DEFER_TIMEOUT_MS;
1481 hdd_debug("Defer power-save due to AP spec non-conformance");
Krunal Soni364e0872017-05-10 21:24:34 -07001482 }
1483
Dustin Brownf660fb42016-09-09 12:04:00 -07001484 if (allow_power_save) {
1485 if (QDF_STA_MODE == adapter->device_mode ||
1486 QDF_P2P_CLIENT_MODE == adapter->device_mode) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001487 hdd_debug("Disabling Auto Power save timer");
Dustin Brownf660fb42016-09-09 12:04:00 -07001488 sme_ps_disable_auto_ps_timer(
1489 WLAN_HDD_GET_HAL_CTX(adapter),
1490 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 if (hdd_ctx->config && hdd_ctx->config->is_ps_enabled) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001494 hdd_debug("Wlan driver Entering Power save");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001495
1496 /*
1497 * Enter Power Save command received from GUI
1498 * this means DHCP is completed
1499 */
1500 sme_ps_enable_disable(hal, adapter->sessionId,
1501 SME_PS_ENABLE);
1502 } else {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001503 hdd_debug("Power Save is not enabled in the cfg");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001505 } else {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001506 hdd_debug("Wlan driver Entering Full Power");
Dustin Brownf660fb42016-09-09 12:04:00 -07001507
1508 /*
1509 * Enter Full power command received from GUI
1510 * this means we are disconnected
1511 */
1512 sme_ps_disable_auto_ps_timer(WLAN_HDD_GET_HAL_CTX(adapter),
1513 adapter->sessionId);
1514 sme_ps_enable_disable(hal, adapter->sessionId, SME_PS_DISABLE);
1515 sme_ps_enable_auto_ps_timer(WLAN_HDD_GET_HAL_CTX(adapter),
Dustin Brown84411b02017-07-21 16:44:44 -07001516 adapter->sessionId, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001518
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001519 return 0;
1520}
1521
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001522static void wlan_hdd_print_suspend_fail_stats(struct hdd_context *hdd_ctx)
Dustin Brown105d7902016-10-03 16:27:59 -07001523{
Dustin Brownd9322482017-01-09 12:46:03 -08001524 struct suspend_resume_stats *stats = &hdd_ctx->suspend_resume_stats;
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301525
Dustin Brown105d7902016-10-03 16:27:59 -07001526 hdd_err("ipa:%d, radar:%d, roam:%d, scan:%d, initial_wakeup:%d",
Dustin Brownd9322482017-01-09 12:46:03 -08001527 stats->suspend_fail[SUSPEND_FAIL_IPA],
1528 stats->suspend_fail[SUSPEND_FAIL_RADAR],
1529 stats->suspend_fail[SUSPEND_FAIL_ROAM],
1530 stats->suspend_fail[SUSPEND_FAIL_SCAN],
1531 stats->suspend_fail[SUSPEND_FAIL_INITIAL_WAKEUP]);
Dustin Brown105d7902016-10-03 16:27:59 -07001532}
1533
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001534void wlan_hdd_inc_suspend_stats(struct hdd_context *hdd_ctx,
Dustin Brown105d7902016-10-03 16:27:59 -07001535 enum suspend_fail_reason reason)
1536{
1537 wlan_hdd_print_suspend_fail_stats(hdd_ctx);
Dustin Brownd9322482017-01-09 12:46:03 -08001538 hdd_ctx->suspend_resume_stats.suspend_fail[reason]++;
Dustin Brown105d7902016-10-03 16:27:59 -07001539 wlan_hdd_print_suspend_fail_stats(hdd_ctx);
1540}
1541
Dustin Brown5fbb1052017-08-11 17:25:51 -07001542#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
1543static inline void
1544hdd_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
1545{
1546 cfg80211_sched_scan_results(wiphy);
1547}
1548#else
1549static inline void
1550hdd_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
1551{
1552 cfg80211_sched_scan_results(wiphy, reqid);
1553}
1554#endif
1555
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556/**
1557 * __wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback
1558 * @wiphy: Pointer to wiphy
1559 *
1560 * This API is called when cfg80211 driver resumes driver updates
1561 * latest sched_scan scan result(if any) to cfg80211 database
1562 *
1563 * Return: integer status
1564 */
1565static int __wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
1566{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001567 struct hdd_context *pHddCtx = wiphy_priv(wiphy);
Jeff Johnson75b737d2017-08-29 14:24:41 -07001568 struct hdd_adapter *pAdapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 hdd_adapter_list_node_t *pAdapterNode, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301570 QDF_STATUS status = QDF_STATUS_SUCCESS;
Dustin Brownd9322482017-01-09 12:46:03 -08001571 int exit_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001572 p_cds_sched_context cds_sched_context = get_cds_sched_ctxt();
1573
1574 ENTER();
1575
Dustin Brownd9322482017-01-09 12:46:03 -08001576 if (cds_is_driver_recovering()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001577 hdd_debug("Driver is recovering; Skipping resume");
Dustin Brownd9322482017-01-09 12:46:03 -08001578 exit_code = 0;
1579 goto exit_with_code;
1580 }
Prashanth Bhatta697dd0c2016-10-20 18:42:41 -07001581
Anurag Chouhan6d760662016-02-20 16:05:43 +05301582 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001583 hdd_err("Command not allowed in FTM mode");
Dustin Brownd9322482017-01-09 12:46:03 -08001584 exit_code = -EINVAL;
1585 goto exit_with_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001586 }
1587
Dustin Brownd9322482017-01-09 12:46:03 -08001588 exit_code = wlan_hdd_validate_context(pHddCtx);
1589 if (exit_code) {
1590 hdd_err("Invalid HDD context");
1591 goto exit_with_code;
1592 }
Arun Khandavallifae92942016-08-01 13:31:08 +05301593
1594 mutex_lock(&pHddCtx->iface_change_lock);
1595 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
1596 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001597 hdd_debug("Driver is not enabled; Skipping resume");
Dustin Brownd9322482017-01-09 12:46:03 -08001598 exit_code = 0;
1599 goto exit_with_code;
Arun Khandavallifae92942016-08-01 13:31:08 +05301600 }
1601 mutex_unlock(&pHddCtx->iface_change_lock);
Dustin Brownd9322482017-01-09 12:46:03 -08001602
Yuanyuan Liu13738502016-04-06 17:41:37 -07001603 pld_request_bus_bandwidth(pHddCtx->parent_dev, PLD_BUS_WIDTH_MEDIUM);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301605 status = hdd_resume_wlan();
1606 if (status != QDF_STATUS_SUCCESS) {
1607 exit_code = 0;
1608 goto exit_with_code;
1609 }
Rajeev Kumareada0d02016-12-08 17:44:17 -08001610 /* Resume control path scheduler */
1611 if (pHddCtx->is_scheduler_suspended) {
Rajeev Kumar0b732952016-12-08 17:51:39 -08001612 scheduler_resume();
Rajeev Kumareada0d02016-12-08 17:44:17 -08001613 pHddCtx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 }
1615#ifdef QCA_CONFIG_SMP
1616 /* Resume tlshim Rx thread */
1617 if (pHddCtx->is_ol_rx_thread_suspended) {
1618 complete(&cds_sched_context->ol_resume_rx_event);
1619 pHddCtx->is_ol_rx_thread_suspended = false;
1620 }
1621#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301623 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05301624 TRACE_CODE_HDD_CFG80211_RESUME_WLAN,
1625 NO_SESSION, pHddCtx->isWiphySuspended));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301626 qdf_spin_lock(&pHddCtx->sched_scan_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001627 pHddCtx->isWiphySuspended = false;
1628 if (true != pHddCtx->isSchedScanUpdatePending) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301629 qdf_spin_unlock(&pHddCtx->sched_scan_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001630 hdd_debug("Return resume is not due to PNO indication");
Dustin Brownd9322482017-01-09 12:46:03 -08001631 goto exit_with_success;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 }
1633 /* Reset flag to avoid updatating cfg80211 data old results again */
1634 pHddCtx->isSchedScanUpdatePending = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301635 qdf_spin_unlock(&pHddCtx->sched_scan_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636
1637 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301638 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 pAdapter = pAdapterNode->pAdapter;
1640 if ((NULL != pAdapter) &&
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001641 (QDF_STA_MODE == pAdapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 if (0 !=
1643 wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy,
1644 pAdapter, 0)) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001645 hdd_warn("NO SCAN result");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646 } else {
1647 /* Acquire wakelock to handle the case where
1648 * APP's tries to suspend immediately after
1649 * updating the scan results. Whis results in
1650 * app's is in suspended state and not able to
1651 * process the connect request to AP
1652 */
Sreelakshmi Konamki22528532016-09-06 16:34:50 +05301653 hdd_prevent_suspend_timeout(
Dustin Brownceed67e2017-05-26 11:57:31 -07001654 HDD_WAKELOCK_TIMEOUT_RESUME,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001655 WIFI_POWER_EVENT_WAKELOCK_RESUME_WLAN);
Dustin Brown5fbb1052017-08-11 17:25:51 -07001656 hdd_sched_scan_results(pHddCtx->wiphy, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 }
1658
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001659 hdd_debug("cfg80211 scan result database updated");
Dustin Brownd9322482017-01-09 12:46:03 -08001660 goto exit_with_success;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001661 }
1662 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1663 pAdapterNode = pNext;
1664 }
1665
Dustin Brownd9322482017-01-09 12:46:03 -08001666exit_with_success:
1667 pHddCtx->suspend_resume_stats.resumes++;
1668 exit_code = 0;
1669
1670exit_with_code:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301671 EXIT();
Dustin Brownd9322482017-01-09 12:46:03 -08001672 return exit_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673}
1674
1675/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 * wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback
1677 * @wiphy: Pointer to wiphy
1678 *
1679 * This API is called when cfg80211 driver resumes driver updates
1680 * latest sched_scan scan result(if any) to cfg80211 database
1681 *
1682 * Return: integer status
1683 */
1684int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
1685{
1686 int ret;
1687
1688 cds_ssr_protect(__func__);
1689 ret = __wlan_hdd_cfg80211_resume_wlan(wiphy);
1690 cds_ssr_unprotect(__func__);
1691
1692 return ret;
1693}
1694
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001695static void hdd_suspend_cb(void)
1696{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001697 struct hdd_context *hdd_ctx;
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001698
1699 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1700 if (!hdd_ctx) {
1701 cds_err("HDD context is NULL");
1702 return;
1703 }
1704
1705 complete(&hdd_ctx->mc_sus_event_var);
1706}
1707
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708/**
1709 * __wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback
1710 * @wiphy: Pointer to wiphy
1711 * @wow: Pointer to wow
1712 *
1713 * This API is called when cfg80211 driver suspends
1714 *
1715 * Return: integer status
1716 */
1717static int __wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
1718 struct cfg80211_wowlan *wow)
1719{
1720#ifdef QCA_CONFIG_SMP
1721#define RX_TLSHIM_SUSPEND_TIMEOUT 200 /* msecs */
1722#endif
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001723 struct hdd_context *pHddCtx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724 p_cds_sched_context cds_sched_context = get_cds_sched_ctxt();
1725 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnson75b737d2017-08-29 14:24:41 -07001726 struct hdd_adapter *pAdapter;
Jeff Johnson37588942017-08-15 16:11:41 -07001727 struct hdd_scan_info *pScanInfo;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301728 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 int rc;
1730
1731 ENTER();
1732
Anurag Chouhan6d760662016-02-20 16:05:43 +05301733 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001734 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001735 return -EINVAL;
1736 }
1737
1738 rc = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301739 if (0 != rc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741
Arun Khandavallifae92942016-08-01 13:31:08 +05301742 mutex_lock(&pHddCtx->iface_change_lock);
1743 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
1744 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001745 hdd_debug("Driver Modules not Enabled ");
Arun Khandavallifae92942016-08-01 13:31:08 +05301746 return 0;
1747 }
1748 mutex_unlock(&pHddCtx->iface_change_lock);
1749
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750 /* If RADAR detection is in progress (HDD), prevent suspend. The flag
1751 * "dfs_cac_block_tx" is set to true when RADAR is found and stay true
1752 * until CAC is done for a SoftAP which is in started state.
1753 */
1754 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301755 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001756 pAdapter = pAdapterNode->pAdapter;
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301757
1758 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
1759 hdd_err("invalid session id: %d", pAdapter->sessionId);
1760 goto next_adapter;
1761 }
1762
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001763 if (QDF_SAP_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001764 if (BSS_START ==
1765 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter)->bssState &&
1766 true ==
1767 WLAN_HDD_GET_AP_CTX_PTR(pAdapter)->
1768 dfs_cac_block_tx) {
Dustin Brown2d228232016-09-22 15:06:19 -07001769 hdd_err("RADAR detection in progress, do not allow suspend");
Dustin Brown105d7902016-10-03 16:27:59 -07001770 wlan_hdd_inc_suspend_stats(pHddCtx,
1771 SUSPEND_FAIL_RADAR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001772 return -EAGAIN;
1773 } else if (!pHddCtx->config->enableSapSuspend) {
1774 /* return -EOPNOTSUPP if SAP does not support
1775 * suspend
1776 */
Jeff Johnsonc3273322016-07-06 15:28:17 -07001777 hdd_err("SAP does not support suspend!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001778 return -EOPNOTSUPP;
1779 }
Krunal Sonifb84cbd2016-03-10 13:09:07 -08001780 } else if (QDF_P2P_GO_MODE == pAdapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001781 if (!pHddCtx->config->enableSapSuspend) {
1782 /* return -EOPNOTSUPP if GO does not support
1783 * suspend
1784 */
Jeff Johnsonc3273322016-07-06 15:28:17 -07001785 hdd_err("GO does not support suspend!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786 return -EOPNOTSUPP;
1787 }
1788 }
Masti, Narayanraddi3e26de62016-08-19 14:33:22 +05301789 if (pAdapter->is_roc_inprogress)
1790 wlan_hdd_cleanup_remain_on_channel_ctx(pAdapter);
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301791next_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001792 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1793 pAdapterNode = pNext;
1794 }
1795
1796 /* Stop ongoing scan on each interface */
1797 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301798 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001799 pAdapter = pAdapterNode->pAdapter;
1800 pScanInfo = &pAdapter->scan_info;
1801
Sandeep Puligillaf8527122016-11-16 18:35:16 -08001802 if (sme_neighbor_middle_of_roaming
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803 (pHddCtx->hHal, pAdapter->sessionId)) {
Dustin Brown2d228232016-09-22 15:06:19 -07001804 hdd_err("Roaming in progress, do not allow suspend");
Dustin Brown105d7902016-10-03 16:27:59 -07001805 wlan_hdd_inc_suspend_stats(pHddCtx,
1806 SUSPEND_FAIL_ROAM);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001807 return -EAGAIN;
1808 }
1809
Dustin Brownc86d5362017-07-07 13:08:51 -07001810 wlan_abort_scan(pHddCtx->hdd_pdev, INVAL_PDEV_ID,
1811 pAdapter->sessionId, INVALID_SCAN_ID, false);
1812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001813 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
1814 pAdapterNode = pNext;
1815 }
1816
Dustin Brown84411b02017-07-21 16:44:44 -07001817 /* flush any pending powersave timers */
1818 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
1819 while (pAdapterNode && QDF_IS_STATUS_SUCCESS(status)) {
1820 pAdapter = pAdapterNode->pAdapter;
1821
1822 sme_ps_timer_flush_sync(pHddCtx->hHal, pAdapter->sessionId);
1823
1824 status = hdd_get_next_adapter(pHddCtx, pAdapterNode,
1825 &pAdapterNode);
1826 }
1827
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001828 /*
1829 * Suspend IPA early before proceeding to suspend other entities like
1830 * firmware to avoid any race conditions.
1831 */
1832 if (hdd_ipa_suspend(pHddCtx)) {
Dustin Brown2d228232016-09-22 15:06:19 -07001833 hdd_err("IPA not ready to suspend!");
Dustin Brown105d7902016-10-03 16:27:59 -07001834 wlan_hdd_inc_suspend_stats(pHddCtx, SUSPEND_FAIL_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835 return -EAGAIN;
1836 }
1837
Rajeev Kumareada0d02016-12-08 17:44:17 -08001838 /* Suspend control path scheduler */
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001839 scheduler_register_hdd_suspend_callback(hdd_suspend_cb);
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301840 scheduler_set_event_mask(MC_SUSPEND_EVENT);
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001841 scheduler_wake_up_controller_thread();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842
Rajeev Kumareada0d02016-12-08 17:44:17 -08001843 /* Wait for suspend confirmation from scheduler */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001844 rc = wait_for_completion_timeout(&pHddCtx->mc_sus_event_var,
1845 msecs_to_jiffies(WLAN_WAIT_TIME_MCTHREAD_SUSPEND));
1846 if (!rc) {
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301847 scheduler_clear_event_mask(MC_SUSPEND_EVENT);
Jeff Johnsonc3273322016-07-06 15:28:17 -07001848 hdd_err("Failed to stop mc thread");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001849 goto resume_tx;
1850 }
Rajeev Kumareada0d02016-12-08 17:44:17 -08001851 pHddCtx->is_scheduler_suspended = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852
1853#ifdef QCA_CONFIG_SMP
1854 /* Suspend tlshim rx thread */
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301855 set_bit(RX_SUSPEND_EVENT, &cds_sched_context->ol_rx_event_flag);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856 wake_up_interruptible(&cds_sched_context->ol_rx_wait_queue);
1857 rc = wait_for_completion_timeout(&cds_sched_context->
1858 ol_suspend_rx_event,
1859 msecs_to_jiffies
1860 (RX_TLSHIM_SUSPEND_TIMEOUT));
1861 if (!rc) {
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301862 clear_bit(RX_SUSPEND_EVENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 &cds_sched_context->ol_rx_event_flag);
Jeff Johnsonc3273322016-07-06 15:28:17 -07001864 hdd_err("Failed to stop tl_shim rx thread");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001865 goto resume_all;
1866 }
1867 pHddCtx->is_ol_rx_thread_suspended = true;
1868#endif
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301869 if (hdd_suspend_wlan() < 0)
1870 goto resume_all;
1871
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301872 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05301873 TRACE_CODE_HDD_CFG80211_SUSPEND_WLAN,
1874 NO_SESSION, pHddCtx->isWiphySuspended));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875 pHddCtx->isWiphySuspended = true;
1876
Yuanyuan Liu13738502016-04-06 17:41:37 -07001877 pld_request_bus_bandwidth(pHddCtx->parent_dev, PLD_BUS_WIDTH_NONE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878
1879 EXIT();
1880 return 0;
1881
1882#ifdef QCA_CONFIG_SMP
1883resume_all:
1884
Rajeev Kumar0b732952016-12-08 17:51:39 -08001885 scheduler_resume();
Rajeev Kumareada0d02016-12-08 17:44:17 -08001886 pHddCtx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887#endif
1888
1889resume_tx:
1890
1891 hdd_resume_wlan();
1892 return -ETIME;
1893
1894}
1895
1896/**
1897 * wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback
1898 * @wiphy: Pointer to wiphy
1899 * @wow: Pointer to wow
1900 *
1901 * This API is called when cfg80211 driver suspends
1902 *
1903 * Return: integer status
1904 */
1905int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
1906 struct cfg80211_wowlan *wow)
1907{
1908 int ret;
1909
1910 cds_ssr_protect(__func__);
1911 ret = __wlan_hdd_cfg80211_suspend_wlan(wiphy, wow);
1912 cds_ssr_unprotect(__func__);
1913
1914 return ret;
1915}
1916
1917/**
Komal Seelama89be8d2016-09-29 11:09:26 +05301918 * hdd_stop_dhcp_ind() - API to stop DHCP sequence
1919 * @adapter: Adapter on which DHCP needs to be stopped
1920 *
1921 * Release the wakelock held for DHCP process and allow
1922 * the runtime pm to continue
1923 *
1924 * Return: None
1925 */
Jeff Johnson75b737d2017-08-29 14:24:41 -07001926static void hdd_stop_dhcp_ind(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05301927{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001928 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05301929
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08001930 hdd_debug("DHCP stop indicated through power save");
Komal Seelama89be8d2016-09-29 11:09:26 +05301931 sme_dhcp_stop_ind(hdd_ctx->hHal, adapter->device_mode,
1932 adapter->macAddressCurrent.bytes,
1933 adapter->sessionId);
1934 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DHCP);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08001935 qdf_runtime_pm_allow_suspend(&adapter->connect_rpm_ctx.connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05301936}
1937
1938/**
1939 * hdd_start_dhcp_ind() - API to start DHCP sequence
1940 * @adapter: Adapter on which DHCP needs to be stopped
1941 *
1942 * Prevent APPS suspend and the runtime suspend during
1943 * DHCP sequence
1944 *
1945 * Return: None
1946 */
Jeff Johnson75b737d2017-08-29 14:24:41 -07001947static void hdd_start_dhcp_ind(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05301948{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001949 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05301950
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001951 hdd_debug("DHCP start indicated through power save");
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08001952 qdf_runtime_pm_prevent_suspend(&adapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07001953 hdd_prevent_suspend_timeout(HDD_WAKELOCK_TIMEOUT_CONNECT,
1954 WIFI_POWER_EVENT_WAKELOCK_DHCP);
Komal Seelama89be8d2016-09-29 11:09:26 +05301955 sme_dhcp_start_ind(hdd_ctx->hHal, adapter->device_mode,
1956 adapter->macAddressCurrent.bytes,
1957 adapter->sessionId);
1958}
1959
1960/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961 * __wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config
1962 * @wiphy: Pointer to wiphy
1963 * @dev: Pointer to network device
Dustin Brownf660fb42016-09-09 12:04:00 -07001964 * @allow_power_save: is wlan allowed to go into power save mode
1965 * @timeout: Timeout value in ms
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001966 *
1967 * Return: 0 for success, non-zero for failure
1968 */
1969static int __wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Dustin Brownf660fb42016-09-09 12:04:00 -07001970 struct net_device *dev,
1971 bool allow_power_save,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001972 int timeout)
1973{
Jeff Johnson75b737d2017-08-29 14:24:41 -07001974 struct hdd_adapter *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001975 struct hdd_context *pHddCtx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001976 int status;
1977
Dustin Brownecfce632016-09-13 10:41:45 -07001978 ENTER();
1979
Dustin Brownf660fb42016-09-09 12:04:00 -07001980 if (timeout < 0) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001981 hdd_debug("User space timeout: %d; Using default instead: %d",
Dustin Brownf660fb42016-09-09 12:04:00 -07001982 timeout, AUTO_PS_ENTRY_USER_TIMER_DEFAULT_VALUE);
1983 timeout = AUTO_PS_ENTRY_USER_TIMER_DEFAULT_VALUE;
1984 }
1985
Anurag Chouhan6d760662016-02-20 16:05:43 +05301986 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001987 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001988 return -EINVAL;
1989 }
1990
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301991 if (wlan_hdd_validate_session_id(pAdapter->sessionId)) {
1992 hdd_err("invalid session id: %d", pAdapter->sessionId);
1993 return -EINVAL;
1994 }
1995
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301996 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997 TRACE_CODE_HDD_CFG80211_SET_POWER_MGMT,
1998 pAdapter->sessionId, timeout));
1999
2000 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2001 status = wlan_hdd_validate_context(pHddCtx);
2002
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302003 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002004 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005
Arun Khandavalli99286452016-08-22 12:13:41 +05302006 mutex_lock(&pHddCtx->iface_change_lock);
2007 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
2008 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002009 hdd_debug("Driver Module not enabled return success");
Arun Khandavalli99286452016-08-22 12:13:41 +05302010 return 0;
2011 }
2012 mutex_unlock(&pHddCtx->iface_change_lock);
2013
Dustin Brownf660fb42016-09-09 12:04:00 -07002014 status = wlan_hdd_set_powersave(pAdapter, allow_power_save, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015
Komal Seelama89be8d2016-09-29 11:09:26 +05302016 allow_power_save ? hdd_stop_dhcp_ind(pAdapter) :
2017 hdd_start_dhcp_ind(pAdapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018
2019 EXIT();
2020 return status;
2021}
2022
2023/**
2024 * wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config
2025 * @wiphy: Pointer to wiphy
2026 * @dev: Pointer to network device
Dustin Brownf660fb42016-09-09 12:04:00 -07002027 * @allow_power_save: is wlan allowed to go into power save mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 * @timeout: Timeout value
2029 *
2030 * Return: 0 for success, non-zero for failure
2031 */
2032int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Dustin Brownf660fb42016-09-09 12:04:00 -07002033 struct net_device *dev,
2034 bool allow_power_save,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002035 int timeout)
2036{
2037 int ret;
2038
2039 cds_ssr_protect(__func__);
Dustin Brownf660fb42016-09-09 12:04:00 -07002040 ret = __wlan_hdd_cfg80211_set_power_mgmt(wiphy, dev,
2041 allow_power_save, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042 cds_ssr_unprotect(__func__);
2043
2044 return ret;
2045}
2046
2047/**
2048 * __wlan_hdd_cfg80211_set_txpower() - set TX power
2049 * @wiphy: Pointer to wiphy
2050 * @wdev: Pointer to network device
2051 * @type: TX power setting type
2052 * @dbm: TX power in dbm
2053 *
2054 * Return: 0 for success, non-zero for failure
2055 */
2056static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002057 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058 enum nl80211_tx_power_setting type,
2059 int dbm)
2060{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07002061 struct hdd_context *pHddCtx = (struct hdd_context *) wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062 tHalHandle hHal = NULL;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302063 struct qdf_mac_addr bssid = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
2064 struct qdf_mac_addr selfMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 int status;
2066
2067 ENTER();
2068
Anurag Chouhan6d760662016-02-20 16:05:43 +05302069 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002070 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002071 return -EINVAL;
2072 }
2073
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302074 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002075 TRACE_CODE_HDD_CFG80211_SET_TXPOWER,
2076 NO_SESSION, type));
2077
2078 status = wlan_hdd_validate_context(pHddCtx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302079 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002080 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002081
2082 hHal = pHddCtx->hHal;
2083
2084 if (0 != sme_cfg_set_int(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL, dbm)) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002085 hdd_err("sme_cfg_set_int failed for tx power %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002086 dbm);
2087 return -EIO;
2088 }
2089
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002090 hdd_debug("Set tx power level %d dbm", dbm);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002091
2092 switch (type) {
2093 /* Automatically determine transmit power */
2094 case NL80211_TX_POWER_AUTOMATIC:
2095 /* Fall through */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05302096 case NL80211_TX_POWER_LIMITED:
2097 /* Limit TX power by the mBm parameter */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002098 if (sme_set_max_tx_power(hHal, bssid, selfMac, dbm) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302099 QDF_STATUS_SUCCESS) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002100 hdd_err("Setting maximum tx power failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002101 return -EIO;
2102 }
2103 break;
2104
2105 case NL80211_TX_POWER_FIXED: /* Fix TX power to the mBm parameter */
Jeff Johnsonc3273322016-07-06 15:28:17 -07002106 hdd_err("NL80211_TX_POWER_FIXED not supported");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002107 return -EOPNOTSUPP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002108
2109 default:
Jeff Johnsonc3273322016-07-06 15:28:17 -07002110 hdd_err("Invalid power setting type %d", type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002111 return -EIO;
2112 }
2113
2114 EXIT();
2115 return 0;
2116}
2117
2118/**
2119 * wlan_hdd_cfg80211_set_txpower() - set TX power
2120 * @wiphy: Pointer to wiphy
2121 * @wdev: Pointer to network device
2122 * @type: TX power setting type
2123 * @dbm: TX power in dbm
2124 *
2125 * Return: 0 for success, non-zero for failure
2126 */
2127int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002128 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002129 enum nl80211_tx_power_setting type,
2130 int dbm)
2131{
2132 int ret;
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05302133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134 cds_ssr_protect(__func__);
2135 ret = __wlan_hdd_cfg80211_set_txpower(wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002136 wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002137 type, dbm);
2138 cds_ssr_unprotect(__func__);
2139
2140 return ret;
2141}
2142
2143/**
2144 * __wlan_hdd_cfg80211_get_txpower() - get TX power
2145 * @wiphy: Pointer to wiphy
2146 * @wdev: Pointer to network device
2147 * @dbm: Pointer to TX power in dbm
2148 *
2149 * Return: 0 for success, non-zero for failure
2150 */
2151static int __wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152 struct wireless_dev *wdev,
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002153 int *dbm)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002154{
2155
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07002156 struct hdd_context *pHddCtx = (struct hdd_context *) wiphy_priv(wiphy);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002157 struct net_device *ndev = wdev->netdev;
Jeff Johnson75b737d2017-08-29 14:24:41 -07002158 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002159 int status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002160 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002161
2162 ENTER();
2163
Anurag Chouhan6d760662016-02-20 16:05:43 +05302164 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002165 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002166 return -EINVAL;
2167 }
2168
2169 status = wlan_hdd_validate_context(pHddCtx);
2170 if (0 != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002171 *dbm = 0;
2172 return status;
2173 }
2174
Arun Khandavalli99286452016-08-22 12:13:41 +05302175 /* Validate adapter sessionId */
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05302176 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2177 hdd_err("invalid session id: %d", adapter->sessionId);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002178 return -EINVAL;
Arun Khandavalli99286452016-08-22 12:13:41 +05302179 }
2180
2181 mutex_lock(&pHddCtx->iface_change_lock);
2182 if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) {
2183 mutex_unlock(&pHddCtx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002184 hdd_debug("Driver Module not enabled return success");
Arun Khandavalli99286452016-08-22 12:13:41 +05302185 /* Send cached data to upperlayer*/
2186 *dbm = adapter->hdd_stats.ClassA_stat.max_pwr;
2187 return 0;
2188 }
2189 mutex_unlock(&pHddCtx->iface_change_lock);
2190
Ganesh Kondabattinif847f062017-05-26 12:36:24 +05302191 if (sta_ctx->conn_info.connState != eConnectionState_Associated) {
2192 hdd_debug("Not associated");
2193 /*To keep GUI happy */
2194 *dbm = 0;
2195 return 0;
2196 }
2197
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302198 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05302199 TRACE_CODE_HDD_CFG80211_GET_TXPOWER,
Arun Khandavalli99286452016-08-22 12:13:41 +05302200 adapter->sessionId, adapter->device_mode));
2201 wlan_hdd_get_class_astats(adapter);
2202 *dbm = adapter->hdd_stats.ClassA_stat.max_pwr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002203
2204 EXIT();
2205 return 0;
2206}
2207
2208/**
2209 * wlan_hdd_cfg80211_get_txpower() - cfg80211 get power handler function
2210 * @wiphy: Pointer to wiphy structure.
2211 * @wdev: Pointer to wireless_dev structure.
2212 * @dbm: dbm
2213 *
2214 * This is the cfg80211 get txpower handler function which invokes
2215 * the internal function @__wlan_hdd_cfg80211_get_txpower with
2216 * SSR protection.
2217 *
2218 * Return: 0 for success, error number on failure.
2219 */
2220int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002221 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002222 int *dbm)
2223{
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002224 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002225
2226 cds_ssr_protect(__func__);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002227 ret = __wlan_hdd_cfg80211_get_txpower(wiphy, wdev, dbm);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002228 cds_ssr_unprotect(__func__);
2229
2230 return ret;
2231}
Kapil Gupta6213c012016-09-02 19:39:09 +05302232
2233/**
2234 * hdd_set_qpower_config() - set qpower config to firmware
2235 * @adapter: HDD adapter
2236 * @qpower: new qpower config value
2237 *
2238 * Return: 0 on success; Errno on failure
2239 */
Jeff Johnson75b737d2017-08-29 14:24:41 -07002240int hdd_set_qpower_config(struct hdd_context *hddctx, struct hdd_adapter *adapter,
Dustin Brown10a7b712016-10-07 10:31:16 -07002241 u8 qpower)
Kapil Gupta6213c012016-09-02 19:39:09 +05302242{
Dustin Brown10a7b712016-10-07 10:31:16 -07002243 QDF_STATUS status;
Kapil Gupta6213c012016-09-02 19:39:09 +05302244
2245 if (!hddctx->config->enablePowersaveOffload) {
2246 hdd_err("qpower is disabled in configuration");
2247 return -EINVAL;
2248 }
Manjeet Singh91b7bb82017-02-10 18:35:40 +05302249 if (adapter->device_mode != QDF_STA_MODE &&
2250 adapter->device_mode != QDF_P2P_CLIENT_MODE) {
2251 hdd_info(FL("QPOWER only allowed in STA/P2P-Client modes:%d "),
2252 adapter->device_mode);
2253 return -EINVAL;
2254 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002255
Kapil Gupta6213c012016-09-02 19:39:09 +05302256 if (qpower > PS_DUTY_CYCLING_QPOWER ||
2257 qpower < PS_LEGACY_NODEEPSLEEP) {
Dustin Brown10a7b712016-10-07 10:31:16 -07002258 hdd_err("invalid qpower value: %d", qpower);
Kapil Gupta6213c012016-09-02 19:39:09 +05302259 return -EINVAL;
2260 }
Kapil Gupta6213c012016-09-02 19:39:09 +05302261
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08002262 if (hddctx->config->nMaxPsPoll) {
2263 if ((qpower == PS_QPOWER_NODEEPSLEEP) ||
2264 (qpower == PS_LEGACY_NODEEPSLEEP))
2265 qpower = PS_LEGACY_NODEEPSLEEP;
2266 else
2267 qpower = PS_LEGACY_DEEPSLEEP;
2268 hdd_info("Qpower disabled, %d", qpower);
2269 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002270 status = wma_set_qpower_config(adapter->sessionId, qpower);
2271 if (status != QDF_STATUS_SUCCESS) {
2272 hdd_err("failed to configure qpower: %d", status);
2273 return -EINVAL;
Kapil Gupta6213c012016-09-02 19:39:09 +05302274 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002275
Kapil Gupta6213c012016-09-02 19:39:09 +05302276 return 0;
2277}
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002278
Dustin Brown54096432017-02-23 13:00:44 -08002279
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002280#ifdef WLAN_SUSPEND_RESUME_TEST
Dustin Brownbc81a472016-10-26 16:56:59 -07002281static struct net_device *g_dev;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002282static struct wiphy *g_wiphy;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002283static enum wow_resume_trigger g_resume_trigger;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002284
2285#define HDD_FA_SUSPENDED_BIT (0)
2286static unsigned long fake_apps_state;
2287
Dustin Brownd53d1a82016-10-03 12:57:33 -07002288/**
2289 * __hdd_wlan_fake_apps_resume() - The core logic for
2290 * hdd_wlan_fake_apps_resume() skipping the call to hif_fake_apps_resume(),
2291 * which is only need for non-irq resume
Dustin Brownbc81a472016-10-26 16:56:59 -07002292 * @wiphy: the kernel wiphy struct for the device being resumed
2293 * @dev: the kernel net_device struct for the device being resumed
Dustin Brownd53d1a82016-10-03 12:57:33 -07002294 *
Dustin Brownbc81a472016-10-26 16:56:59 -07002295 * Return: none, calls QDF_BUG() on failure
Dustin Brownd53d1a82016-10-03 12:57:33 -07002296 */
Dustin Brownbc81a472016-10-26 16:56:59 -07002297static void __hdd_wlan_fake_apps_resume(struct wiphy *wiphy,
2298 struct net_device *dev)
Dustin Brownd53d1a82016-10-03 12:57:33 -07002299{
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002300 struct hif_opaque_softc *hif_ctx;
Dustin Brownddb59702017-01-12 16:20:31 -08002301 qdf_device_t qdf_dev;
Dustin Brownd53d1a82016-10-03 12:57:33 -07002302
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002303 hdd_info("Unit-test resume WLAN");
Dustin Brownddb59702017-01-12 16:20:31 -08002304
2305 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2306 if (!qdf_dev) {
2307 hdd_err("Failed to get QDF device context");
2308 QDF_BUG(0);
2309 return;
2310 }
2311
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002312 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2313 if (!hif_ctx) {
2314 hdd_err("Failed to get HIF context");
2315 return;
2316 }
2317
Dustin Brownd53d1a82016-10-03 12:57:33 -07002318 if (!test_and_clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) {
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002319 hdd_alert("Not unit-test suspended; Nothing to do");
Dustin Brownd53d1a82016-10-03 12:57:33 -07002320 return;
2321 }
2322
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002323 /* simulate kernel disable irqs */
2324 QDF_BUG(!hif_apps_wake_irq_disable(hif_ctx));
Dustin Brownd53d1a82016-10-03 12:57:33 -07002325
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002326 QDF_BUG(!wlan_hdd_bus_resume_noirq());
Dustin Brownd53d1a82016-10-03 12:57:33 -07002327
2328 /* simulate kernel enable irqs */
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002329 QDF_BUG(!hif_apps_irqs_enable(hif_ctx));
Dustin Brownd53d1a82016-10-03 12:57:33 -07002330
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002331 QDF_BUG(!wlan_hdd_bus_resume());
Dustin Brownd53d1a82016-10-03 12:57:33 -07002332
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002333 QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy));
2334
2335 if (g_resume_trigger == WOW_RESUME_TRIGGER_HTC_WAKEUP)
2336 hif_vote_link_down(hif_ctx);
Dustin Brownbc81a472016-10-26 16:56:59 -07002337
2338 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Dustin Brown562b9672016-12-22 15:25:33 -08002339
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002340 hdd_alert("Unit-test resume succeeded");
Dustin Brownd53d1a82016-10-03 12:57:33 -07002341}
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002342
2343/**
2344 * hdd_wlan_fake_apps_resume_irq_callback() - Irq callback function for resuming
2345 * from unit-test initiated suspend from irq wakeup signal
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002346 *
2347 * Resume wlan after getting very 1st CE interrupt from target
2348 *
2349 * Return: none
2350 */
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002351static void hdd_wlan_fake_apps_resume_irq_callback(void)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002352{
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002353 hdd_info("Trigger unit-test resume WLAN");
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002354
2355 QDF_BUG(g_wiphy);
Dustin Brownbc81a472016-10-26 16:56:59 -07002356 QDF_BUG(g_dev);
2357 __hdd_wlan_fake_apps_resume(g_wiphy, g_dev);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002358 g_wiphy = NULL;
Dustin Brownbc81a472016-10-26 16:56:59 -07002359 g_dev = NULL;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002360}
2361
Dustin Brown54096432017-02-23 13:00:44 -08002362int hdd_wlan_fake_apps_suspend(struct wiphy *wiphy, struct net_device *dev,
2363 enum wow_interface_pause pause_setting,
2364 enum wow_resume_trigger resume_setting)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002365{
Dustin Brownddb59702017-01-12 16:20:31 -08002366 qdf_device_t qdf_dev;
2367 struct hif_opaque_softc *hif_ctx;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002368 int errno;
Dustin Brown54096432017-02-23 13:00:44 -08002369 struct wow_enable_params wow_params = {
2370 .is_unit_test = true,
2371 .interface_pause = pause_setting,
2372 .resume_trigger = resume_setting
2373 };
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002374
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002375 hdd_info("Unit-test suspend WLAN");
Dustin Brownddb59702017-01-12 16:20:31 -08002376
Dustin Brown54096432017-02-23 13:00:44 -08002377 if (pause_setting < WOW_INTERFACE_PAUSE_DEFAULT ||
2378 pause_setting >= WOW_INTERFACE_PAUSE_COUNT) {
2379 hdd_err("Invalid interface pause %d (expected range [0, 2])",
2380 pause_setting);
2381 return -EINVAL;
2382 }
2383
2384 if (resume_setting < WOW_RESUME_TRIGGER_DEFAULT ||
2385 resume_setting >= WOW_RESUME_TRIGGER_COUNT) {
2386 hdd_err("Invalid resume trigger %d (expected range [0, 2])",
2387 resume_setting);
2388 return -EINVAL;
2389 }
2390
Dustin Brownddb59702017-01-12 16:20:31 -08002391 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2392 if (!qdf_dev) {
2393 hdd_err("Failed to get QDF device context");
2394 return -EINVAL;
2395 }
2396
2397 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2398 if (!hif_ctx) {
2399 hdd_err("Failed to get HIF context");
2400 return -EINVAL;
2401 }
2402
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002403 if (test_and_set_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) {
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002404 hdd_alert("Already unit-test suspended; Nothing to do");
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002405 return 0;
2406 }
2407
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002408 /* pci link is needed to wakeup from HTC wakeup trigger */
2409 if (resume_setting == WOW_RESUME_TRIGGER_HTC_WAKEUP)
2410 hif_vote_link_up(hif_ctx);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002411
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002412 errno = wlan_hdd_cfg80211_suspend_wlan(wiphy, NULL);
2413 if (errno)
2414 goto link_down;
2415
2416 errno = wlan_hdd_unit_test_bus_suspend(wow_params);
2417 if (errno)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002418 goto cfg80211_resume;
2419
2420 /* simulate kernel disabling irqs */
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002421 errno = hif_apps_irqs_disable(hif_ctx);
2422 if (errno)
2423 goto bus_resume;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002424
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002425 errno = wlan_hdd_bus_suspend_noirq();
2426 if (errno)
2427 goto enable_irqs;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002428
Dustin Brownbc81a472016-10-26 16:56:59 -07002429 /* pass wiphy/dev to callback via global variables */
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002430 g_wiphy = wiphy;
Dustin Brownbc81a472016-10-26 16:56:59 -07002431 g_dev = dev;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002432 g_resume_trigger = resume_setting;
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002433 hif_ut_apps_suspend(hif_ctx, hdd_wlan_fake_apps_resume_irq_callback);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002434
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002435 /* re-enable wake irq */
2436 errno = hif_apps_wake_irq_enable(hif_ctx);
2437 if (errno)
2438 goto fake_apps_resume;
2439
Dustin Brownbc81a472016-10-26 16:56:59 -07002440 /*
2441 * Tell the kernel not to worry if TX queues aren't moving. This is
2442 * expected since we are suspending the wifi hardware, but not APPS
2443 */
2444 dev->watchdog_timeo = INT_MAX;
2445
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002446 hdd_alert("Unit-test suspend succeeded");
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002447
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002448 return 0;
2449
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002450fake_apps_resume:
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002451 hif_ut_apps_resume(hif_ctx);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002452
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002453enable_irqs:
2454 QDF_BUG(!hif_apps_irqs_enable(hif_ctx));
2455
2456bus_resume:
2457 QDF_BUG(!wlan_hdd_bus_resume());
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002458
2459cfg80211_resume:
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002460 QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy));
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002461
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002462link_down:
2463 hif_vote_link_down(hif_ctx);
2464
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002465 clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state);
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002466 hdd_err("Unit-test suspend failed: %d", errno);
2467
2468 return errno;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002469}
2470
Dustin Brownbc81a472016-10-26 16:56:59 -07002471int hdd_wlan_fake_apps_resume(struct wiphy *wiphy, struct net_device *dev)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002472{
Dustin Brownddb59702017-01-12 16:20:31 -08002473 struct hif_opaque_softc *hif_ctx;
2474
2475 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2476 if (!hif_ctx) {
2477 hdd_err("Failed to get HIF context");
2478 return -EINVAL;
2479 }
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002480
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002481 hif_ut_apps_resume(hif_ctx);
Dustin Brownbc81a472016-10-26 16:56:59 -07002482 __hdd_wlan_fake_apps_resume(wiphy, dev);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002483
2484 return 0;
2485}
2486#endif