blob: ba52464dfea9a17ee43854e4fe101d5451535a03 [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"
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +053084#include "wlan_hdd_packet_filter_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080085
86/* Preprocessor definitions and constants */
Yue Ma5fe30dd2017-05-02 15:47:40 -070087#ifdef QCA_WIFI_NAPIER_EMULATION
88#define HDD_SSR_BRING_UP_TIME 3000000
89#else
Yue Ma4ea4f052015-10-27 12:25:27 -070090#define HDD_SSR_BRING_UP_TIME 30000
Yue Ma5fe30dd2017-05-02 15:47:40 -070091#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080092
93/* Type declarations */
94
Abhishek Singhbaea27d2016-04-27 13:29:30 +053095#ifdef FEATURE_WLAN_DIAG_SUPPORT
96/**
97 * hdd_wlan_suspend_resume_event()- send suspend/resume state
98 * @state: suspend/resume state
99 *
100 * This Function send send suspend resume state diag event
101 *
102 * Return: void.
103 */
104void hdd_wlan_suspend_resume_event(uint8_t state)
105{
106 WLAN_HOST_DIAG_EVENT_DEF(suspend_state, struct host_event_suspend);
107 qdf_mem_zero(&suspend_state, sizeof(suspend_state));
108
109 suspend_state.state = state;
110 WLAN_HOST_DIAG_EVENT_REPORT(&suspend_state, EVENT_WLAN_SUSPEND_RESUME);
111}
Abhishek Singh4aad0f72016-04-27 13:43:29 +0530112
113/**
114 * hdd_wlan_offload_event()- send offloads event
115 * @type: offload type
116 * @state: enabled or disabled
117 *
118 * This Function send offloads enable/disable diag event
119 *
120 * Return: void.
121 */
122
123void hdd_wlan_offload_event(uint8_t type, uint8_t state)
124{
125 WLAN_HOST_DIAG_EVENT_DEF(host_offload, struct host_event_offload_req);
126 qdf_mem_zero(&host_offload, sizeof(host_offload));
127
128 host_offload.offload_type = type;
129 host_offload.state = state;
130
131 WLAN_HOST_DIAG_EVENT_REPORT(&host_offload, EVENT_WLAN_OFFLOAD_REQ);
132}
Abhishek Singhbaea27d2016-04-27 13:29:30 +0530133#endif
134
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800135/**
Mukul Sharma3d36c392017-01-18 18:39:12 +0530136 * hdd_enable_gtk_offload() - enable GTK offload
137 * @adapter: pointer to the adapter
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138 *
Mukul Sharma3d36c392017-01-18 18:39:12 +0530139 * Central function to enable GTK offload.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800140 *
141 * Return: nothing
142 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700143static void hdd_enable_gtk_offload(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800144{
Mukul Sharma3d36c392017-01-18 18:39:12 +0530145 QDF_STATUS status;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -0700146
Mukul Sharma3d36c392017-01-18 18:39:12 +0530147 status = pmo_ucfg_enable_gtk_offload_in_fwr(adapter->hdd_vdev);
148 if (status != QDF_STATUS_SUCCESS)
149 hdd_info("Failed to enable gtk offload");
150}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800151
Mukul Sharma3d36c392017-01-18 18:39:12 +0530152/**
153 * hdd_disable_gtk_offload() - disable GTK offload
Jeff Johnsonf6d24282017-10-02 13:25:25 -0700154 * @adapter: pointer to the adapter
Mukul Sharma3d36c392017-01-18 18:39:12 +0530155 *
156 * Central function to disable GTK offload.
157 *
158 * Return: nothing
159 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700160static void hdd_disable_gtk_offload(struct hdd_adapter *adapter)
Mukul Sharma3d36c392017-01-18 18:39:12 +0530161{
162 struct pmo_gtk_rsp_req gtk_rsp_request;
163 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164
Mukul Sharma3d36c392017-01-18 18:39:12 +0530165 /* ensure to get gtk rsp first before disable it*/
166 gtk_rsp_request.callback =
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530167 wlan_hdd_cfg80211_update_replay_counter_cb;
Mukul Sharma3d36c392017-01-18 18:39:12 +0530168 /* Passing as void* as PMO does not know legacy HDD adapter type */
169 gtk_rsp_request.callback_context =
170 (void *)adapter;
171 status = pmo_ucfg_get_gtk_rsp(adapter->hdd_vdev,
172 &gtk_rsp_request);
173 if (status != QDF_STATUS_SUCCESS) {
174 hdd_err("Failed to send get gtk rsp status:%d", status);
175 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176 }
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800177 hdd_debug("send get_gtk_rsp successful");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530178 status = pmo_ucfg_disable_gtk_offload_in_fwr(adapter->hdd_vdev);
179 if (status != QDF_STATUS_SUCCESS)
180 hdd_info("Failed to disable gtk offload");
181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800183
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185/**
186 * __wlan_hdd_ipv6_changed() - IPv6 notifier callback function
187 * @nb: notifier block that was registered with the kernel
188 * @data: (unused) generic data that was registered with the kernel
189 * @arg: (unused) generic argument that was registered with the kernel
190 *
191 * This is a callback function that is registered with the kernel via
192 * register_inet6addr_notifier() which allows the driver to be
193 * notified when there is an IPv6 address change.
194 *
195 * Return: NOTIFY_DONE to indicate we don't care what happens with
196 * other callbacks
197 */
198static int __wlan_hdd_ipv6_changed(struct notifier_block *nb,
Dustin Brownf13b8c32017-05-19 17:23:08 -0700199 unsigned long data, void *arg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800200{
201 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
202 struct net_device *ndev = ifa->idev->dev;
Jeff Johnson75b737d2017-08-29 14:24:41 -0700203 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700204 struct hdd_context *hdd_ctx;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700205 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206
Jeff Johnson158c8d02016-10-31 13:11:48 -0700207 ENTER_DEV(ndev);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530208
Dustin Brownf13b8c32017-05-19 17:23:08 -0700209 errno = hdd_validate_adapter(adapter);
210 if (errno)
211 goto exit;
212
213 if (adapter->dev == ndev &&
214 (adapter->device_mode == QDF_STA_MODE ||
215 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
216 adapter->device_mode == QDF_NDI_MODE)) {
217 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
218 errno = wlan_hdd_validate_context(hdd_ctx);
219 if (errno)
220 goto exit;
221
Nachiket Kukadec9045fe2017-06-19 15:14:43 +0530222 /* Ignore if the interface is down */
223 if (!(ndev->flags & IFF_UP)) {
224 hdd_err("Rcvd change addr request on %s(flags 0x%X)",
225 ndev->name, ndev->flags);
226 hdd_err("NETDEV Interface is down, ignoring...");
227 goto exit;
228 }
229
Dustin Brownf13b8c32017-05-19 17:23:08 -0700230 hdd_debug("invoking sme_dhcp_done_ind");
Jeff Johnson1b780e42017-10-31 14:11:45 -0700231 sme_dhcp_done_ind(hdd_ctx->hHal, adapter->session_id);
Jeff Johnsonb527ebe2017-10-28 13:14:03 -0700232 schedule_work(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800233 }
234
Dustin Brownf13b8c32017-05-19 17:23:08 -0700235exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530236 EXIT();
Dustin Brownf13b8c32017-05-19 17:23:08 -0700237
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800238 return NOTIFY_DONE;
239}
240
241/**
242 * wlan_hdd_ipv6_changed() - IPv6 change notifier callback
243 * @nb: pointer to notifier block
244 * @data: data
245 * @arg: arg
246 *
247 * This is the IPv6 notifier callback function gets invoked
248 * if any change in IP and then invoke the function @__wlan_hdd_ipv6_changed
249 * to reconfigure the offload parameters.
250 *
251 * Return: 0 on success, error number otherwise.
252 */
253int wlan_hdd_ipv6_changed(struct notifier_block *nb,
254 unsigned long data, void *arg)
255{
256 int ret;
257
258 cds_ssr_protect(__func__);
259 ret = __wlan_hdd_ipv6_changed(nb, data, arg);
260 cds_ssr_unprotect(__func__);
261
262 return ret;
263}
264
265/**
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530266 * hdd_fill_ipv6_uc_addr() - fill IPv6 unicast addresses
267 * @idev: pointer to net device
268 * @ipv6addr: destination array to fill IPv6 addresses
269 * @ipv6addr_type: IPv6 Address type
270 * @count: number of IPv6 addresses
271 *
272 * This is the IPv6 utility function to populate unicast addresses.
273 *
274 * Return: 0 on success, error number otherwise.
275 */
276static int hdd_fill_ipv6_uc_addr(struct inet6_dev *idev,
277 uint8_t ipv6_uc_addr[][SIR_MAC_IPV6_ADDR_LEN],
278 uint8_t *ipv6addr_type, uint32_t *count)
279{
280 struct inet6_ifaddr *ifa;
281 struct list_head *p;
282 uint32_t scope;
283
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700284 read_lock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530285 list_for_each(p, &idev->addr_list) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530286 if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) {
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700287 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530288 return -EINVAL;
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700289 }
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530290 ifa = list_entry(p, struct inet6_ifaddr, if_list);
291 if (ifa->flags & IFA_F_DADFAILED)
292 continue;
293 scope = ipv6_addr_src_scope(&ifa->addr);
294 switch (scope) {
295 case IPV6_ADDR_SCOPE_GLOBAL:
296 case IPV6_ADDR_SCOPE_LINKLOCAL:
297 qdf_mem_copy(ipv6_uc_addr[*count], &ifa->addr.s6_addr,
298 sizeof(ifa->addr.s6_addr));
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530299 ipv6addr_type[*count] = PMO_IPV6_ADDR_UC_TYPE;
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800300 hdd_debug("Index %d scope = %s UC-Address: %pI6",
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530301 *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ?
302 "LINK LOCAL" : "GLOBAL", ipv6_uc_addr[*count]);
303 *count += 1;
304 break;
305 default:
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800306 hdd_warn("The Scope %d is not supported", scope);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530307 }
308 }
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700309
310 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530311 return 0;
312}
313
314/**
315 * hdd_fill_ipv6_ac_addr() - fill IPv6 anycast addresses
316 * @idev: pointer to net device
317 * @ipv6addr: destination array to fill IPv6 addresses
318 * @ipv6addr_type: IPv6 Address type
319 * @count: number of IPv6 addresses
320 *
321 * This is the IPv6 utility function to populate anycast addresses.
322 *
323 * Return: 0 on success, error number otherwise.
324 */
325static int hdd_fill_ipv6_ac_addr(struct inet6_dev *idev,
326 uint8_t ipv6_ac_addr[][SIR_MAC_IPV6_ADDR_LEN],
327 uint8_t *ipv6addr_type, uint32_t *count)
328{
329 struct ifacaddr6 *ifaca;
330 uint32_t scope;
331
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700332 read_lock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530333 for (ifaca = idev->ac_list; ifaca; ifaca = ifaca->aca_next) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530334 if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) {
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700335 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530336 return -EINVAL;
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700337 }
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530338 /* For anycast addr no DAD */
339 scope = ipv6_addr_src_scope(&ifaca->aca_addr);
340 switch (scope) {
341 case IPV6_ADDR_SCOPE_GLOBAL:
342 case IPV6_ADDR_SCOPE_LINKLOCAL:
343 qdf_mem_copy(ipv6_ac_addr[*count], &ifaca->aca_addr,
344 sizeof(ifaca->aca_addr));
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530345 ipv6addr_type[*count] = PMO_IPV6_ADDR_AC_TYPE;
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800346 hdd_debug("Index %d scope = %s AC-Address: %pI6",
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530347 *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ?
348 "LINK LOCAL" : "GLOBAL", ipv6_ac_addr[*count]);
349 *count += 1;
350 break;
351 default:
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800352 hdd_warn("The Scope %d is not supported", scope);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530353 }
354 }
Srinivas Girigowda90cdd3c2016-10-18 11:28:10 -0700355
356 read_unlock_bh(&idev->lock);
Sravan Kumar Kairamc0873582016-07-26 17:34:57 +0530357 return 0;
358}
359
Jeff Johnson75b737d2017-08-29 14:24:41 -0700360void hdd_enable_ns_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530361 enum pmo_offload_trigger trigger)
Dustin Brown2444ee62016-09-06 17:20:36 -0700362{
363 struct inet6_dev *in6_dev;
Dustin Brown2444ee62016-09-06 17:20:36 -0700364 QDF_STATUS status;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700365 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530366 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
367 struct pmo_ns_req *ns_req = NULL;
368 int err;
369
370 ENTER();
371 if (!psoc) {
372 hdd_err("psoc is NULL");
373 goto out;
374 }
Dustin Brown2444ee62016-09-06 17:20:36 -0700375
376 in6_dev = __in6_dev_get(adapter->dev);
377 if (NULL == in6_dev) {
378 hdd_err("IPv6 dev does not exist. Failed to request NSOffload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530379 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700380 }
381
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530382 ns_req = qdf_mem_malloc(sizeof(*ns_req));
383 if (!ns_req) {
384 hdd_err("fail to allocate ns_req");
385 goto out;
386 }
387
388 ns_req->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -0700389 ns_req->vdev_id = adapter->session_id;
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530390 ns_req->trigger = trigger;
391 ns_req->count = 0;
392
Dustin Brown2444ee62016-09-06 17:20:36 -0700393 /* Unicast Addresses */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530394 err = hdd_fill_ipv6_uc_addr(in6_dev, ns_req->ipv6_addr,
395 ns_req->ipv6_addr_type, &ns_req->count);
Dustin Brown2444ee62016-09-06 17:20:36 -0700396 if (err) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530397 hdd_disable_ns_offload(adapter, trigger);
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530398 hdd_debug("Max supported addresses: disabling NS offload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530399 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700400 }
401
402 /* Anycast Addresses */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530403 err = hdd_fill_ipv6_ac_addr(in6_dev, ns_req->ipv6_addr,
404 ns_req->ipv6_addr_type, &ns_req->count);
Dustin Brown2444ee62016-09-06 17:20:36 -0700405 if (err) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530406 hdd_disable_ns_offload(adapter, trigger);
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530407 hdd_debug("Max supported addresses: disabling NS offload");
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530408 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700409 }
410
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530411 /* cache ns request */
412 status = pmo_ucfg_cache_ns_offload_req(ns_req);
413 if (status != QDF_STATUS_SUCCESS) {
414 hdd_err("Failed to cache ns request status: %d", status);
415 goto out;
Dustin Brown2444ee62016-09-06 17:20:36 -0700416 }
417
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530418 /* enable ns request */
419 status = pmo_ucfg_enable_ns_offload_in_fwr(adapter->hdd_vdev, trigger);
420 if (status != QDF_STATUS_SUCCESS)
Dustin Brown2444ee62016-09-06 17:20:36 -0700421 hdd_err("Failed to enable HostOffload feature with status: %d",
422 status);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530423 else
424 hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD, SIR_OFFLOAD_ENABLE);
425out:
426 if (ns_req)
427 qdf_mem_free(ns_req);
428 EXIT();
429
Dustin Brown2444ee62016-09-06 17:20:36 -0700430}
431
Jeff Johnson75b737d2017-08-29 14:24:41 -0700432void hdd_disable_ns_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530433 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800434{
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530435 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800436
437 ENTER();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530438 status = pmo_ucfg_flush_ns_offload_req(adapter->hdd_vdev);
439 if (status != QDF_STATUS_SUCCESS) {
440 hdd_err("Failed to flush NS Offload");
441 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800442 }
443
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530444 status = pmo_ucfg_disable_ns_offload_in_fwr(adapter->hdd_vdev, trigger);
445 if (status != QDF_STATUS_SUCCESS)
446 hdd_err("Failed to disable NS Offload");
Dustin Brown2444ee62016-09-06 17:20:36 -0700447 else
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530448 hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD,
449 SIR_OFFLOAD_DISABLE);
450out:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800451 EXIT();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530452
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800453}
454
455/**
456 * __hdd_ipv6_notifier_work_queue() - IPv6 notification work function
457 * @work: registered work item
458 *
459 * This function performs the work initially trigged by a callback
460 * from the IPv6 netdev notifier. Since this means there has been a
461 * change in IPv6 state for the interface, the NS offload is
462 * reconfigured.
463 *
464 * Return: None
465 */
Jeff Johnsonc8d0c252016-10-05 16:19:50 -0700466static void __hdd_ipv6_notifier_work_queue(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800467{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700468 struct hdd_context *hdd_ctx;
Jeff Johnson75b737d2017-08-29 14:24:41 -0700469 struct hdd_adapter *adapter;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700470 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800471
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530472 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800473
Jeff Johnsonb527ebe2017-10-28 13:14:03 -0700474 adapter = container_of(work, struct hdd_adapter, ipv6_notifier_work);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700475 errno = hdd_validate_adapter(adapter);
476 if (errno)
477 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478
Dustin Brownf13b8c32017-05-19 17:23:08 -0700479 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
480 errno = wlan_hdd_validate_context(hdd_ctx);
481 if (errno)
482 goto exit;
483
484 hdd_enable_ns_offload(adapter, pmo_ipv6_change_notify);
485
486exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530487 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488}
489
490/**
491 * hdd_ipv6_notifier_work_queue() - IP V6 change notifier work handler
492 * @work: Pointer to work context
493 *
494 * Return: none
495 */
496void hdd_ipv6_notifier_work_queue(struct work_struct *work)
497{
498 cds_ssr_protect(__func__);
499 __hdd_ipv6_notifier_work_queue(work);
500 cds_ssr_unprotect(__func__);
501}
502
Jeff Johnson75b737d2017-08-29 14:24:41 -0700503static void hdd_enable_hw_filter(struct hdd_adapter *adapter)
Dustin Brown1224e212017-05-12 14:02:12 -0700504{
505 QDF_STATUS status;
506
507 ENTER();
508
509 status = pmo_ucfg_enable_hw_filter_in_fwr(adapter->hdd_vdev);
510 if (status != QDF_STATUS_SUCCESS)
511 hdd_info("Failed to enable hardware filter");
512
513 EXIT();
514}
515
Jeff Johnson75b737d2017-08-29 14:24:41 -0700516static void hdd_disable_hw_filter(struct hdd_adapter *adapter)
Dustin Brown1224e212017-05-12 14:02:12 -0700517{
518 QDF_STATUS status;
519
520 ENTER();
521
522 status = pmo_ucfg_disable_hw_filter_in_fwr(adapter->hdd_vdev);
523 if (status != QDF_STATUS_SUCCESS)
524 hdd_info("Failed to disable hardware filter");
525
526 EXIT();
527}
528
Jeff Johnson75b737d2017-08-29 14:24:41 -0700529void hdd_enable_host_offloads(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530530 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531{
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530532 ENTER();
533
Rajeev Kumarec1194d2017-11-16 17:30:01 -0800534 if (!ucfg_pmo_is_vdev_supports_offload(adapter->hdd_vdev)) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530535 hdd_info("offload is not supported on this vdev opmode: %d",
536 adapter->device_mode);
537 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800538 }
539
Rajeev Kumar9084cc82017-10-31 14:32:08 -0700540 if (!ucfg_pmo_is_vdev_connected(adapter->hdd_vdev)) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530541 hdd_info("vdev is not connected");
542 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 }
544
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530545 hdd_info("enable offloads");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530546 hdd_enable_gtk_offload(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530547 hdd_enable_arp_offload(adapter, trigger);
548 hdd_enable_ns_offload(adapter, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530549 hdd_enable_mc_addr_filtering(adapter, trigger);
Dustin Brown1224e212017-05-12 14:02:12 -0700550 hdd_enable_hw_filter(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530551out:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530552 EXIT();
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530553
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800554}
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530555
Jeff Johnson75b737d2017-08-29 14:24:41 -0700556void hdd_disable_host_offloads(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530557 enum pmo_offload_trigger trigger)
558{
559 ENTER();
560
Rajeev Kumarec1194d2017-11-16 17:30:01 -0800561 if (!ucfg_pmo_is_vdev_supports_offload(adapter->hdd_vdev)) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530562 hdd_info("offload is not supported on this vdev opmode: %d",
563 adapter->device_mode);
564 goto out;
565 }
566
Rajeev Kumar9084cc82017-10-31 14:32:08 -0700567 if (!ucfg_pmo_is_vdev_connected(adapter->hdd_vdev)) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530568 hdd_info("vdev is not connected");
569 goto out;
570 }
571
572 hdd_info("disable offloads");
Mukul Sharma3d36c392017-01-18 18:39:12 +0530573 hdd_disable_gtk_offload(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530574 hdd_disable_arp_offload(adapter, trigger);
575 hdd_disable_ns_offload(adapter, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530576 hdd_disable_mc_addr_filtering(adapter, trigger);
Dustin Brown1224e212017-05-12 14:02:12 -0700577 hdd_disable_hw_filter(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530578out:
579 EXIT();
580
581}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800582
583/**
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800584 * hdd_lookup_ifaddr() - Lookup interface address data by name
585 * @adapter: the adapter whose name should be searched for
586 *
587 * return in_ifaddr pointer on success, NULL for failure
588 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700589static struct in_ifaddr *hdd_lookup_ifaddr(struct hdd_adapter *adapter)
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800590{
591 struct in_ifaddr *ifa;
592 struct in_device *in_dev;
593
594 if (!adapter) {
595 hdd_err("adapter is null");
596 return NULL;
597 }
598
599 in_dev = __in_dev_get_rtnl(adapter->dev);
600 if (!in_dev) {
601 hdd_err("Failed to get in_device");
602 return NULL;
603 }
604
605 /* lookup address data by interface name */
606 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
607 if (!strcmp(adapter->dev->name, ifa->ifa_label))
608 return ifa;
609 }
610
611 return NULL;
612}
613
614/**
615 * hdd_populate_ipv4_addr() - Populates the adapter's IPv4 address
616 * @adapter: the adapter whose IPv4 address is desired
617 * @ipv4_addr: the address of the array to copy the IPv4 address into
618 *
619 * return: zero for success; non-zero for failure
620 */
Jeff Johnsond6d1f632017-10-06 20:06:10 -0700621static int hdd_populate_ipv4_addr(struct hdd_adapter *adapter,
622 uint8_t *ipv4_addr)
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800623{
624 struct in_ifaddr *ifa;
625 int i;
626
627 if (!adapter) {
628 hdd_err("adapter is null");
629 return -EINVAL;
630 }
631
632 if (!ipv4_addr) {
633 hdd_err("ipv4_addr is null");
634 return -EINVAL;
635 }
636
637 ifa = hdd_lookup_ifaddr(adapter);
638 if (!ifa || !ifa->ifa_local) {
639 hdd_err("ipv4 address not found");
640 return -EINVAL;
641 }
642
643 /* convert u32 to byte array */
644 for (i = 0; i < 4; i++)
645 ipv4_addr[i] = (ifa->ifa_local >> i * 8) & 0xff;
646
647 return 0;
648}
649
650/**
651 * hdd_set_grat_arp_keepalive() - Enable grat APR keepalive
652 * @adapter: the HDD adapter to configure
653 *
654 * This configures gratuitous APR keepalive based on the adapter's current
655 * connection information, specifically IPv4 address and BSSID
656 *
657 * return: zero for success, non-zero for failure
658 */
Jeff Johnson75b737d2017-08-29 14:24:41 -0700659static int hdd_set_grat_arp_keepalive(struct hdd_adapter *adapter)
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800660{
661 QDF_STATUS status;
662 int exit_code;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700663 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -0700664 struct hdd_station_ctx *sta_ctx;
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800665 tSirKeepAliveReq req = {
666 .packetType = SIR_KEEP_ALIVE_UNSOLICIT_ARP_RSP,
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800667 .dest_macaddr = QDF_MAC_ADDR_BROADCAST_INITIALIZER,
668 };
669
670 if (!adapter) {
671 hdd_err("adapter is null");
672 return -EINVAL;
673 }
674
675 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
676 if (!hdd_ctx) {
677 hdd_err("hdd_ctx is null");
678 return -EINVAL;
679 }
680
681 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
682 if (!sta_ctx) {
683 hdd_err("sta_ctx is null");
684 return -EINVAL;
685 }
686
687 exit_code = hdd_populate_ipv4_addr(adapter, req.hostIpv4Addr);
688 if (exit_code) {
689 hdd_err("Failed to populate ipv4 address");
690 return exit_code;
691 }
692
Dustin Brown6b4643d2017-02-09 12:19:28 -0800693 /* according to RFC5227, sender/target ip address should be the same */
694 qdf_mem_copy(&req.destIpv4Addr, &req.hostIpv4Addr,
695 sizeof(req.destIpv4Addr));
696
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800697 qdf_copy_macaddr(&req.bssid, &sta_ctx->conn_info.bssId);
698 req.timePeriod = hdd_ctx->config->infraStaKeepAlivePeriod;
Jeff Johnson1b780e42017-10-31 14:11:45 -0700699 req.sessionId = adapter->session_id;
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800700
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800701 hdd_debug("Setting gratuitous ARP keepalive; ipv4_addr:%u.%u.%u.%u",
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800702 req.hostIpv4Addr[0], req.hostIpv4Addr[1],
703 req.hostIpv4Addr[2], req.hostIpv4Addr[3]);
704
705 status = sme_set_keep_alive(hdd_ctx->hHal, req.sessionId, &req);
706 if (QDF_IS_STATUS_ERROR(status)) {
707 hdd_err("Failed to set keepalive");
708 return qdf_status_to_os_return(status);
709 }
710
711 return 0;
712}
713
714/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800715 * __hdd_ipv4_notifier_work_queue() - IPv4 notification work function
716 * @work: registered work item
717 *
718 * This function performs the work initially trigged by a callback
719 * from the IPv4 netdev notifier. Since this means there has been a
720 * change in IPv4 state for the interface, the ARP offload is
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +0530721 * reconfigured. Also, Updates the HLP IE info with IP address info
722 * to fw if LFR3 is enabled
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800723 *
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;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +0530731 struct hdd_wext_state *wext_state;
732 tCsrRoamProfile *roam_profile;
733 struct in_ifaddr *ifa;
Dustin Brownb6b0f182017-03-08 13:08:27 -0800734
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530735 ENTER();
Dustin Brownb6b0f182017-03-08 13:08:27 -0800736
Jeff Johnsonb527ebe2017-10-28 13:14:03 -0700737 adapter = container_of(work, struct hdd_adapter, ipv4_notifier_work);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700738 errno = hdd_validate_adapter(adapter);
739 if (errno)
740 goto exit;
Dustin Brownb6b0f182017-03-08 13:08:27 -0800741
742 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700743 errno = wlan_hdd_validate_context(hdd_ctx);
744 if (errno)
745 goto exit;
746
747 hdd_enable_arp_offload(adapter, pmo_ipv4_change_notify);
748
Dustin Brownb6b0f182017-03-08 13:08:27 -0800749 if (hdd_ctx->config->sta_keepalive_method == HDD_STA_KEEPALIVE_GRAT_ARP)
750 hdd_set_grat_arp_keepalive(adapter);
751
Vignesh Viswanathan731186f2017-09-18 13:47:37 +0530752 hdd_debug("FILS Roaming support: %d",
753 hdd_ctx->is_fils_roaming_supported);
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +0530754 wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
755 roam_profile = &wext_state->roamProfile;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +0530756
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +0530757 ifa = hdd_lookup_ifaddr(adapter);
Vignesh Viswanathan731186f2017-09-18 13:47:37 +0530758 if (ifa && hdd_ctx->is_fils_roaming_supported)
Jeff Johnson1b780e42017-10-31 14:11:45 -0700759 sme_send_hlp_ie_info(hdd_ctx->hHal, adapter->session_id,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +0530760 roam_profile, ifa->ifa_local);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700761exit:
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530762 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800763}
764
765/**
766 * hdd_ipv4_notifier_work_queue() - IP V4 change notifier work handler
767 * @work: Pointer to work context
768 *
769 * Return: none
770 */
771void hdd_ipv4_notifier_work_queue(struct work_struct *work)
772{
773 cds_ssr_protect(__func__);
774 __hdd_ipv4_notifier_work_queue(work);
775 cds_ssr_unprotect(__func__);
776}
777
778/**
779 * __wlan_hdd_ipv4_changed() - IPv4 notifier callback function
780 * @nb: notifier block that was registered with the kernel
781 * @data: (unused) generic data that was registered with the kernel
782 * @arg: (unused) generic argument that was registered with the kernel
783 *
784 * This is a callback function that is registered with the kernel via
785 * register_inetaddr_notifier() which allows the driver to be
786 * notified when there is an IPv4 address change.
787 *
788 * Return: NOTIFY_DONE to indicate we don't care what happens with
789 * other callbacks
790 */
791static int __wlan_hdd_ipv4_changed(struct notifier_block *nb,
792 unsigned long data, void *arg)
793{
794 struct in_ifaddr *ifa = (struct in_ifaddr *)arg;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800795 struct net_device *ndev = ifa->ifa_dev->dev;
Jeff Johnson75b737d2017-08-29 14:24:41 -0700796 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700797 struct hdd_context *hdd_ctx;
Dustin Brownf13b8c32017-05-19 17:23:08 -0700798 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800799
Jeff Johnson158c8d02016-10-31 13:11:48 -0700800 ENTER_DEV(ndev);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530801
Dustin Brownf13b8c32017-05-19 17:23:08 -0700802 errno = hdd_validate_adapter(adapter);
803 if (errno)
804 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805
Dustin Brownf13b8c32017-05-19 17:23:08 -0700806 if (adapter->dev == ndev &&
807 (adapter->device_mode == QDF_STA_MODE ||
808 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
809 adapter->device_mode == QDF_NDI_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810
Dustin Brownf13b8c32017-05-19 17:23:08 -0700811 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
812 errno = wlan_hdd_validate_context(hdd_ctx);
813 if (errno)
814 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800815
Nachiket Kukadec9045fe2017-06-19 15:14:43 +0530816 /* Ignore if the interface is down */
817 if (!(ndev->flags & IFF_UP)) {
818 hdd_err("Rcvd change addr request on %s(flags 0x%X)",
819 ndev->name, ndev->flags);
820 hdd_err("NETDEV Interface is down, ignoring...");
821 goto exit;
822 }
Padma, Santhosh Kumar8392fb42017-03-17 12:35:27 +0530823 hdd_debug("invoking sme_dhcp_done_ind");
Jeff Johnson1b780e42017-10-31 14:11:45 -0700824 sme_dhcp_done_ind(hdd_ctx->hHal, adapter->session_id);
Abhishek Singhca408032016-09-13 15:26:12 +0530825
Dustin Brownf13b8c32017-05-19 17:23:08 -0700826 if (!hdd_ctx->config->fhostArpOffload) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -0800827 hdd_debug("Offload not enabled ARPOffload=%d",
Dustin Brownf13b8c32017-05-19 17:23:08 -0700828 hdd_ctx->config->fhostArpOffload);
829 goto exit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 }
831
Dustin Brownf13b8c32017-05-19 17:23:08 -0700832 ifa = hdd_lookup_ifaddr(adapter);
Dustin Brown3c31ceb2017-02-01 14:43:52 -0800833 if (ifa && ifa->ifa_local)
Jeff Johnsonb527ebe2017-10-28 13:14:03 -0700834 schedule_work(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 }
Dustin Brownf13b8c32017-05-19 17:23:08 -0700836
837exit:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +0530838 EXIT();
Dustin Brownf13b8c32017-05-19 17:23:08 -0700839
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 return NOTIFY_DONE;
841}
842
843/**
844 * wlan_hdd_ipv4_changed() - IPv4 change notifier callback
845 * @nb: pointer to notifier block
846 * @data: data
847 * @arg: arg
848 *
849 * This is the IPv4 notifier callback function gets invoked
850 * if any change in IP and then invoke the function @__wlan_hdd_ipv4_changed
851 * to reconfigure the offload parameters.
852 *
853 * Return: 0 on success, error number otherwise.
854 */
855int wlan_hdd_ipv4_changed(struct notifier_block *nb,
856 unsigned long data, void *arg)
857{
858 int ret;
859
860 cds_ssr_protect(__func__);
861 ret = __wlan_hdd_ipv4_changed(nb, data, arg);
862 cds_ssr_unprotect(__func__);
863
864 return ret;
865}
866
867/**
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530868 * hdd_get_ipv4_local_interface() - get ipv4 local interafce from iface list
Jeff Johnsonf6d24282017-10-02 13:25:25 -0700869 * @adapter: Adapter context for which ARP offload is to be configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 *
871 * Return:
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530872 * ifa - on successful operation,
873 * NULL - on failure of operation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 */
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530875static struct in_ifaddr *hdd_get_ipv4_local_interface(
Jeff Johnsonf6d24282017-10-02 13:25:25 -0700876 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877{
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530878 struct in_ifaddr **ifap = NULL;
879 struct in_ifaddr *ifa = NULL;
880 struct in_device *in_dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800881
Jeff Johnsonf6d24282017-10-02 13:25:25 -0700882 in_dev = __in_dev_get_rtnl(adapter->dev);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530883 if (in_dev) {
884 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
885 ifap = &ifa->ifa_next) {
Jeff Johnsonf6d24282017-10-02 13:25:25 -0700886 if (!strcmp(adapter->dev->name, ifa->ifa_label)) {
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530887 /* if match break */
888 return ifa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800889 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 }
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530891 }
892 ifa = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530894 return ifa;
895}
896
Jeff Johnson75b737d2017-08-29 14:24:41 -0700897void hdd_enable_arp_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530898 enum pmo_offload_trigger trigger)
899{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -0700900 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530901 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
902 QDF_STATUS status;
903 struct pmo_arp_req *arp_req = NULL;
904 struct in_ifaddr *ifa = NULL;
905
906 ENTER();
907 arp_req = qdf_mem_malloc(sizeof(*arp_req));
908 if (!arp_req) {
909 hdd_err("cannot allocate arp_req");
910 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 }
Jeff Johnson68755312017-02-10 11:46:55 -0800912
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530913 arp_req->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -0700914 arp_req->vdev_id = adapter->session_id;
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530915 arp_req->trigger = trigger;
Jeff Johnson68755312017-02-10 11:46:55 -0800916
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530917 ifa = hdd_get_ipv4_local_interface(adapter);
918 if (ifa && ifa->ifa_local) {
919 arp_req->ipv4_addr = (uint32_t)ifa->ifa_local;
920 status = pmo_ucfg_cache_arp_offload_req(arp_req);
921 if (status == QDF_STATUS_SUCCESS) {
922 status = pmo_ucfg_enable_arp_offload_in_fwr(
923 adapter->hdd_vdev, trigger);
924 if (status == QDF_STATUS_SUCCESS)
925 hdd_wlan_offload_event(
926 PMO_IPV4_ARP_REPLY_OFFLOAD,
927 PMO_OFFLOAD_ENABLE);
928 else
929 hdd_info("fail to enable arp offload in fwr");
930 } else
931 hdd_info("fail to cache arp offload request");
932 } else {
933 hdd_notice("IP Address is not assigned");
934 status = QDF_STATUS_NOT_INITIALIZED;
935 }
936out:
937 if (arp_req)
938 qdf_mem_free(arp_req);
939 EXIT();
940
941}
942
Jeff Johnson75b737d2017-08-29 14:24:41 -0700943void hdd_disable_arp_offload(struct hdd_adapter *adapter,
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530944 enum pmo_offload_trigger trigger)
945{
946 QDF_STATUS status;
947
948 ENTER();
949 status = pmo_ucfg_flush_arp_offload_req(adapter->hdd_vdev);
950 if (status != QDF_STATUS_SUCCESS) {
951 hdd_err("Failed to flush arp Offload");
952 goto out;
Jeff Johnson68755312017-02-10 11:46:55 -0800953 }
954
Jeff Johnsond6d1f632017-10-06 20:06:10 -0700955 status = pmo_ucfg_disable_arp_offload_in_fwr(adapter->hdd_vdev,
956 trigger);
Mukul Sharma3ba26b82017-01-12 21:59:41 +0530957 if (status == QDF_STATUS_SUCCESS)
958 hdd_wlan_offload_event(PMO_IPV4_ARP_REPLY_OFFLOAD,
959 PMO_OFFLOAD_DISABLE);
960 else
961 hdd_info("fail to disable arp offload");
962out:
963 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964}
965
Jeff Johnson75b737d2017-08-29 14:24:41 -0700966void hdd_enable_mc_addr_filtering(struct hdd_adapter *adapter,
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530967 enum pmo_offload_trigger trigger)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968{
Jeff Johnson399c6272017-08-30 10:51:00 -0700969 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530970 QDF_STATUS status;
971 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800972
Ravi Joshi24477b72016-07-19 15:45:09 -0700973 ENTER();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530974 if (wlan_hdd_validate_context(hdd_ctx))
975 goto out;
Ravi Joshi24477b72016-07-19 15:45:09 -0700976
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530977 status = pmo_ucfg_enable_mc_addr_filtering_in_fwr(psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700978 adapter->session_id, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530979 if (status != QDF_STATUS_SUCCESS)
980 hdd_info("failed to enable mc list status %d", status);
981out:
Ravi Joshi24477b72016-07-19 15:45:09 -0700982 EXIT();
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530983
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984}
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530985
Jeff Johnson75b737d2017-08-29 14:24:41 -0700986void hdd_disable_mc_addr_filtering(struct hdd_adapter *adapter,
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530987 enum pmo_offload_trigger trigger)
988{
Jeff Johnson399c6272017-08-30 10:51:00 -0700989 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530990 QDF_STATUS status = QDF_STATUS_SUCCESS;
991 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
992
993 ENTER();
994 if (wlan_hdd_validate_context(hdd_ctx))
995 goto out;
996
997 status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700998 adapter->session_id, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +0530999 if (status != QDF_STATUS_SUCCESS)
1000 hdd_info("failed to disable mc list status %d", status);
1001out:
1002 EXIT();
1003
1004}
1005
1006int hdd_cache_mc_addr_list(struct pmo_mc_addr_list_params *mc_list_config)
1007{
1008 QDF_STATUS status;
1009 int ret = 0;
1010
1011 ENTER();
1012 /* cache mc addr list */
1013 status = pmo_ucfg_cache_mc_addr_list(mc_list_config);
1014 if (status != QDF_STATUS_SUCCESS) {
1015 hdd_info("fail to cache mc list status %d", status);
1016 ret = -EINVAL;
1017 }
1018 EXIT();
1019
1020 return ret;
1021}
1022
Jeff Johnson75b737d2017-08-29 14:24:41 -07001023void hdd_disable_and_flush_mc_addr_list(struct hdd_adapter *adapter,
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05301024 enum pmo_offload_trigger trigger)
1025{
Jeff Johnson399c6272017-08-30 10:51:00 -07001026 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05301027 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1028 QDF_STATUS status = QDF_STATUS_SUCCESS;
1029
1030 ENTER();
1031 /* disable mc list first */
1032 status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001033 adapter->session_id, trigger);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05301034 if (status != QDF_STATUS_SUCCESS)
1035 hdd_info("fail to disable mc list");
1036
1037 /* flush mc list */
Jeff Johnson1b780e42017-10-31 14:11:45 -07001038 status = pmo_ucfg_flush_mc_addr_list(psoc, adapter->session_id);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05301039 if (status != QDF_STATUS_SUCCESS)
1040 hdd_info("fail to flush mc list status %d", status);
1041 EXIT();
1042
1043 return;
1044
1045}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046
1047/**
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001048 * hdd_update_conn_state_mask(): record info needed by wma_suspend_req
1049 * @adapter: adapter to get info from
1050 * @conn_state_mask: mask of connection info
1051 *
1052 * currently only need to send connection info.
1053 */
Jeff Johnsond6d1f632017-10-06 20:06:10 -07001054static void hdd_update_conn_state_mask(struct hdd_adapter *adapter,
1055 uint32_t *conn_state_mask)
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001056{
1057
1058 eConnectionState connState;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07001059 struct hdd_station_ctx *sta_ctx;
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301060
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001061 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301062
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001063 connState = sta_ctx->conn_info.connState;
1064
1065 if (connState == eConnectionState_Associated ||
1066 connState == eConnectionState_IbssConnected)
Jeff Johnson1b780e42017-10-31 14:11:45 -07001067 *conn_state_mask |= (1 << adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068}
1069
1070/**
1071 * hdd_suspend_wlan() - Driver suspend function
1072 * @callback: Callback function to invoke when driver is ready to suspend
1073 * @callbackContext: Context to pass back to @callback function
1074 *
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301075 * Return: 0 on success else error code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301077static int
1078hdd_suspend_wlan(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079{
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001080 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301082 QDF_STATUS status;
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001083 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001084 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001085 uint32_t conn_state_mask = 0;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07001086
Jeff Johnsonc3273322016-07-06 15:28:17 -07001087 hdd_info("WLAN being suspended by OS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001089 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1090 if (!hdd_ctx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001091 hdd_err("HDD context is Null");
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301092 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 }
1094
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301095 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001096 hdd_info("Recovery in Progress. State: 0x%x Ignore suspend!!!",
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001097 cds_get_driver_state());
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301098 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001099 }
1100
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001101 status = hdd_get_front_adapter(hdd_ctx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301102 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001103 adapter = pAdapterNode->adapter;
Jeff Johnson1b780e42017-10-31 14:11:45 -07001104 if (wlan_hdd_validate_session_id(adapter->session_id)) {
1105 hdd_err("invalid session id: %d", adapter->session_id);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301106 goto next_adapter;
1107 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001108
1109 /* stop all TX queues before suspend */
Srinivas Girigowda6598eea2017-07-06 19:26:19 -07001110 hdd_info("Disabling queues");
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001111 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05301112 WLAN_STOP_ALL_NETIF_QUEUE,
1113 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +05301115 if (adapter->device_mode == QDF_STA_MODE)
1116 status = hdd_enable_default_pkt_filters(adapter);
1117
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001118 /* Configure supported OffLoads */
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001119 hdd_enable_host_offloads(adapter, pmo_apps_suspend);
1120 hdd_update_conn_state_mask(adapter, &conn_state_mask);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301121next_adapter:
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001122 status = hdd_get_next_adapter(hdd_ctx, pAdapterNode, &pNext);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001123 pAdapterNode = pNext;
1124 }
1125
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001126 status = pmo_ucfg_psoc_user_space_suspend_req(hdd_ctx->hdd_psoc,
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301127 QDF_SYSTEM_SUSPEND);
1128 if (status != QDF_STATUS_SUCCESS)
1129 return -EAGAIN;
Houston Hoffman7260ecb2015-10-05 18:43:07 -07001130
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001131 hdd_ctx->hdd_wlan_suspended = true;
Abhishek Singhbaea27d2016-04-27 13:29:30 +05301132 hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_SUSPEND);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001133
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301134 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135}
1136
1137/**
1138 * hdd_resume_wlan() - Driver resume function
1139 *
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301140 * Return: 0 on success else error code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 */
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301142static int hdd_resume_wlan(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001143{
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001144 struct hdd_context *hdd_ctx;
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001145 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301147 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148
Dustin Brown2d228232016-09-22 15:06:19 -07001149 hdd_info("WLAN being resumed by OS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001150
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001151 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1152 if (!hdd_ctx) {
Dustin Brown2d228232016-09-22 15:06:19 -07001153 hdd_err("HDD context is Null");
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301154 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001155 }
1156
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301157 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001158 hdd_info("Recovery in Progress. State: 0x%x Ignore resume!!!",
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001159 cds_get_driver_state());
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301160 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 }
1162
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001163 hdd_ctx->hdd_wlan_suspended = false;
Abhishek Singhbaea27d2016-04-27 13:29:30 +05301164 hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_RESUME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001165
1166 /*loop through all adapters. Concurrency */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001167 status = hdd_get_front_adapter(hdd_ctx, &pAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001168
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301169 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001170 adapter = pAdapterNode->adapter;
Jeff Johnson1b780e42017-10-31 14:11:45 -07001171 if (wlan_hdd_validate_session_id(adapter->session_id)) {
1172 hdd_err("invalid session id: %d", adapter->session_id);
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301173 goto next_adapter;
1174 }
1175 /* Disable supported OffLoads */
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001176 hdd_disable_host_offloads(adapter, pmo_apps_resume);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001177
1178 /* wake the tx queues */
Dustin Brown2d228232016-09-22 15:06:19 -07001179 hdd_info("Enabling queues");
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001180 wlan_hdd_netif_queue_control(adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001181 WLAN_WAKE_ALL_NETIF_QUEUE,
1182 WLAN_CONTROL_PATH);
1183
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +05301184 if (adapter->device_mode == QDF_STA_MODE)
1185 status = hdd_disable_default_pkt_filters(adapter);
1186
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301187next_adapter:
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001188 status = hdd_get_next_adapter(hdd_ctx, pAdapterNode, &pNext);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001189 pAdapterNode = pNext;
1190 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001191 hdd_ipa_resume(hdd_ctx);
1192 status = pmo_ucfg_psoc_user_space_resume_req(hdd_ctx->hdd_psoc,
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301193 QDF_SYSTEM_SUSPEND);
1194 if (status != QDF_STATUS_SUCCESS)
1195 return -EAGAIN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301197 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001198}
1199
1200/**
Komal Seelam78ff65a2016-08-18 15:25:24 +05301201 * hdd_svc_fw_shutdown_ind() - API to send FW SHUTDOWN IND to Userspace
1202 *
1203 * @dev: Device Pointer
1204 *
1205 * Return: None
1206 */
1207void hdd_svc_fw_shutdown_ind(struct device *dev)
1208{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001209 struct hdd_context *hdd_ctx;
Komal Seelam78ff65a2016-08-18 15:25:24 +05301210
1211 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1212
1213 hdd_ctx ? wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
1214 WLAN_SVC_FW_SHUTDOWN_IND,
1215 NULL, 0) : 0;
1216}
1217
1218/**
Arun Khandavallicc544b32017-01-30 19:52:16 +05301219 * hdd_ssr_restart_sap() - restart sap on SSR
1220 * @hdd_ctx: hdd context
1221 *
1222 * Return: nothing
1223 */
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001224static void hdd_ssr_restart_sap(struct hdd_context *hdd_ctx)
Arun Khandavallicc544b32017-01-30 19:52:16 +05301225{
1226 QDF_STATUS status;
1227 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson75b737d2017-08-29 14:24:41 -07001228 struct hdd_adapter *adapter;
Arun Khandavallicc544b32017-01-30 19:52:16 +05301229
1230 ENTER();
1231
1232 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1233 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001234 adapter = adapter_node->adapter;
Arun Khandavallicc544b32017-01-30 19:52:16 +05301235 if (adapter && adapter->device_mode == QDF_SAP_MODE) {
Manikandan Mohan0a0ac952017-02-16 15:49:31 -08001236 if (test_bit(SOFTAP_INIT_DONE, &adapter->event_flags)) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001237 hdd_debug("Restart prev SAP session");
Manikandan Mohan0a0ac952017-02-16 15:49:31 -08001238 wlan_hdd_start_sap(adapter, true);
1239 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05301240 }
1241 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
1242 adapter_node = next;
1243 }
1244
1245 EXIT();
1246}
1247
1248/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 * hdd_wlan_shutdown() - HDD SSR shutdown function
1250 *
1251 * This function is called by the HIF to shutdown the driver during SSR.
1252 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301253 * Return: QDF_STATUS_SUCCESS if the driver was shut down,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254 * or an error status otherwise
1255 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301256QDF_STATUS hdd_wlan_shutdown(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001257{
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001258 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259 p_cds_sched_context cds_sched_context = NULL;
Manikandan Mohan8b4e2012017-03-22 11:15:55 -07001260 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001262 hdd_info("WLAN driver shutting down!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001263
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264 /* Get the HDD context. */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001265 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1266 if (!hdd_ctx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001267 hdd_err("HDD context is Null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301268 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 }
1270
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001271 policy_mgr_clear_concurrent_session_count(hdd_ctx->hdd_psoc);
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +05301272
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001273 hdd_debug("Invoking packetdump deregistration API");
Himanshu Agarwalf65bd4c2016-12-05 17:21:12 +05301274 wlan_deregister_txrx_packetdump();
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001275 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
1276 hdd_reset_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277
Poddar, Siddarth1ab0a3d2016-09-29 18:58:45 +05301278 /* Flush cached rx frame queue */
Manikandan Mohan8b4e2012017-03-22 11:15:55 -07001279 if (soc)
1280 cdp_flush_cache_rx_queue(soc);
Poddar, Siddarth1ab0a3d2016-09-29 18:58:45 +05301281
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301282 /* De-register the HDD callbacks */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001283 hdd_deregister_cb(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284
1285 cds_sched_context = get_cds_sched_ctxt();
1286
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001287 if (hdd_ctx->is_scheduler_suspended) {
Rajeev Kumar0b732952016-12-08 17:51:39 -08001288 scheduler_resume();
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001289 hdd_ctx->is_scheduler_suspended = false;
Jeff Johnson214671b2017-10-30 19:45:23 -07001290 hdd_ctx->is_wiphy_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291 }
1292#ifdef QCA_CONFIG_SMP
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001293 if (true == hdd_ctx->is_ol_rx_thread_suspended) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001294 complete(&cds_sched_context->ol_resume_rx_event);
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001295 hdd_ctx->is_ol_rx_thread_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 }
1297#endif
1298
Manikandan Mohan71844ea2017-07-05 21:51:08 -07001299 hdd_ipa_uc_ssr_deinit();
Nitesh Shah61c10d92016-10-19 19:29:15 +05301300
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001301 hdd_bus_bandwidth_destroy(hdd_ctx);
Prashanth Bhattaab004382016-10-11 16:08:11 -07001302
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001303 hdd_wlan_stop_modules(hdd_ctx, false);
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05301304
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001305 hdd_lpass_notify_stop(hdd_ctx);
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07001306
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001307 wlan_objmgr_print_ref_all_objects_per_psoc(hdd_ctx->hdd_psoc);
Yue Ma2be12872017-06-02 13:06:58 -07001308
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001309 hdd_info("WLAN driver shutdown complete");
Yue Ma2be12872017-06-02 13:06:58 -07001310
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301311 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312}
1313
Sen, Devendra154b3c42017-02-13 20:44:15 +05301314#ifdef FEATURE_WLAN_DIAG_SUPPORT
1315/**
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301316 * hdd_wlan_ssr_reinit_event()- send ssr reinit state
1317 *
1318 * This Function send send ssr reinit state diag event
1319 *
1320 * Return: void.
1321 */
Sen, Devendra154b3c42017-02-13 20:44:15 +05301322static void hdd_wlan_ssr_reinit_event(void)
1323{
1324 WLAN_HOST_DIAG_EVENT_DEF(ssr_reinit, struct host_event_wlan_ssr_reinit);
1325 qdf_mem_zero(&ssr_reinit, sizeof(ssr_reinit));
1326 ssr_reinit.status = SSR_SUB_SYSTEM_REINIT;
1327 WLAN_HOST_DIAG_EVENT_REPORT(&ssr_reinit,
1328 EVENT_WLAN_SSR_REINIT_SUBSYSTEM);
1329}
1330#else
1331static inline void hdd_wlan_ssr_reinit_event(void)
1332{
1333
1334}
1335#endif
1336
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337/**
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05301338 * hdd_send_default_scan_ies - send default scan ies to fw
1339 *
1340 * This function is used to send default scan ies to fw
1341 * in case of wlan re-init
1342 *
1343 * Return: void
1344 */
1345static void hdd_send_default_scan_ies(struct hdd_context *hdd_ctx)
1346{
1347 hdd_adapter_list_node_t *adapter_node, *next;
1348 struct hdd_adapter *adapter;
1349 QDF_STATUS status;
1350
1351 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1352 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001353 adapter = adapter_node->adapter;
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05301354 if (hdd_is_interface_up(adapter) &&
1355 (adapter->device_mode == QDF_STA_MODE ||
1356 adapter->device_mode == QDF_P2P_DEVICE_MODE)) {
1357 sme_set_default_scan_ie(hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001358 adapter->session_id,
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05301359 adapter->scan_info.default_scan_ies,
1360 adapter->scan_info.default_scan_ies_len);
1361 }
1362 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
1363 &next);
1364 adapter_node = next;
1365 }
1366}
1367
1368/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001369 * hdd_wlan_re_init() - HDD SSR re-init function
1370 *
1371 * This function is called by the HIF to re-initialize the driver after SSR.
1372 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301373 * Return: QDF_STATUS_SUCCESS if the driver was re-initialized,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 * or an error status otherwise
1375 */
Arun Khandavallifae92942016-08-01 13:31:08 +05301376QDF_STATUS hdd_wlan_re_init(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377{
Arun Khandavallifae92942016-08-01 13:31:08 +05301378
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001379 struct hdd_context *hdd_ctx = NULL;
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001380 struct hdd_adapter *adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05301381 int ret;
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301382 bool bug_on_reinit_failure = CFG_BUG_ON_REINIT_FAILURE_DEFAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383
1384 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
1385
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 /* Get the HDD context */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001387 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1388 if (!hdd_ctx) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001389 hdd_err("HDD context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 goto err_re_init;
1391 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001392 bug_on_reinit_failure = hdd_ctx->config->bug_on_reinit_failure;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001394 /* The driver should always be initialized in STA mode after SSR */
1395 hdd_set_conparam(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396 /* Try to get an adapter from mode ID */
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001397 adapter = hdd_get_adapter(hdd_ctx, QDF_STA_MODE);
1398 if (!adapter) {
1399 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
1400 if (!adapter) {
1401 adapter = hdd_get_adapter(hdd_ctx, QDF_IBSS_MODE);
1402 if (!adapter) {
1403 adapter = hdd_get_adapter(hdd_ctx,
1404 QDF_MONITOR_MODE);
1405 if (!adapter)
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001406 hdd_err("Failed to get Adapter!");
Arunk Khandavalli062fb032017-10-04 12:18:15 +05301407 }
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301408
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 }
1410 }
1411
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001412 if (hdd_ctx->config->enable_dp_trace)
1413 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05301414
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001415 hdd_bus_bandwidth_init(hdd_ctx);
Prashanth Bhattaab004382016-10-11 16:08:11 -07001416
Arun Khandavallicc544b32017-01-30 19:52:16 +05301417
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001418 ret = hdd_wlan_start_modules(hdd_ctx, adapter, true);
Arun Khandavallifae92942016-08-01 13:31:08 +05301419 if (ret) {
1420 hdd_err("Failed to start wlan after error");
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301421 goto err_re_init;
Arun Khandavallifae92942016-08-01 13:31:08 +05301422 }
1423
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001424 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001425
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001426 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Wu Gao36717432016-11-21 15:09:48 +08001427 WLAN_SVC_FW_CRASHED_IND, NULL, 0);
1428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429 /* Restart all adapters */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001430 hdd_start_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001432 hdd_ctx->last_scan_reject_session_id = 0xFF;
1433 hdd_ctx->last_scan_reject_reason = 0;
1434 hdd_ctx->last_scan_reject_timestamp = 0;
1435 hdd_ctx->scan_reject_cnt = 0;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05301436
Selvaraj, Sridhar1c487562017-04-19 14:29:07 +05301437 hdd_set_roaming_in_progress(false);
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001438 complete(&adapter->roaming_comp_var);
Jeff Johnson59b19312017-11-02 21:14:33 -07001439 hdd_ctx->bt_coex_mode_set = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 /* Allow the phone to go to sleep */
1442 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05301443 /* set chip power save failure detected callback */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001444 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05301445 hdd_chip_pwr_save_fail_detected_cb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001447 ret = hdd_register_cb(hdd_ctx);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301448 if (ret) {
1449 hdd_err("Failed to register HDD callbacks!");
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +05301450 goto err_cds_disable;
Arun Khandavalli4b55da72016-07-19 19:55:01 +05301451 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001452
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001453 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001454
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05301455 hdd_send_default_scan_ies(hdd_ctx);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001456 hdd_info("WLAN host driver reinitiation completed!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001457 goto success;
1458
1459err_cds_disable:
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001460 hdd_wlan_stop_modules(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001462err_re_init:
1463 /* Allow the phone to go to sleep */
1464 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT);
Mukul Sharmaf7d62e12016-09-03 15:16:22 +05301465 if (bug_on_reinit_failure)
1466 QDF_BUG(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001467 return -EPERM;
1468
1469success:
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001470 if (hdd_ctx->config->sap_internal_restart)
1471 hdd_ssr_restart_sap(hdd_ctx);
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301472
Sen, Devendra154b3c42017-02-13 20:44:15 +05301473 hdd_wlan_ssr_reinit_event();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301474 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001475}
1476
Jeff Johnson75b737d2017-08-29 14:24:41 -07001477int wlan_hdd_set_powersave(struct hdd_adapter *adapter,
Dustin Brownf660fb42016-09-09 12:04:00 -07001478 bool allow_power_save, uint32_t timeout)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001479{
1480 tHalHandle hal;
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001481 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001482
1483 if (NULL == adapter) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001484 hdd_err("Adapter NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485 return -ENODEV;
1486 }
1487
1488 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1489 if (!hdd_ctx) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001490 hdd_err("hdd context is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491 return -EINVAL;
1492 }
1493
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001494 hdd_debug("Allow power save: %d", allow_power_save);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001495 hal = WLAN_HDD_GET_HAL_CTX(adapter);
1496
Dustin Brown84411b02017-07-21 16:44:44 -07001497 /*
1498 * This is a workaround for defective AP's that send a disassoc
1499 * immediately after WPS connection completes. Defer powersave by a
1500 * small amount if the affected AP is detected.
1501 */
1502 if (allow_power_save &&
1503 adapter->device_mode == QDF_STA_MODE &&
Jeff Johnsonb9424862017-10-30 08:49:35 -07001504 !adapter->session.station.ap_supports_immediate_power_save) {
Dustin Brown84411b02017-07-21 16:44:44 -07001505 timeout = AUTO_PS_DEFER_TIMEOUT_MS;
1506 hdd_debug("Defer power-save due to AP spec non-conformance");
Krunal Soni364e0872017-05-10 21:24:34 -07001507 }
1508
Dustin Brownf660fb42016-09-09 12:04:00 -07001509 if (allow_power_save) {
1510 if (QDF_STA_MODE == adapter->device_mode ||
1511 QDF_P2P_CLIENT_MODE == adapter->device_mode) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001512 hdd_debug("Disabling Auto Power save timer");
Dustin Brownf660fb42016-09-09 12:04:00 -07001513 sme_ps_disable_auto_ps_timer(
1514 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07001515 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518 if (hdd_ctx->config && hdd_ctx->config->is_ps_enabled) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001519 hdd_debug("Wlan driver Entering Power save");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520
1521 /*
1522 * Enter Power Save command received from GUI
1523 * this means DHCP is completed
1524 */
Yeshwanth Sriram Guntukaae03c432017-11-12 13:31:02 +05301525 if (timeout)
1526 sme_ps_enable_auto_ps_timer(hal,
1527 adapter->session_id,
1528 timeout);
1529 else
1530 sme_ps_enable_disable(hal, adapter->session_id,
1531 SME_PS_ENABLE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 } else {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001533 hdd_debug("Power Save is not enabled in the cfg");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001534 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001535 } else {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001536 hdd_debug("Wlan driver Entering Full Power");
Dustin Brownf660fb42016-09-09 12:04:00 -07001537
1538 /*
1539 * Enter Full power command received from GUI
1540 * this means we are disconnected
1541 */
1542 sme_ps_disable_auto_ps_timer(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07001543 adapter->session_id);
1544 sme_ps_enable_disable(hal, adapter->session_id, SME_PS_DISABLE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545 }
Dustin Brownf660fb42016-09-09 12:04:00 -07001546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547 return 0;
1548}
1549
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001550static void wlan_hdd_print_suspend_fail_stats(struct hdd_context *hdd_ctx)
Dustin Brown105d7902016-10-03 16:27:59 -07001551{
Dustin Brownd9322482017-01-09 12:46:03 -08001552 struct suspend_resume_stats *stats = &hdd_ctx->suspend_resume_stats;
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05301553
Dustin Brown105d7902016-10-03 16:27:59 -07001554 hdd_err("ipa:%d, radar:%d, roam:%d, scan:%d, initial_wakeup:%d",
Dustin Brownd9322482017-01-09 12:46:03 -08001555 stats->suspend_fail[SUSPEND_FAIL_IPA],
1556 stats->suspend_fail[SUSPEND_FAIL_RADAR],
1557 stats->suspend_fail[SUSPEND_FAIL_ROAM],
1558 stats->suspend_fail[SUSPEND_FAIL_SCAN],
1559 stats->suspend_fail[SUSPEND_FAIL_INITIAL_WAKEUP]);
Dustin Brown105d7902016-10-03 16:27:59 -07001560}
1561
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001562void wlan_hdd_inc_suspend_stats(struct hdd_context *hdd_ctx,
Dustin Brown105d7902016-10-03 16:27:59 -07001563 enum suspend_fail_reason reason)
1564{
1565 wlan_hdd_print_suspend_fail_stats(hdd_ctx);
Dustin Brownd9322482017-01-09 12:46:03 -08001566 hdd_ctx->suspend_resume_stats.suspend_fail[reason]++;
Dustin Brown105d7902016-10-03 16:27:59 -07001567 wlan_hdd_print_suspend_fail_stats(hdd_ctx);
1568}
1569
Dustin Brown5fbb1052017-08-11 17:25:51 -07001570#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
1571static inline void
1572hdd_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
1573{
1574 cfg80211_sched_scan_results(wiphy);
1575}
1576#else
1577static inline void
1578hdd_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
1579{
1580 cfg80211_sched_scan_results(wiphy, reqid);
1581}
1582#endif
1583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584/**
1585 * __wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback
1586 * @wiphy: Pointer to wiphy
1587 *
1588 * This API is called when cfg80211 driver resumes driver updates
1589 * latest sched_scan scan result(if any) to cfg80211 database
1590 *
1591 * Return: integer status
1592 */
1593static int __wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
1594{
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001595 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301596 QDF_STATUS status = QDF_STATUS_SUCCESS;
Dustin Brownd9322482017-01-09 12:46:03 -08001597 int exit_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598 p_cds_sched_context cds_sched_context = get_cds_sched_ctxt();
1599
1600 ENTER();
1601
Dustin Brownd9322482017-01-09 12:46:03 -08001602 if (cds_is_driver_recovering()) {
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001603 hdd_debug("Driver is recovering; Skipping resume");
Dustin Brownd9322482017-01-09 12:46:03 -08001604 exit_code = 0;
1605 goto exit_with_code;
1606 }
Prashanth Bhatta697dd0c2016-10-20 18:42:41 -07001607
Anurag Chouhan6d760662016-02-20 16:05:43 +05301608 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001609 hdd_err("Command not allowed in FTM mode");
Dustin Brownd9322482017-01-09 12:46:03 -08001610 exit_code = -EINVAL;
1611 goto exit_with_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 }
1613
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001614 exit_code = wlan_hdd_validate_context(hdd_ctx);
Dustin Brownd9322482017-01-09 12:46:03 -08001615 if (exit_code) {
1616 hdd_err("Invalid HDD context");
1617 goto exit_with_code;
1618 }
Arun Khandavallifae92942016-08-01 13:31:08 +05301619
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001620 mutex_lock(&hdd_ctx->iface_change_lock);
1621 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1622 mutex_unlock(&hdd_ctx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001623 hdd_debug("Driver is not enabled; Skipping resume");
Dustin Brownd9322482017-01-09 12:46:03 -08001624 exit_code = 0;
1625 goto exit_with_code;
Arun Khandavallifae92942016-08-01 13:31:08 +05301626 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001627 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brownd9322482017-01-09 12:46:03 -08001628
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001629 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_MEDIUM);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301631 status = hdd_resume_wlan();
1632 if (status != QDF_STATUS_SUCCESS) {
1633 exit_code = 0;
1634 goto exit_with_code;
1635 }
Rajeev Kumareada0d02016-12-08 17:44:17 -08001636 /* Resume control path scheduler */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001637 if (hdd_ctx->is_scheduler_suspended) {
Rajeev Kumar0b732952016-12-08 17:51:39 -08001638 scheduler_resume();
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001639 hdd_ctx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001640 }
1641#ifdef QCA_CONFIG_SMP
1642 /* Resume tlshim Rx thread */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001643 if (hdd_ctx->is_ol_rx_thread_suspended) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644 complete(&cds_sched_context->ol_resume_rx_event);
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001645 hdd_ctx->is_ol_rx_thread_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646 }
1647#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301649 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05301650 TRACE_CODE_HDD_CFG80211_RESUME_WLAN,
Jeff Johnson214671b2017-10-30 19:45:23 -07001651 NO_SESSION, hdd_ctx->is_wiphy_suspended));
Jeff Johnson214671b2017-10-30 19:45:23 -07001652 hdd_ctx->is_wiphy_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001654 hdd_ctx->suspend_resume_stats.resumes++;
Dustin Brownd9322482017-01-09 12:46:03 -08001655 exit_code = 0;
1656
1657exit_with_code:
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301658 EXIT();
Dustin Brownd9322482017-01-09 12:46:03 -08001659 return exit_code;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001660}
1661
1662/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 * wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback
1664 * @wiphy: Pointer to wiphy
1665 *
1666 * This API is called when cfg80211 driver resumes driver updates
1667 * latest sched_scan scan result(if any) to cfg80211 database
1668 *
1669 * Return: integer status
1670 */
1671int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
1672{
1673 int ret;
1674
1675 cds_ssr_protect(__func__);
1676 ret = __wlan_hdd_cfg80211_resume_wlan(wiphy);
1677 cds_ssr_unprotect(__func__);
1678
1679 return ret;
1680}
1681
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001682static void hdd_suspend_cb(void)
1683{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001684 struct hdd_context *hdd_ctx;
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001685
1686 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1687 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001688 hdd_err("HDD context is NULL");
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001689 return;
1690 }
1691
1692 complete(&hdd_ctx->mc_sus_event_var);
1693}
1694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695/**
1696 * __wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback
1697 * @wiphy: Pointer to wiphy
1698 * @wow: Pointer to wow
1699 *
1700 * This API is called when cfg80211 driver suspends
1701 *
1702 * Return: integer status
1703 */
1704static int __wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
1705 struct cfg80211_wowlan *wow)
1706{
1707#ifdef QCA_CONFIG_SMP
1708#define RX_TLSHIM_SUSPEND_TIMEOUT 200 /* msecs */
1709#endif
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001710 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711 p_cds_sched_context cds_sched_context = get_cds_sched_ctxt();
1712 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001713 struct hdd_adapter *adapter;
Jeff Johnson5287de52017-10-28 12:23:06 -07001714 struct hdd_scan_info *scan_info;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301715 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716 int rc;
1717
1718 ENTER();
1719
Anurag Chouhan6d760662016-02-20 16:05:43 +05301720 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001721 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722 return -EINVAL;
1723 }
1724
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001725 rc = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301726 if (0 != rc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001727 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001728
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001729 mutex_lock(&hdd_ctx->iface_change_lock);
1730 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1731 mutex_unlock(&hdd_ctx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001732 hdd_debug("Driver Modules not Enabled ");
Arun Khandavallifae92942016-08-01 13:31:08 +05301733 return 0;
1734 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001735 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05301736
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001737 /* If RADAR detection is in progress (HDD), prevent suspend. The flag
1738 * "dfs_cac_block_tx" is set to true when RADAR is found and stay true
1739 * until CAC is done for a SoftAP which is in started state.
1740 */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001741 status = hdd_get_front_adapter(hdd_ctx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301742 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001743 adapter = pAdapterNode->adapter;
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301744
Jeff Johnson1b780e42017-10-31 14:11:45 -07001745 if (wlan_hdd_validate_session_id(adapter->session_id)) {
1746 hdd_err("invalid session id: %d", adapter->session_id);
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301747 goto next_adapter;
1748 }
1749
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001750 if (QDF_SAP_MODE == adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001751 if (BSS_START ==
Jeff Johnson0f9f87b2017-10-28 09:21:06 -07001752 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter)->bss_state &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753 true ==
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001754 WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755 dfs_cac_block_tx) {
Dustin Brown2d228232016-09-22 15:06:19 -07001756 hdd_err("RADAR detection in progress, do not allow suspend");
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001757 wlan_hdd_inc_suspend_stats(hdd_ctx,
Dustin Brown105d7902016-10-03 16:27:59 -07001758 SUSPEND_FAIL_RADAR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001759 return -EAGAIN;
Jeff Johnson60cbd2d2017-11-03 18:26:28 -07001760 } else if (!hdd_ctx->config->enable_sap_suspend) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761 /* return -EOPNOTSUPP if SAP does not support
1762 * suspend
1763 */
Jeff Johnsonc3273322016-07-06 15:28:17 -07001764 hdd_err("SAP does not support suspend!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001765 return -EOPNOTSUPP;
1766 }
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001767 } else if (QDF_P2P_GO_MODE == adapter->device_mode) {
Jeff Johnson60cbd2d2017-11-03 18:26:28 -07001768 if (!hdd_ctx->config->enable_sap_suspend) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769 /* return -EOPNOTSUPP if GO does not support
1770 * suspend
1771 */
Jeff Johnsonc3273322016-07-06 15:28:17 -07001772 hdd_err("GO does not support suspend!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773 return -EOPNOTSUPP;
1774 }
1775 }
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301776next_adapter:
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001777 status = hdd_get_next_adapter(hdd_ctx, pAdapterNode, &pNext);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001778 pAdapterNode = pNext;
1779 }
1780
1781 /* Stop ongoing scan on each interface */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001782 status = hdd_get_front_adapter(hdd_ctx, &pAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301783 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001784 adapter = pAdapterNode->adapter;
Jeff Johnson5287de52017-10-28 12:23:06 -07001785 scan_info = &adapter->scan_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786
Sandeep Puligillaf8527122016-11-16 18:35:16 -08001787 if (sme_neighbor_middle_of_roaming
Jeff Johnson1b780e42017-10-31 14:11:45 -07001788 (hdd_ctx->hHal, adapter->session_id)) {
Dustin Brown2d228232016-09-22 15:06:19 -07001789 hdd_err("Roaming in progress, do not allow suspend");
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001790 wlan_hdd_inc_suspend_stats(hdd_ctx,
Dustin Brown105d7902016-10-03 16:27:59 -07001791 SUSPEND_FAIL_ROAM);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001792 return -EAGAIN;
1793 }
1794
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001795 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001796 adapter->session_id, INVALID_SCAN_ID, false);
Dustin Brownc86d5362017-07-07 13:08:51 -07001797
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001798 status = hdd_get_next_adapter(hdd_ctx, pAdapterNode, &pNext);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001799 pAdapterNode = pNext;
1800 }
1801
Dustin Brown84411b02017-07-21 16:44:44 -07001802 /* flush any pending powersave timers */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001803 status = hdd_get_front_adapter(hdd_ctx, &pAdapterNode);
Dustin Brown84411b02017-07-21 16:44:44 -07001804 while (pAdapterNode && QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001805 adapter = pAdapterNode->adapter;
Dustin Brown84411b02017-07-21 16:44:44 -07001806
Jeff Johnson1b780e42017-10-31 14:11:45 -07001807 sme_ps_timer_flush_sync(hdd_ctx->hHal, adapter->session_id);
Dustin Brown84411b02017-07-21 16:44:44 -07001808
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001809 status = hdd_get_next_adapter(hdd_ctx, pAdapterNode,
Dustin Brown84411b02017-07-21 16:44:44 -07001810 &pAdapterNode);
1811 }
1812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001813 /*
1814 * Suspend IPA early before proceeding to suspend other entities like
1815 * firmware to avoid any race conditions.
1816 */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001817 if (hdd_ipa_suspend(hdd_ctx)) {
Dustin Brown2d228232016-09-22 15:06:19 -07001818 hdd_err("IPA not ready to suspend!");
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001819 wlan_hdd_inc_suspend_stats(hdd_ctx, SUSPEND_FAIL_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001820 return -EAGAIN;
1821 }
1822
Rajeev Kumareada0d02016-12-08 17:44:17 -08001823 /* Suspend control path scheduler */
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001824 scheduler_register_hdd_suspend_callback(hdd_suspend_cb);
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301825 scheduler_set_event_mask(MC_SUSPEND_EVENT);
Krunal Sonid32c6bc2016-10-18 18:00:21 -07001826 scheduler_wake_up_controller_thread();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001827
Rajeev Kumareada0d02016-12-08 17:44:17 -08001828 /* Wait for suspend confirmation from scheduler */
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001829 rc = wait_for_completion_timeout(&hdd_ctx->mc_sus_event_var,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830 msecs_to_jiffies(WLAN_WAIT_TIME_MCTHREAD_SUSPEND));
1831 if (!rc) {
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301832 scheduler_clear_event_mask(MC_SUSPEND_EVENT);
Jeff Johnsonc3273322016-07-06 15:28:17 -07001833 hdd_err("Failed to stop mc thread");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 goto resume_tx;
1835 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001836 hdd_ctx->is_scheduler_suspended = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001837
1838#ifdef QCA_CONFIG_SMP
1839 /* Suspend tlshim rx thread */
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301840 set_bit(RX_SUSPEND_EVENT, &cds_sched_context->ol_rx_event_flag);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841 wake_up_interruptible(&cds_sched_context->ol_rx_wait_queue);
1842 rc = wait_for_completion_timeout(&cds_sched_context->
1843 ol_suspend_rx_event,
1844 msecs_to_jiffies
1845 (RX_TLSHIM_SUSPEND_TIMEOUT));
1846 if (!rc) {
Manjeet Singh1a376ce2016-10-06 19:31:10 +05301847 clear_bit(RX_SUSPEND_EVENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848 &cds_sched_context->ol_rx_event_flag);
Jeff Johnsonc3273322016-07-06 15:28:17 -07001849 hdd_err("Failed to stop tl_shim rx thread");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850 goto resume_all;
1851 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001852 hdd_ctx->is_ol_rx_thread_suspended = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853#endif
Mukul Sharma4c60a7e2017-03-06 19:42:18 +05301854 if (hdd_suspend_wlan() < 0)
1855 goto resume_all;
1856
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301857 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05301858 TRACE_CODE_HDD_CFG80211_SUSPEND_WLAN,
Jeff Johnson214671b2017-10-30 19:45:23 -07001859 NO_SESSION, hdd_ctx->is_wiphy_suspended));
1860 hdd_ctx->is_wiphy_suspended = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001861
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001862 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863
1864 EXIT();
1865 return 0;
1866
1867#ifdef QCA_CONFIG_SMP
1868resume_all:
1869
Rajeev Kumar0b732952016-12-08 17:51:39 -08001870 scheduler_resume();
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001871 hdd_ctx->is_scheduler_suspended = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001872#endif
1873
1874resume_tx:
1875
1876 hdd_resume_wlan();
1877 return -ETIME;
1878
1879}
1880
1881/**
1882 * wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback
1883 * @wiphy: Pointer to wiphy
1884 * @wow: Pointer to wow
1885 *
1886 * This API is called when cfg80211 driver suspends
1887 *
1888 * Return: integer status
1889 */
1890int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
1891 struct cfg80211_wowlan *wow)
1892{
1893 int ret;
1894
1895 cds_ssr_protect(__func__);
1896 ret = __wlan_hdd_cfg80211_suspend_wlan(wiphy, wow);
1897 cds_ssr_unprotect(__func__);
1898
1899 return ret;
1900}
1901
1902/**
Komal Seelama89be8d2016-09-29 11:09:26 +05301903 * hdd_stop_dhcp_ind() - API to stop DHCP sequence
1904 * @adapter: Adapter on which DHCP needs to be stopped
1905 *
1906 * Release the wakelock held for DHCP process and allow
1907 * the runtime pm to continue
1908 *
1909 * Return: None
1910 */
Jeff Johnson75b737d2017-08-29 14:24:41 -07001911static void hdd_stop_dhcp_ind(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05301912{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001913 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05301914
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08001915 hdd_debug("DHCP stop indicated through power save");
Komal Seelama89be8d2016-09-29 11:09:26 +05301916 sme_dhcp_stop_ind(hdd_ctx->hHal, adapter->device_mode,
Jeff Johnson1e851a12017-10-28 14:36:12 -07001917 adapter->mac_addr.bytes,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001918 adapter->session_id);
Komal Seelama89be8d2016-09-29 11:09:26 +05301919 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DHCP);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08001920 qdf_runtime_pm_allow_suspend(&adapter->connect_rpm_ctx.connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05301921}
1922
1923/**
1924 * hdd_start_dhcp_ind() - API to start DHCP sequence
1925 * @adapter: Adapter on which DHCP needs to be stopped
1926 *
1927 * Prevent APPS suspend and the runtime suspend during
1928 * DHCP sequence
1929 *
1930 * Return: None
1931 */
Jeff Johnson75b737d2017-08-29 14:24:41 -07001932static void hdd_start_dhcp_ind(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05301933{
Jeff Johnsoncfb65a82017-08-28 11:45:41 -07001934 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05301935
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001936 hdd_debug("DHCP start indicated through power save");
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08001937 qdf_runtime_pm_prevent_suspend(&adapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07001938 hdd_prevent_suspend_timeout(HDD_WAKELOCK_TIMEOUT_CONNECT,
1939 WIFI_POWER_EVENT_WAKELOCK_DHCP);
Komal Seelama89be8d2016-09-29 11:09:26 +05301940 sme_dhcp_start_ind(hdd_ctx->hHal, adapter->device_mode,
Jeff Johnson1e851a12017-10-28 14:36:12 -07001941 adapter->mac_addr.bytes,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001942 adapter->session_id);
Komal Seelama89be8d2016-09-29 11:09:26 +05301943}
1944
1945/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946 * __wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config
1947 * @wiphy: Pointer to wiphy
1948 * @dev: Pointer to network device
Dustin Brownf660fb42016-09-09 12:04:00 -07001949 * @allow_power_save: is wlan allowed to go into power save mode
1950 * @timeout: Timeout value in ms
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001951 *
1952 * Return: 0 for success, non-zero for failure
1953 */
1954static int __wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Dustin Brownf660fb42016-09-09 12:04:00 -07001955 struct net_device *dev,
1956 bool allow_power_save,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 int timeout)
1958{
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001959 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001960 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961 int status;
1962
Dustin Brownecfce632016-09-13 10:41:45 -07001963 ENTER();
1964
Dustin Brownf660fb42016-09-09 12:04:00 -07001965 if (timeout < 0) {
Yeshwanth Sriram Guntukaae03c432017-11-12 13:31:02 +05301966 hdd_debug("User space timeout: %d; Enter full power or power save",
1967 timeout);
1968 timeout = 0;
Dustin Brownf660fb42016-09-09 12:04:00 -07001969 }
1970
Anurag Chouhan6d760662016-02-20 16:05:43 +05301971 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07001972 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001973 return -EINVAL;
1974 }
1975
Jeff Johnson1b780e42017-10-31 14:11:45 -07001976 if (wlan_hdd_validate_session_id(adapter->session_id)) {
1977 hdd_err("invalid session id: %d", adapter->session_id);
Hanumanth Reddy Pothulad9491f42016-10-24 19:08:38 +05301978 return -EINVAL;
1979 }
1980
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301981 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001982 TRACE_CODE_HDD_CFG80211_SET_POWER_MGMT,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001983 adapter->session_id, timeout));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001984
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001985 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001986 status = wlan_hdd_validate_context(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001987
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05301988 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001990
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001991 mutex_lock(&hdd_ctx->iface_change_lock);
1992 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1993 mutex_unlock(&hdd_ctx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08001994 hdd_debug("Driver Module not enabled return success");
Arun Khandavalli99286452016-08-22 12:13:41 +05301995 return 0;
1996 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07001997 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavalli99286452016-08-22 12:13:41 +05301998
Jeff Johnsonf6d24282017-10-02 13:25:25 -07001999 status = wlan_hdd_set_powersave(adapter, allow_power_save, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002000
Jeff Johnsonf6d24282017-10-02 13:25:25 -07002001 allow_power_save ? hdd_stop_dhcp_ind(adapter) :
2002 hdd_start_dhcp_ind(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003
2004 EXIT();
2005 return status;
2006}
2007
2008/**
2009 * wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config
2010 * @wiphy: Pointer to wiphy
2011 * @dev: Pointer to network device
Dustin Brownf660fb42016-09-09 12:04:00 -07002012 * @allow_power_save: is wlan allowed to go into power save mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002013 * @timeout: Timeout value
2014 *
2015 * Return: 0 for success, non-zero for failure
2016 */
2017int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Dustin Brownf660fb42016-09-09 12:04:00 -07002018 struct net_device *dev,
2019 bool allow_power_save,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020 int timeout)
2021{
2022 int ret;
2023
2024 cds_ssr_protect(__func__);
Dustin Brownf660fb42016-09-09 12:04:00 -07002025 ret = __wlan_hdd_cfg80211_set_power_mgmt(wiphy, dev,
2026 allow_power_save, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002027 cds_ssr_unprotect(__func__);
2028
2029 return ret;
2030}
2031
2032/**
2033 * __wlan_hdd_cfg80211_set_txpower() - set TX power
2034 * @wiphy: Pointer to wiphy
2035 * @wdev: Pointer to network device
2036 * @type: TX power setting type
2037 * @dbm: TX power in dbm
2038 *
2039 * Return: 0 for success, non-zero for failure
2040 */
2041static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002043 enum nl80211_tx_power_setting type,
2044 int dbm)
2045{
Jeff Johnson1a9b9792017-09-03 09:22:08 -07002046 struct hdd_context *hdd_ctx = (struct hdd_context *) wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002047 tHalHandle hHal = NULL;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302048 struct qdf_mac_addr bssid = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
2049 struct qdf_mac_addr selfMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002050 int status;
2051
2052 ENTER();
2053
Anurag Chouhan6d760662016-02-20 16:05:43 +05302054 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002055 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002056 return -EINVAL;
2057 }
2058
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302059 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002060 TRACE_CODE_HDD_CFG80211_SET_TXPOWER,
2061 NO_SESSION, type));
2062
Jeff Johnson1a9b9792017-09-03 09:22:08 -07002063 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302064 if (0 != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066
Jeff Johnson1a9b9792017-09-03 09:22:08 -07002067 hHal = hdd_ctx->hHal;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068
2069 if (0 != sme_cfg_set_int(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL, dbm)) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002070 hdd_err("sme_cfg_set_int failed for tx power %hu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002071 dbm);
2072 return -EIO;
2073 }
2074
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002075 hdd_debug("Set tx power level %d dbm", dbm);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002076
2077 switch (type) {
2078 /* Automatically determine transmit power */
2079 case NL80211_TX_POWER_AUTOMATIC:
2080 /* Fall through */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05302081 case NL80211_TX_POWER_LIMITED:
2082 /* Limit TX power by the mBm parameter */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002083 if (sme_set_max_tx_power(hHal, bssid, selfMac, dbm) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302084 QDF_STATUS_SUCCESS) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002085 hdd_err("Setting maximum tx power failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002086 return -EIO;
2087 }
2088 break;
2089
2090 case NL80211_TX_POWER_FIXED: /* Fix TX power to the mBm parameter */
Jeff Johnsonc3273322016-07-06 15:28:17 -07002091 hdd_err("NL80211_TX_POWER_FIXED not supported");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002092 return -EOPNOTSUPP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002093
2094 default:
Jeff Johnsonc3273322016-07-06 15:28:17 -07002095 hdd_err("Invalid power setting type %d", type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002096 return -EIO;
2097 }
2098
2099 EXIT();
2100 return 0;
2101}
2102
2103/**
2104 * wlan_hdd_cfg80211_set_txpower() - set TX power
2105 * @wiphy: Pointer to wiphy
2106 * @wdev: Pointer to network device
2107 * @type: TX power setting type
2108 * @dbm: TX power in dbm
2109 *
2110 * Return: 0 for success, non-zero for failure
2111 */
2112int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002113 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114 enum nl80211_tx_power_setting type,
2115 int dbm)
2116{
2117 int ret;
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +05302118
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119 cds_ssr_protect(__func__);
2120 ret = __wlan_hdd_cfg80211_set_txpower(wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121 wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002122 type, dbm);
2123 cds_ssr_unprotect(__func__);
2124
2125 return ret;
2126}
2127
2128/**
2129 * __wlan_hdd_cfg80211_get_txpower() - get TX power
2130 * @wiphy: Pointer to wiphy
2131 * @wdev: Pointer to network device
2132 * @dbm: Pointer to TX power in dbm
2133 *
2134 * Return: 0 for success, non-zero for failure
2135 */
2136static int __wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002137 struct wireless_dev *wdev,
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002138 int *dbm)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139{
2140
Jeff Johnson1a9b9792017-09-03 09:22:08 -07002141 struct hdd_context *hdd_ctx = (struct hdd_context *) wiphy_priv(wiphy);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002142 struct net_device *ndev = wdev->netdev;
Jeff Johnson75b737d2017-08-29 14:24:41 -07002143 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002144 int status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002145 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002146
2147 ENTER();
2148
Anurag Chouhan6d760662016-02-20 16:05:43 +05302149 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Jeff Johnsonc3273322016-07-06 15:28:17 -07002150 hdd_err("Command not allowed in FTM mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151 return -EINVAL;
2152 }
2153
Jeff Johnson1a9b9792017-09-03 09:22:08 -07002154 status = wlan_hdd_validate_context(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002155 if (0 != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002156 *dbm = 0;
2157 return status;
2158 }
2159
Arun Khandavalli99286452016-08-22 12:13:41 +05302160 /* Validate adapter sessionId */
Jeff Johnson1b780e42017-10-31 14:11:45 -07002161 if (wlan_hdd_validate_session_id(adapter->session_id)) {
2162 hdd_err("invalid session id: %d", adapter->session_id);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002163 return -EINVAL;
Arun Khandavalli99286452016-08-22 12:13:41 +05302164 }
2165
Jeff Johnson1a9b9792017-09-03 09:22:08 -07002166 mutex_lock(&hdd_ctx->iface_change_lock);
2167 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
2168 mutex_unlock(&hdd_ctx->iface_change_lock);
Srinivas Girigowda5d6bde62017-03-06 18:26:02 -08002169 hdd_debug("Driver Module not enabled return success");
Arun Khandavalli99286452016-08-22 12:13:41 +05302170 /* Send cached data to upperlayer*/
Jeff Johnson861dd4f2017-10-24 10:10:40 -07002171 *dbm = adapter->hdd_stats.class_a_stat.max_pwr;
Arun Khandavalli99286452016-08-22 12:13:41 +05302172 return 0;
2173 }
Jeff Johnson1a9b9792017-09-03 09:22:08 -07002174 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavalli99286452016-08-22 12:13:41 +05302175
Ganesh Kondabattinif847f062017-05-26 12:36:24 +05302176 if (sta_ctx->conn_info.connState != eConnectionState_Associated) {
2177 hdd_debug("Not associated");
2178 /*To keep GUI happy */
2179 *dbm = 0;
2180 return 0;
2181 }
2182
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302183 MTRACE(qdf_trace(QDF_MODULE_ID_HDD,
Sreelakshmi Konamki6744cff2015-09-07 12:10:39 +05302184 TRACE_CODE_HDD_CFG80211_GET_TXPOWER,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002185 adapter->session_id, adapter->device_mode));
Arun Khandavalli99286452016-08-22 12:13:41 +05302186 wlan_hdd_get_class_astats(adapter);
Jeff Johnson861dd4f2017-10-24 10:10:40 -07002187 *dbm = adapter->hdd_stats.class_a_stat.max_pwr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188
2189 EXIT();
2190 return 0;
2191}
2192
2193/**
2194 * wlan_hdd_cfg80211_get_txpower() - cfg80211 get power handler function
2195 * @wiphy: Pointer to wiphy structure.
2196 * @wdev: Pointer to wireless_dev structure.
2197 * @dbm: dbm
2198 *
2199 * This is the cfg80211 get txpower handler function which invokes
2200 * the internal function @__wlan_hdd_cfg80211_get_txpower with
2201 * SSR protection.
2202 *
2203 * Return: 0 for success, error number on failure.
2204 */
2205int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002206 struct wireless_dev *wdev,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002207 int *dbm)
2208{
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002209 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002210
2211 cds_ssr_protect(__func__);
Srinivas Girigowda5557a392017-03-09 14:28:36 -08002212 ret = __wlan_hdd_cfg80211_get_txpower(wiphy, wdev, dbm);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002213 cds_ssr_unprotect(__func__);
2214
2215 return ret;
2216}
Kapil Gupta6213c012016-09-02 19:39:09 +05302217
Jeff Johnson4fbee2f2017-10-03 11:19:35 -07002218int hdd_set_qpower_config(struct hdd_context *hddctx,
2219 struct hdd_adapter *adapter,
Dustin Brown10a7b712016-10-07 10:31:16 -07002220 u8 qpower)
Kapil Gupta6213c012016-09-02 19:39:09 +05302221{
Dustin Brown10a7b712016-10-07 10:31:16 -07002222 QDF_STATUS status;
Kapil Gupta6213c012016-09-02 19:39:09 +05302223
2224 if (!hddctx->config->enablePowersaveOffload) {
2225 hdd_err("qpower is disabled in configuration");
2226 return -EINVAL;
2227 }
Manjeet Singh91b7bb82017-02-10 18:35:40 +05302228 if (adapter->device_mode != QDF_STA_MODE &&
2229 adapter->device_mode != QDF_P2P_CLIENT_MODE) {
2230 hdd_info(FL("QPOWER only allowed in STA/P2P-Client modes:%d "),
2231 adapter->device_mode);
2232 return -EINVAL;
2233 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002234
Kapil Gupta6213c012016-09-02 19:39:09 +05302235 if (qpower > PS_DUTY_CYCLING_QPOWER ||
2236 qpower < PS_LEGACY_NODEEPSLEEP) {
Dustin Brown10a7b712016-10-07 10:31:16 -07002237 hdd_err("invalid qpower value: %d", qpower);
Kapil Gupta6213c012016-09-02 19:39:09 +05302238 return -EINVAL;
2239 }
Kapil Gupta6213c012016-09-02 19:39:09 +05302240
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08002241 if (hddctx->config->nMaxPsPoll) {
2242 if ((qpower == PS_QPOWER_NODEEPSLEEP) ||
2243 (qpower == PS_LEGACY_NODEEPSLEEP))
2244 qpower = PS_LEGACY_NODEEPSLEEP;
2245 else
2246 qpower = PS_LEGACY_DEEPSLEEP;
2247 hdd_info("Qpower disabled, %d", qpower);
2248 }
Jeff Johnson1b780e42017-10-31 14:11:45 -07002249 status = wma_set_qpower_config(adapter->session_id, qpower);
Dustin Brown10a7b712016-10-07 10:31:16 -07002250 if (status != QDF_STATUS_SUCCESS) {
2251 hdd_err("failed to configure qpower: %d", status);
2252 return -EINVAL;
Kapil Gupta6213c012016-09-02 19:39:09 +05302253 }
Dustin Brown10a7b712016-10-07 10:31:16 -07002254
Kapil Gupta6213c012016-09-02 19:39:09 +05302255 return 0;
2256}
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002257
Dustin Brown54096432017-02-23 13:00:44 -08002258
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002259#ifdef WLAN_SUSPEND_RESUME_TEST
Dustin Brownbc81a472016-10-26 16:56:59 -07002260static struct net_device *g_dev;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002261static struct wiphy *g_wiphy;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002262static enum wow_resume_trigger g_resume_trigger;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002263
2264#define HDD_FA_SUSPENDED_BIT (0)
2265static unsigned long fake_apps_state;
2266
Dustin Brownd53d1a82016-10-03 12:57:33 -07002267/**
2268 * __hdd_wlan_fake_apps_resume() - The core logic for
2269 * hdd_wlan_fake_apps_resume() skipping the call to hif_fake_apps_resume(),
2270 * which is only need for non-irq resume
Dustin Brownbc81a472016-10-26 16:56:59 -07002271 * @wiphy: the kernel wiphy struct for the device being resumed
2272 * @dev: the kernel net_device struct for the device being resumed
Dustin Brownd53d1a82016-10-03 12:57:33 -07002273 *
Dustin Brownbc81a472016-10-26 16:56:59 -07002274 * Return: none, calls QDF_BUG() on failure
Dustin Brownd53d1a82016-10-03 12:57:33 -07002275 */
Dustin Brownbc81a472016-10-26 16:56:59 -07002276static void __hdd_wlan_fake_apps_resume(struct wiphy *wiphy,
2277 struct net_device *dev)
Dustin Brownd53d1a82016-10-03 12:57:33 -07002278{
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002279 struct hif_opaque_softc *hif_ctx;
Dustin Brownddb59702017-01-12 16:20:31 -08002280 qdf_device_t qdf_dev;
Dustin Brownd53d1a82016-10-03 12:57:33 -07002281
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002282 hdd_info("Unit-test resume WLAN");
Dustin Brownddb59702017-01-12 16:20:31 -08002283
2284 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2285 if (!qdf_dev) {
2286 hdd_err("Failed to get QDF device context");
2287 QDF_BUG(0);
2288 return;
2289 }
2290
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002291 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2292 if (!hif_ctx) {
2293 hdd_err("Failed to get HIF context");
2294 return;
2295 }
2296
Dustin Brownd53d1a82016-10-03 12:57:33 -07002297 if (!test_and_clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) {
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002298 hdd_alert("Not unit-test suspended; Nothing to do");
Dustin Brownd53d1a82016-10-03 12:57:33 -07002299 return;
2300 }
2301
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002302 /* simulate kernel disable irqs */
2303 QDF_BUG(!hif_apps_wake_irq_disable(hif_ctx));
Dustin Brownd53d1a82016-10-03 12:57:33 -07002304
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002305 QDF_BUG(!wlan_hdd_bus_resume_noirq());
Dustin Brownd53d1a82016-10-03 12:57:33 -07002306
2307 /* simulate kernel enable irqs */
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002308 QDF_BUG(!hif_apps_irqs_enable(hif_ctx));
Dustin Brownd53d1a82016-10-03 12:57:33 -07002309
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002310 QDF_BUG(!wlan_hdd_bus_resume());
Dustin Brownd53d1a82016-10-03 12:57:33 -07002311
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002312 QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy));
2313
2314 if (g_resume_trigger == WOW_RESUME_TRIGGER_HTC_WAKEUP)
2315 hif_vote_link_down(hif_ctx);
Dustin Brownbc81a472016-10-26 16:56:59 -07002316
2317 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Dustin Brown562b9672016-12-22 15:25:33 -08002318
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002319 hdd_alert("Unit-test resume succeeded");
Dustin Brownd53d1a82016-10-03 12:57:33 -07002320}
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002321
2322/**
2323 * hdd_wlan_fake_apps_resume_irq_callback() - Irq callback function for resuming
2324 * from unit-test initiated suspend from irq wakeup signal
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002325 *
2326 * Resume wlan after getting very 1st CE interrupt from target
2327 *
2328 * Return: none
2329 */
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002330static void hdd_wlan_fake_apps_resume_irq_callback(void)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002331{
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002332 hdd_info("Trigger unit-test resume WLAN");
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002333
2334 QDF_BUG(g_wiphy);
Dustin Brownbc81a472016-10-26 16:56:59 -07002335 QDF_BUG(g_dev);
2336 __hdd_wlan_fake_apps_resume(g_wiphy, g_dev);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002337 g_wiphy = NULL;
Dustin Brownbc81a472016-10-26 16:56:59 -07002338 g_dev = NULL;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002339}
2340
Dustin Brown54096432017-02-23 13:00:44 -08002341int hdd_wlan_fake_apps_suspend(struct wiphy *wiphy, struct net_device *dev,
2342 enum wow_interface_pause pause_setting,
2343 enum wow_resume_trigger resume_setting)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002344{
Dustin Brownddb59702017-01-12 16:20:31 -08002345 qdf_device_t qdf_dev;
2346 struct hif_opaque_softc *hif_ctx;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002347 int errno;
Dustin Brown54096432017-02-23 13:00:44 -08002348 struct wow_enable_params wow_params = {
2349 .is_unit_test = true,
2350 .interface_pause = pause_setting,
2351 .resume_trigger = resume_setting
2352 };
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002353
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002354 hdd_info("Unit-test suspend WLAN");
Dustin Brownddb59702017-01-12 16:20:31 -08002355
Dustin Brown54096432017-02-23 13:00:44 -08002356 if (pause_setting < WOW_INTERFACE_PAUSE_DEFAULT ||
2357 pause_setting >= WOW_INTERFACE_PAUSE_COUNT) {
2358 hdd_err("Invalid interface pause %d (expected range [0, 2])",
2359 pause_setting);
2360 return -EINVAL;
2361 }
2362
2363 if (resume_setting < WOW_RESUME_TRIGGER_DEFAULT ||
2364 resume_setting >= WOW_RESUME_TRIGGER_COUNT) {
2365 hdd_err("Invalid resume trigger %d (expected range [0, 2])",
2366 resume_setting);
2367 return -EINVAL;
2368 }
2369
Dustin Brownddb59702017-01-12 16:20:31 -08002370 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2371 if (!qdf_dev) {
2372 hdd_err("Failed to get QDF device context");
2373 return -EINVAL;
2374 }
2375
2376 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2377 if (!hif_ctx) {
2378 hdd_err("Failed to get HIF context");
2379 return -EINVAL;
2380 }
2381
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002382 if (test_and_set_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) {
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002383 hdd_alert("Already unit-test suspended; Nothing to do");
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002384 return 0;
2385 }
2386
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002387 /* pci link is needed to wakeup from HTC wakeup trigger */
2388 if (resume_setting == WOW_RESUME_TRIGGER_HTC_WAKEUP)
2389 hif_vote_link_up(hif_ctx);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002390
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002391 errno = wlan_hdd_cfg80211_suspend_wlan(wiphy, NULL);
2392 if (errno)
2393 goto link_down;
2394
2395 errno = wlan_hdd_unit_test_bus_suspend(wow_params);
2396 if (errno)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002397 goto cfg80211_resume;
2398
2399 /* simulate kernel disabling irqs */
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002400 errno = hif_apps_irqs_disable(hif_ctx);
2401 if (errno)
2402 goto bus_resume;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002403
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002404 errno = wlan_hdd_bus_suspend_noirq();
2405 if (errno)
2406 goto enable_irqs;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002407
Dustin Brownbc81a472016-10-26 16:56:59 -07002408 /* pass wiphy/dev to callback via global variables */
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002409 g_wiphy = wiphy;
Dustin Brownbc81a472016-10-26 16:56:59 -07002410 g_dev = dev;
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002411 g_resume_trigger = resume_setting;
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002412 hif_ut_apps_suspend(hif_ctx, hdd_wlan_fake_apps_resume_irq_callback);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002413
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002414 /* re-enable wake irq */
2415 errno = hif_apps_wake_irq_enable(hif_ctx);
2416 if (errno)
2417 goto fake_apps_resume;
2418
Dustin Brownbc81a472016-10-26 16:56:59 -07002419 /*
2420 * Tell the kernel not to worry if TX queues aren't moving. This is
2421 * expected since we are suspending the wifi hardware, but not APPS
2422 */
2423 dev->watchdog_timeo = INT_MAX;
2424
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002425 hdd_alert("Unit-test suspend succeeded");
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002426
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002427 return 0;
2428
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002429fake_apps_resume:
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002430 hif_ut_apps_resume(hif_ctx);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002431
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002432enable_irqs:
2433 QDF_BUG(!hif_apps_irqs_enable(hif_ctx));
2434
2435bus_resume:
2436 QDF_BUG(!wlan_hdd_bus_resume());
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002437
2438cfg80211_resume:
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002439 QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy));
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002440
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002441link_down:
2442 hif_vote_link_down(hif_ctx);
2443
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002444 clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state);
Dustin Brown3ed3e9b2017-03-23 12:57:58 -07002445 hdd_err("Unit-test suspend failed: %d", errno);
2446
2447 return errno;
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002448}
2449
Dustin Brownbc81a472016-10-26 16:56:59 -07002450int hdd_wlan_fake_apps_resume(struct wiphy *wiphy, struct net_device *dev)
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002451{
Dustin Brownddb59702017-01-12 16:20:31 -08002452 struct hif_opaque_softc *hif_ctx;
2453
2454 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2455 if (!hif_ctx) {
2456 hdd_err("Failed to get HIF context");
2457 return -EINVAL;
2458 }
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002459
Dustin Brown0f8dc3d2017-06-01 14:37:26 -07002460 hif_ut_apps_resume(hif_ctx);
Dustin Brownbc81a472016-10-26 16:56:59 -07002461 __hdd_wlan_fake_apps_resume(wiphy, dev);
Rajeev Kumar9bb2e852016-09-24 12:29:25 -07002462
2463 return 0;
2464}
2465#endif