Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Poddar, Siddarth | a78cac3 | 2016-12-29 20:08:34 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
| 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 Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 44 | #include "qdf_types.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 45 | #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 Johnson | c8d0c25 | 2016-10-05 16:19:50 -0700 | [diff] [blame] | 55 | #include <wlan_hdd_host_offload.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 56 | #include <dbglog_host.h> |
| 57 | #include <wlan_hdd_trace.h> |
Masti, Narayanraddi | 3e26de6 | 2016-08-19 14:33:22 +0530 | [diff] [blame] | 58 | #include <wlan_hdd_p2p.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 59 | |
| 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 Puligilla | e390be5 | 2016-02-08 17:07:05 -0800 | [diff] [blame] | 66 | #include <wlan_hdd_scan.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 67 | #include <wlan_hdd_cfg80211.h> |
| 68 | #include <net/addrconf.h> |
| 69 | #include <wlan_hdd_ipa.h> |
Jeff Johnson | 2b0a7b8 | 2016-05-18 15:08:02 -0700 | [diff] [blame] | 70 | #include <wlan_hdd_lpass.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 71 | |
| 72 | #include <wma_types.h> |
Poddar, Siddarth | a78cac3 | 2016-12-29 20:08:34 +0530 | [diff] [blame] | 73 | #include <ol_txrx_osif_api.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 74 | #include "hif.h" |
| 75 | #include "sme_power_save_api.h" |
Tushnim Bhattacharyya | de1070d | 2017-03-09 13:23:55 -0800 | [diff] [blame] | 76 | #include "wlan_policy_mgr_api.h" |
Dhanashri Atre | b08959a | 2016-03-01 17:28:03 -0800 | [diff] [blame] | 77 | #include "cdp_txrx_flow_ctrl_v2.h" |
Yuanyuan Liu | 1373850 | 2016-04-06 17:41:37 -0700 | [diff] [blame] | 78 | #include "pld_common.h" |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 79 | #include "wlan_hdd_driver_ops.h" |
Himanshu Agarwal | f65bd4c | 2016-12-05 17:21:12 +0530 | [diff] [blame] | 80 | #include <wlan_logging_sock_svc.h> |
Krunal Soni | d32c6bc | 2016-10-18 18:00:21 -0700 | [diff] [blame] | 81 | #include "scheduler_api.h" |
yeshwanth sriram guntuka | 310b3ac | 2016-11-15 23:25:26 +0530 | [diff] [blame] | 82 | #include "cds_utils.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 83 | |
| 84 | /* Preprocessor definitions and constants */ |
Yue Ma | 4ea4f05 | 2015-10-27 12:25:27 -0700 | [diff] [blame] | 85 | #define HDD_SSR_BRING_UP_TIME 30000 |
Sreelakshmi Konamki | 2252853 | 2016-09-06 16:34:50 +0530 | [diff] [blame] | 86 | #define HDD_WAKE_LOCK_RESUME_DURATION 1000 |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 87 | |
| 88 | /* Type declarations */ |
| 89 | |
Abhishek Singh | baea27d | 2016-04-27 13:29:30 +0530 | [diff] [blame] | 90 | #ifdef FEATURE_WLAN_DIAG_SUPPORT |
| 91 | /** |
| 92 | * hdd_wlan_suspend_resume_event()- send suspend/resume state |
| 93 | * @state: suspend/resume state |
| 94 | * |
| 95 | * This Function send send suspend resume state diag event |
| 96 | * |
| 97 | * Return: void. |
| 98 | */ |
| 99 | void hdd_wlan_suspend_resume_event(uint8_t state) |
| 100 | { |
| 101 | WLAN_HOST_DIAG_EVENT_DEF(suspend_state, struct host_event_suspend); |
| 102 | qdf_mem_zero(&suspend_state, sizeof(suspend_state)); |
| 103 | |
| 104 | suspend_state.state = state; |
| 105 | WLAN_HOST_DIAG_EVENT_REPORT(&suspend_state, EVENT_WLAN_SUSPEND_RESUME); |
| 106 | } |
Abhishek Singh | 4aad0f7 | 2016-04-27 13:43:29 +0530 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * hdd_wlan_offload_event()- send offloads event |
| 110 | * @type: offload type |
| 111 | * @state: enabled or disabled |
| 112 | * |
| 113 | * This Function send offloads enable/disable diag event |
| 114 | * |
| 115 | * Return: void. |
| 116 | */ |
| 117 | |
| 118 | void hdd_wlan_offload_event(uint8_t type, uint8_t state) |
| 119 | { |
| 120 | WLAN_HOST_DIAG_EVENT_DEF(host_offload, struct host_event_offload_req); |
| 121 | qdf_mem_zero(&host_offload, sizeof(host_offload)); |
| 122 | |
| 123 | host_offload.offload_type = type; |
| 124 | host_offload.state = state; |
| 125 | |
| 126 | WLAN_HOST_DIAG_EVENT_REPORT(&host_offload, EVENT_WLAN_OFFLOAD_REQ); |
| 127 | } |
Abhishek Singh | baea27d | 2016-04-27 13:29:30 +0530 | [diff] [blame] | 128 | #endif |
| 129 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 130 | /* Function and variables declarations */ |
| 131 | |
| 132 | extern struct notifier_block hdd_netdev_notifier; |
| 133 | |
| 134 | static struct timer_list ssr_timer; |
| 135 | static bool ssr_timer_started; |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 136 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 137 | /** |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 138 | * hdd_enable_gtk_offload() - enable GTK offload |
| 139 | * @adapter: pointer to the adapter |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 140 | * |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 141 | * Central function to enable GTK offload. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 142 | * |
| 143 | * Return: nothing |
| 144 | */ |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 145 | static void hdd_enable_gtk_offload(hdd_adapter_t *adapter) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 146 | { |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 147 | QDF_STATUS status; |
| 148 | status = pmo_ucfg_enable_gtk_offload_in_fwr(adapter->hdd_vdev); |
| 149 | if (status != QDF_STATUS_SUCCESS) |
| 150 | hdd_info("Failed to enable gtk offload"); |
| 151 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 152 | |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 153 | /** |
| 154 | * hdd_disable_gtk_offload() - disable GTK offload |
| 155 | * @pAdapter: pointer to the adapter |
| 156 | * |
| 157 | * Central function to disable GTK offload. |
| 158 | * |
| 159 | * Return: nothing |
| 160 | */ |
| 161 | static void hdd_disable_gtk_offload(hdd_adapter_t *adapter) |
| 162 | { |
| 163 | struct pmo_gtk_rsp_req gtk_rsp_request; |
| 164 | QDF_STATUS status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 165 | |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 166 | /* ensure to get gtk rsp first before disable it*/ |
| 167 | gtk_rsp_request.callback = |
| 168 | wlan_hdd_cfg80211_update_replay_counter_callback; |
| 169 | /* Passing as void* as PMO does not know legacy HDD adapter type */ |
| 170 | gtk_rsp_request.callback_context = |
| 171 | (void *)adapter; |
| 172 | status = pmo_ucfg_get_gtk_rsp(adapter->hdd_vdev, |
| 173 | >k_rsp_request); |
| 174 | if (status != QDF_STATUS_SUCCESS) { |
| 175 | hdd_err("Failed to send get gtk rsp status:%d", status); |
| 176 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 177 | } |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 178 | hdd_debug("send get_gtk_rsp successful"); |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 179 | status = pmo_ucfg_disable_gtk_offload_in_fwr(adapter->hdd_vdev); |
| 180 | if (status != QDF_STATUS_SUCCESS) |
| 181 | hdd_info("Failed to disable gtk offload"); |
| 182 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 183 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 184 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 185 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 186 | /** |
| 187 | * __wlan_hdd_ipv6_changed() - IPv6 notifier callback function |
| 188 | * @nb: notifier block that was registered with the kernel |
| 189 | * @data: (unused) generic data that was registered with the kernel |
| 190 | * @arg: (unused) generic argument that was registered with the kernel |
| 191 | * |
| 192 | * This is a callback function that is registered with the kernel via |
| 193 | * register_inet6addr_notifier() which allows the driver to be |
| 194 | * notified when there is an IPv6 address change. |
| 195 | * |
| 196 | * Return: NOTIFY_DONE to indicate we don't care what happens with |
| 197 | * other callbacks |
| 198 | */ |
| 199 | static int __wlan_hdd_ipv6_changed(struct notifier_block *nb, |
| 200 | unsigned long data, void *arg) |
| 201 | { |
| 202 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg; |
| 203 | struct net_device *ndev = ifa->idev->dev; |
| 204 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev); |
| 205 | hdd_context_t *pHddCtx; |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 206 | hdd_station_ctx_t *sta_ctx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 207 | int status; |
| 208 | |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 209 | ENTER_DEV(ndev); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 210 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 211 | if ((pAdapter == NULL) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 212 | hdd_err("Adapter context is invalid %p", pAdapter); |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 213 | return NOTIFY_DONE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | if ((pAdapter->dev == ndev) && |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 217 | (pAdapter->device_mode == QDF_STA_MODE || |
| 218 | pAdapter->device_mode == QDF_P2P_CLIENT_MODE || |
| 219 | pAdapter->device_mode == QDF_NDI_MODE)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 220 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 221 | status = wlan_hdd_validate_context(pHddCtx); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 222 | if (0 != status) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 223 | return NOTIFY_DONE; |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 224 | sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter); |
Padma, Santhosh Kumar | 8392fb4 | 2017-03-17 12:35:27 +0530 | [diff] [blame] | 225 | hdd_debug("invoking sme_dhcp_done_ind"); |
| 226 | sme_dhcp_done_ind(pHddCtx->hHal, |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 227 | pAdapter->sessionId); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 228 | schedule_work(&pAdapter->ipv6NotifierWorkQueue); |
| 229 | } |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 230 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 231 | return NOTIFY_DONE; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * wlan_hdd_ipv6_changed() - IPv6 change notifier callback |
| 236 | * @nb: pointer to notifier block |
| 237 | * @data: data |
| 238 | * @arg: arg |
| 239 | * |
| 240 | * This is the IPv6 notifier callback function gets invoked |
| 241 | * if any change in IP and then invoke the function @__wlan_hdd_ipv6_changed |
| 242 | * to reconfigure the offload parameters. |
| 243 | * |
| 244 | * Return: 0 on success, error number otherwise. |
| 245 | */ |
| 246 | int wlan_hdd_ipv6_changed(struct notifier_block *nb, |
| 247 | unsigned long data, void *arg) |
| 248 | { |
| 249 | int ret; |
| 250 | |
| 251 | cds_ssr_protect(__func__); |
| 252 | ret = __wlan_hdd_ipv6_changed(nb, data, arg); |
| 253 | cds_ssr_unprotect(__func__); |
| 254 | |
| 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | /** |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 259 | * hdd_fill_ipv6_uc_addr() - fill IPv6 unicast addresses |
| 260 | * @idev: pointer to net device |
| 261 | * @ipv6addr: destination array to fill IPv6 addresses |
| 262 | * @ipv6addr_type: IPv6 Address type |
| 263 | * @count: number of IPv6 addresses |
| 264 | * |
| 265 | * This is the IPv6 utility function to populate unicast addresses. |
| 266 | * |
| 267 | * Return: 0 on success, error number otherwise. |
| 268 | */ |
| 269 | static int hdd_fill_ipv6_uc_addr(struct inet6_dev *idev, |
| 270 | uint8_t ipv6_uc_addr[][SIR_MAC_IPV6_ADDR_LEN], |
| 271 | uint8_t *ipv6addr_type, uint32_t *count) |
| 272 | { |
| 273 | struct inet6_ifaddr *ifa; |
| 274 | struct list_head *p; |
| 275 | uint32_t scope; |
| 276 | |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 277 | read_lock_bh(&idev->lock); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 278 | list_for_each(p, &idev->addr_list) { |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 279 | if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) { |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 280 | read_unlock_bh(&idev->lock); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 281 | return -EINVAL; |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 282 | } |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 283 | ifa = list_entry(p, struct inet6_ifaddr, if_list); |
| 284 | if (ifa->flags & IFA_F_DADFAILED) |
| 285 | continue; |
| 286 | scope = ipv6_addr_src_scope(&ifa->addr); |
| 287 | switch (scope) { |
| 288 | case IPV6_ADDR_SCOPE_GLOBAL: |
| 289 | case IPV6_ADDR_SCOPE_LINKLOCAL: |
| 290 | qdf_mem_copy(ipv6_uc_addr[*count], &ifa->addr.s6_addr, |
| 291 | sizeof(ifa->addr.s6_addr)); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 292 | ipv6addr_type[*count] = PMO_IPV6_ADDR_UC_TYPE; |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 293 | hdd_debug("Index %d scope = %s UC-Address: %pI6", |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 294 | *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ? |
| 295 | "LINK LOCAL" : "GLOBAL", ipv6_uc_addr[*count]); |
| 296 | *count += 1; |
| 297 | break; |
| 298 | default: |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 299 | hdd_warn("The Scope %d is not supported", scope); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 300 | } |
| 301 | } |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 302 | |
| 303 | read_unlock_bh(&idev->lock); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * hdd_fill_ipv6_ac_addr() - fill IPv6 anycast addresses |
| 309 | * @idev: pointer to net device |
| 310 | * @ipv6addr: destination array to fill IPv6 addresses |
| 311 | * @ipv6addr_type: IPv6 Address type |
| 312 | * @count: number of IPv6 addresses |
| 313 | * |
| 314 | * This is the IPv6 utility function to populate anycast addresses. |
| 315 | * |
| 316 | * Return: 0 on success, error number otherwise. |
| 317 | */ |
| 318 | static int hdd_fill_ipv6_ac_addr(struct inet6_dev *idev, |
| 319 | uint8_t ipv6_ac_addr[][SIR_MAC_IPV6_ADDR_LEN], |
| 320 | uint8_t *ipv6addr_type, uint32_t *count) |
| 321 | { |
| 322 | struct ifacaddr6 *ifaca; |
| 323 | uint32_t scope; |
| 324 | |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 325 | read_lock_bh(&idev->lock); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 326 | for (ifaca = idev->ac_list; ifaca; ifaca = ifaca->aca_next) { |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 327 | if (*count >= PMO_MAC_NUM_TARGET_IPV6_NS_OFFLOAD_NA) { |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 328 | read_unlock_bh(&idev->lock); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 329 | return -EINVAL; |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 330 | } |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 331 | /* For anycast addr no DAD */ |
| 332 | scope = ipv6_addr_src_scope(&ifaca->aca_addr); |
| 333 | switch (scope) { |
| 334 | case IPV6_ADDR_SCOPE_GLOBAL: |
| 335 | case IPV6_ADDR_SCOPE_LINKLOCAL: |
| 336 | qdf_mem_copy(ipv6_ac_addr[*count], &ifaca->aca_addr, |
| 337 | sizeof(ifaca->aca_addr)); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 338 | ipv6addr_type[*count] = PMO_IPV6_ADDR_AC_TYPE; |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 339 | hdd_debug("Index %d scope = %s AC-Address: %pI6", |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 340 | *count, (scope == IPV6_ADDR_SCOPE_LINKLOCAL) ? |
| 341 | "LINK LOCAL" : "GLOBAL", ipv6_ac_addr[*count]); |
| 342 | *count += 1; |
| 343 | break; |
| 344 | default: |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 345 | hdd_warn("The Scope %d is not supported", scope); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 346 | } |
| 347 | } |
Srinivas Girigowda | 90cdd3c | 2016-10-18 11:28:10 -0700 | [diff] [blame] | 348 | |
| 349 | read_unlock_bh(&idev->lock); |
Sravan Kumar Kairam | c087358 | 2016-07-26 17:34:57 +0530 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 353 | void hdd_enable_ns_offload(hdd_adapter_t *adapter, |
| 354 | enum pmo_offload_trigger trigger) |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 355 | { |
| 356 | struct inet6_dev *in6_dev; |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 357 | QDF_STATUS status; |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 358 | hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 359 | struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc; |
| 360 | struct pmo_ns_req *ns_req = NULL; |
| 361 | int err; |
| 362 | |
| 363 | ENTER(); |
| 364 | if (!psoc) { |
| 365 | hdd_err("psoc is NULL"); |
| 366 | goto out; |
| 367 | } |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | in6_dev = __in6_dev_get(adapter->dev); |
| 370 | if (NULL == in6_dev) { |
| 371 | hdd_err("IPv6 dev does not exist. Failed to request NSOffload"); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 372 | goto out; |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 375 | ns_req = qdf_mem_malloc(sizeof(*ns_req)); |
| 376 | if (!ns_req) { |
| 377 | hdd_err("fail to allocate ns_req"); |
| 378 | goto out; |
| 379 | } |
| 380 | |
| 381 | ns_req->psoc = psoc; |
| 382 | ns_req->vdev_id = adapter->sessionId; |
| 383 | ns_req->trigger = trigger; |
| 384 | ns_req->count = 0; |
| 385 | |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 386 | /* Unicast Addresses */ |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 387 | err = hdd_fill_ipv6_uc_addr(in6_dev, ns_req->ipv6_addr, |
| 388 | ns_req->ipv6_addr_type, &ns_req->count); |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 389 | if (err) { |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 390 | hdd_disable_ns_offload(adapter, trigger); |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 391 | hdd_debug("Reached max supported addresses and not enabling " |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 392 | "NS offload"); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 393 | goto out; |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* Anycast Addresses */ |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 397 | err = hdd_fill_ipv6_ac_addr(in6_dev, ns_req->ipv6_addr, |
| 398 | ns_req->ipv6_addr_type, &ns_req->count); |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 399 | if (err) { |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 400 | hdd_disable_ns_offload(adapter, trigger); |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 401 | hdd_debug("Reached max supported addresses and not enabling " |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 402 | "NS offload"); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 403 | goto out; |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 406 | /* cache ns request */ |
| 407 | status = pmo_ucfg_cache_ns_offload_req(ns_req); |
| 408 | if (status != QDF_STATUS_SUCCESS) { |
| 409 | hdd_err("Failed to cache ns request status: %d", status); |
| 410 | goto out; |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 413 | /* enable ns request */ |
| 414 | status = pmo_ucfg_enable_ns_offload_in_fwr(adapter->hdd_vdev, trigger); |
| 415 | if (status != QDF_STATUS_SUCCESS) |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 416 | hdd_err("Failed to enable HostOffload feature with status: %d", |
| 417 | status); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 418 | else |
| 419 | hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD, SIR_OFFLOAD_ENABLE); |
| 420 | out: |
| 421 | if (ns_req) |
| 422 | qdf_mem_free(ns_req); |
| 423 | EXIT(); |
| 424 | |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 427 | void hdd_disable_ns_offload(hdd_adapter_t *adapter, |
| 428 | enum pmo_offload_trigger trigger) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 429 | { |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 430 | QDF_STATUS status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 431 | |
| 432 | ENTER(); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 433 | status = pmo_ucfg_flush_ns_offload_req(adapter->hdd_vdev); |
| 434 | if (status != QDF_STATUS_SUCCESS) { |
| 435 | hdd_err("Failed to flush NS Offload"); |
| 436 | goto out; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 439 | status = pmo_ucfg_disable_ns_offload_in_fwr(adapter->hdd_vdev, trigger); |
| 440 | if (status != QDF_STATUS_SUCCESS) |
| 441 | hdd_err("Failed to disable NS Offload"); |
Dustin Brown | 2444ee6 | 2016-09-06 17:20:36 -0700 | [diff] [blame] | 442 | else |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 443 | hdd_wlan_offload_event(SIR_IPV6_NS_OFFLOAD, |
| 444 | SIR_OFFLOAD_DISABLE); |
| 445 | out: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 446 | EXIT(); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 447 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
| 451 | * __hdd_ipv6_notifier_work_queue() - IPv6 notification work function |
| 452 | * @work: registered work item |
| 453 | * |
| 454 | * This function performs the work initially trigged by a callback |
| 455 | * from the IPv6 netdev notifier. Since this means there has been a |
| 456 | * change in IPv6 state for the interface, the NS offload is |
| 457 | * reconfigured. |
| 458 | * |
| 459 | * Return: None |
| 460 | */ |
Jeff Johnson | c8d0c25 | 2016-10-05 16:19:50 -0700 | [diff] [blame] | 461 | static void __hdd_ipv6_notifier_work_queue(struct work_struct *work) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 462 | { |
| 463 | hdd_adapter_t *pAdapter = |
| 464 | container_of(work, hdd_adapter_t, ipv6NotifierWorkQueue); |
| 465 | hdd_context_t *pHddCtx; |
| 466 | int status; |
| 467 | |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 468 | ENTER(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 469 | |
| 470 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 471 | status = wlan_hdd_validate_context(pHddCtx); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 472 | if (0 != status) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 473 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 474 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 475 | hdd_enable_ns_offload(pAdapter, pmo_ipv6_change_notify); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 476 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
| 480 | * hdd_ipv6_notifier_work_queue() - IP V6 change notifier work handler |
| 481 | * @work: Pointer to work context |
| 482 | * |
| 483 | * Return: none |
| 484 | */ |
| 485 | void hdd_ipv6_notifier_work_queue(struct work_struct *work) |
| 486 | { |
| 487 | cds_ssr_protect(__func__); |
| 488 | __hdd_ipv6_notifier_work_queue(work); |
| 489 | cds_ssr_unprotect(__func__); |
| 490 | } |
| 491 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 492 | void hdd_enable_host_offloads(hdd_adapter_t *adapter, |
| 493 | enum pmo_offload_trigger trigger) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 494 | { |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 495 | ENTER(); |
| 496 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 497 | if (!pmo_ucfg_is_vdev_supports_offload(adapter->hdd_vdev)) { |
| 498 | hdd_info("offload is not supported on this vdev opmode: %d", |
| 499 | adapter->device_mode); |
| 500 | goto out; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 503 | if (!pmo_ucfg_is_vdev_connected(adapter->hdd_vdev)) { |
| 504 | hdd_info("vdev is not connected"); |
| 505 | goto out; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 506 | } |
| 507 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 508 | hdd_info("enable offloads"); |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 509 | hdd_enable_gtk_offload(adapter); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 510 | hdd_enable_arp_offload(adapter, trigger); |
| 511 | hdd_enable_ns_offload(adapter, trigger); |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 512 | hdd_enable_mc_addr_filtering(adapter, trigger); |
Ravi Kumar Bokka | 794fd71 | 2017-03-21 20:52:46 +0530 | [diff] [blame^] | 513 | hdd_enable_non_arp_hw_broadcast_filter(adapter); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 514 | out: |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 515 | EXIT(); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 516 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 517 | } |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 518 | |
| 519 | void hdd_disable_host_offloads(hdd_adapter_t *adapter, |
| 520 | enum pmo_offload_trigger trigger) |
| 521 | { |
| 522 | ENTER(); |
| 523 | |
| 524 | if (!pmo_ucfg_is_vdev_supports_offload(adapter->hdd_vdev)) { |
| 525 | hdd_info("offload is not supported on this vdev opmode: %d", |
| 526 | adapter->device_mode); |
| 527 | goto out; |
| 528 | } |
| 529 | |
| 530 | if (!pmo_ucfg_is_vdev_connected(adapter->hdd_vdev)) { |
| 531 | hdd_info("vdev is not connected"); |
| 532 | goto out; |
| 533 | } |
| 534 | |
| 535 | hdd_info("disable offloads"); |
Mukul Sharma | 3d36c39 | 2017-01-18 18:39:12 +0530 | [diff] [blame] | 536 | hdd_disable_gtk_offload(adapter); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 537 | hdd_disable_arp_offload(adapter, trigger); |
| 538 | hdd_disable_ns_offload(adapter, trigger); |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 539 | hdd_disable_mc_addr_filtering(adapter, trigger); |
Ravi Kumar Bokka | 794fd71 | 2017-03-21 20:52:46 +0530 | [diff] [blame^] | 540 | hdd_disable_non_arp_hw_broadcast_filter(adapter); |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 541 | out: |
| 542 | EXIT(); |
| 543 | |
| 544 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 545 | |
| 546 | /** |
Dustin Brown | 3c31ceb | 2017-02-01 14:43:52 -0800 | [diff] [blame] | 547 | * hdd_lookup_ifaddr() - Lookup interface address data by name |
| 548 | * @adapter: the adapter whose name should be searched for |
| 549 | * |
| 550 | * return in_ifaddr pointer on success, NULL for failure |
| 551 | */ |
| 552 | static struct in_ifaddr *hdd_lookup_ifaddr(hdd_adapter_t *adapter) |
| 553 | { |
| 554 | struct in_ifaddr *ifa; |
| 555 | struct in_device *in_dev; |
| 556 | |
| 557 | if (!adapter) { |
| 558 | hdd_err("adapter is null"); |
| 559 | return NULL; |
| 560 | } |
| 561 | |
| 562 | in_dev = __in_dev_get_rtnl(adapter->dev); |
| 563 | if (!in_dev) { |
| 564 | hdd_err("Failed to get in_device"); |
| 565 | return NULL; |
| 566 | } |
| 567 | |
| 568 | /* lookup address data by interface name */ |
| 569 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
| 570 | if (!strcmp(adapter->dev->name, ifa->ifa_label)) |
| 571 | return ifa; |
| 572 | } |
| 573 | |
| 574 | return NULL; |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * hdd_populate_ipv4_addr() - Populates the adapter's IPv4 address |
| 579 | * @adapter: the adapter whose IPv4 address is desired |
| 580 | * @ipv4_addr: the address of the array to copy the IPv4 address into |
| 581 | * |
| 582 | * return: zero for success; non-zero for failure |
| 583 | */ |
| 584 | static int hdd_populate_ipv4_addr(hdd_adapter_t *adapter, uint8_t *ipv4_addr) |
| 585 | { |
| 586 | struct in_ifaddr *ifa; |
| 587 | int i; |
| 588 | |
| 589 | if (!adapter) { |
| 590 | hdd_err("adapter is null"); |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | |
| 594 | if (!ipv4_addr) { |
| 595 | hdd_err("ipv4_addr is null"); |
| 596 | return -EINVAL; |
| 597 | } |
| 598 | |
| 599 | ifa = hdd_lookup_ifaddr(adapter); |
| 600 | if (!ifa || !ifa->ifa_local) { |
| 601 | hdd_err("ipv4 address not found"); |
| 602 | return -EINVAL; |
| 603 | } |
| 604 | |
| 605 | /* convert u32 to byte array */ |
| 606 | for (i = 0; i < 4; i++) |
| 607 | ipv4_addr[i] = (ifa->ifa_local >> i * 8) & 0xff; |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * hdd_set_grat_arp_keepalive() - Enable grat APR keepalive |
| 614 | * @adapter: the HDD adapter to configure |
| 615 | * |
| 616 | * This configures gratuitous APR keepalive based on the adapter's current |
| 617 | * connection information, specifically IPv4 address and BSSID |
| 618 | * |
| 619 | * return: zero for success, non-zero for failure |
| 620 | */ |
| 621 | static int hdd_set_grat_arp_keepalive(hdd_adapter_t *adapter) |
| 622 | { |
| 623 | QDF_STATUS status; |
| 624 | int exit_code; |
| 625 | hdd_context_t *hdd_ctx; |
| 626 | hdd_station_ctx_t *sta_ctx; |
| 627 | tSirKeepAliveReq req = { |
| 628 | .packetType = SIR_KEEP_ALIVE_UNSOLICIT_ARP_RSP, |
Dustin Brown | 3c31ceb | 2017-02-01 14:43:52 -0800 | [diff] [blame] | 629 | .dest_macaddr = QDF_MAC_ADDR_BROADCAST_INITIALIZER, |
| 630 | }; |
| 631 | |
| 632 | if (!adapter) { |
| 633 | hdd_err("adapter is null"); |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
| 637 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 638 | if (!hdd_ctx) { |
| 639 | hdd_err("hdd_ctx is null"); |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | |
| 643 | sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter); |
| 644 | if (!sta_ctx) { |
| 645 | hdd_err("sta_ctx is null"); |
| 646 | return -EINVAL; |
| 647 | } |
| 648 | |
| 649 | exit_code = hdd_populate_ipv4_addr(adapter, req.hostIpv4Addr); |
| 650 | if (exit_code) { |
| 651 | hdd_err("Failed to populate ipv4 address"); |
| 652 | return exit_code; |
| 653 | } |
| 654 | |
Dustin Brown | 6b4643d | 2017-02-09 12:19:28 -0800 | [diff] [blame] | 655 | /* according to RFC5227, sender/target ip address should be the same */ |
| 656 | qdf_mem_copy(&req.destIpv4Addr, &req.hostIpv4Addr, |
| 657 | sizeof(req.destIpv4Addr)); |
| 658 | |
Dustin Brown | 3c31ceb | 2017-02-01 14:43:52 -0800 | [diff] [blame] | 659 | qdf_copy_macaddr(&req.bssid, &sta_ctx->conn_info.bssId); |
| 660 | req.timePeriod = hdd_ctx->config->infraStaKeepAlivePeriod; |
| 661 | req.sessionId = adapter->sessionId; |
| 662 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 663 | hdd_debug("Setting gratuitous ARP keepalive; ipv4_addr:%u.%u.%u.%u", |
Dustin Brown | 3c31ceb | 2017-02-01 14:43:52 -0800 | [diff] [blame] | 664 | req.hostIpv4Addr[0], req.hostIpv4Addr[1], |
| 665 | req.hostIpv4Addr[2], req.hostIpv4Addr[3]); |
| 666 | |
| 667 | status = sme_set_keep_alive(hdd_ctx->hHal, req.sessionId, &req); |
| 668 | if (QDF_IS_STATUS_ERROR(status)) { |
| 669 | hdd_err("Failed to set keepalive"); |
| 670 | return qdf_status_to_os_return(status); |
| 671 | } |
| 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 677 | * __hdd_ipv4_notifier_work_queue() - IPv4 notification work function |
| 678 | * @work: registered work item |
| 679 | * |
| 680 | * This function performs the work initially trigged by a callback |
| 681 | * from the IPv4 netdev notifier. Since this means there has been a |
| 682 | * change in IPv4 state for the interface, the ARP offload is |
| 683 | * reconfigured. |
| 684 | * |
| 685 | * Return: None |
| 686 | */ |
Jeff Johnson | c8d0c25 | 2016-10-05 16:19:50 -0700 | [diff] [blame] | 687 | static void __hdd_ipv4_notifier_work_queue(struct work_struct *work) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 688 | { |
Dustin Brown | b6b0f18 | 2017-03-08 13:08:27 -0800 | [diff] [blame] | 689 | hdd_adapter_t *adapter; |
| 690 | hdd_context_t *hdd_ctx; |
| 691 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 692 | ENTER(); |
Dustin Brown | b6b0f18 | 2017-03-08 13:08:27 -0800 | [diff] [blame] | 693 | |
| 694 | adapter = container_of(work, hdd_adapter_t, ipv4NotifierWorkQueue); |
| 695 | hdd_enable_arp_offload(adapter, pmo_ipv4_change_notify); |
| 696 | |
| 697 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 698 | if (hdd_ctx->config->sta_keepalive_method == HDD_STA_KEEPALIVE_GRAT_ARP) |
| 699 | hdd_set_grat_arp_keepalive(adapter); |
| 700 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 701 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /** |
| 705 | * hdd_ipv4_notifier_work_queue() - IP V4 change notifier work handler |
| 706 | * @work: Pointer to work context |
| 707 | * |
| 708 | * Return: none |
| 709 | */ |
| 710 | void hdd_ipv4_notifier_work_queue(struct work_struct *work) |
| 711 | { |
| 712 | cds_ssr_protect(__func__); |
| 713 | __hdd_ipv4_notifier_work_queue(work); |
| 714 | cds_ssr_unprotect(__func__); |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * __wlan_hdd_ipv4_changed() - IPv4 notifier callback function |
| 719 | * @nb: notifier block that was registered with the kernel |
| 720 | * @data: (unused) generic data that was registered with the kernel |
| 721 | * @arg: (unused) generic argument that was registered with the kernel |
| 722 | * |
| 723 | * This is a callback function that is registered with the kernel via |
| 724 | * register_inetaddr_notifier() which allows the driver to be |
| 725 | * notified when there is an IPv4 address change. |
| 726 | * |
| 727 | * Return: NOTIFY_DONE to indicate we don't care what happens with |
| 728 | * other callbacks |
| 729 | */ |
| 730 | static int __wlan_hdd_ipv4_changed(struct notifier_block *nb, |
| 731 | unsigned long data, void *arg) |
| 732 | { |
| 733 | struct in_ifaddr *ifa = (struct in_ifaddr *)arg; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 734 | struct net_device *ndev = ifa->ifa_dev->dev; |
| 735 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(ndev); |
| 736 | hdd_context_t *pHddCtx; |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 737 | hdd_station_ctx_t *sta_ctx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 738 | int status; |
| 739 | |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 740 | ENTER_DEV(ndev); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 741 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 742 | if ((pAdapter == NULL) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 743 | hdd_err("Adapter context is invalid %p", pAdapter); |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 744 | return NOTIFY_DONE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 745 | } |
| 746 | |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 747 | if ((pAdapter->dev == ndev) && |
| 748 | (pAdapter->device_mode == QDF_STA_MODE || |
| 749 | pAdapter->device_mode == QDF_P2P_CLIENT_MODE || |
| 750 | pAdapter->device_mode == QDF_NDI_MODE)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 751 | |
| 752 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 753 | status = wlan_hdd_validate_context(pHddCtx); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 754 | if (0 != status) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 755 | return NOTIFY_DONE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 756 | |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 757 | sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter); |
Padma, Santhosh Kumar | 8392fb4 | 2017-03-17 12:35:27 +0530 | [diff] [blame] | 758 | hdd_debug("invoking sme_dhcp_done_ind"); |
| 759 | sme_dhcp_done_ind(pHddCtx->hHal, |
Jeff Johnson | 158c8d0 | 2016-10-31 13:11:48 -0700 | [diff] [blame] | 760 | pAdapter->sessionId); |
Abhishek Singh | ca40803 | 2016-09-13 15:26:12 +0530 | [diff] [blame] | 761 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 762 | if (!pHddCtx->config->fhostArpOffload) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 763 | hdd_debug("Offload not enabled ARPOffload=%d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 764 | pHddCtx->config->fhostArpOffload); |
| 765 | return NOTIFY_DONE; |
| 766 | } |
| 767 | |
Dustin Brown | 3c31ceb | 2017-02-01 14:43:52 -0800 | [diff] [blame] | 768 | ifa = hdd_lookup_ifaddr(pAdapter); |
| 769 | if (ifa && ifa->ifa_local) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 770 | schedule_work(&pAdapter->ipv4NotifierWorkQueue); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 771 | } |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 772 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 773 | return NOTIFY_DONE; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * wlan_hdd_ipv4_changed() - IPv4 change notifier callback |
| 778 | * @nb: pointer to notifier block |
| 779 | * @data: data |
| 780 | * @arg: arg |
| 781 | * |
| 782 | * This is the IPv4 notifier callback function gets invoked |
| 783 | * if any change in IP and then invoke the function @__wlan_hdd_ipv4_changed |
| 784 | * to reconfigure the offload parameters. |
| 785 | * |
| 786 | * Return: 0 on success, error number otherwise. |
| 787 | */ |
| 788 | int wlan_hdd_ipv4_changed(struct notifier_block *nb, |
| 789 | unsigned long data, void *arg) |
| 790 | { |
| 791 | int ret; |
| 792 | |
| 793 | cds_ssr_protect(__func__); |
| 794 | ret = __wlan_hdd_ipv4_changed(nb, data, arg); |
| 795 | cds_ssr_unprotect(__func__); |
| 796 | |
| 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | /** |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 801 | * hdd_get_ipv4_local_interface() - get ipv4 local interafce from iface list |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 802 | * @pAdapter: Adapter context for which ARP offload is to be configured |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 803 | * |
| 804 | * Return: |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 805 | * ifa - on successful operation, |
| 806 | * NULL - on failure of operation |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 807 | */ |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 808 | static struct in_ifaddr *hdd_get_ipv4_local_interface( |
| 809 | hdd_adapter_t *pAdapter) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 810 | { |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 811 | struct in_ifaddr **ifap = NULL; |
| 812 | struct in_ifaddr *ifa = NULL; |
| 813 | struct in_device *in_dev; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 814 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 815 | in_dev = __in_dev_get_rtnl(pAdapter->dev); |
| 816 | if (in_dev) { |
| 817 | for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL; |
| 818 | ifap = &ifa->ifa_next) { |
| 819 | if (!strcmp(pAdapter->dev->name, ifa->ifa_label)) { |
| 820 | /* if match break */ |
| 821 | return ifa; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 822 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 823 | } |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 824 | } |
| 825 | ifa = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 826 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 827 | return ifa; |
| 828 | } |
| 829 | |
| 830 | void hdd_enable_arp_offload(hdd_adapter_t *adapter, |
| 831 | enum pmo_offload_trigger trigger) |
| 832 | { |
| 833 | hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 834 | struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc; |
| 835 | QDF_STATUS status; |
| 836 | struct pmo_arp_req *arp_req = NULL; |
| 837 | struct in_ifaddr *ifa = NULL; |
| 838 | |
| 839 | ENTER(); |
| 840 | arp_req = qdf_mem_malloc(sizeof(*arp_req)); |
| 841 | if (!arp_req) { |
| 842 | hdd_err("cannot allocate arp_req"); |
| 843 | goto out; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 844 | } |
Jeff Johnson | 6875531 | 2017-02-10 11:46:55 -0800 | [diff] [blame] | 845 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 846 | arp_req->psoc = psoc; |
| 847 | arp_req->vdev_id = adapter->sessionId; |
| 848 | arp_req->trigger = trigger; |
Jeff Johnson | 6875531 | 2017-02-10 11:46:55 -0800 | [diff] [blame] | 849 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 850 | ifa = hdd_get_ipv4_local_interface(adapter); |
| 851 | if (ifa && ifa->ifa_local) { |
| 852 | arp_req->ipv4_addr = (uint32_t)ifa->ifa_local; |
| 853 | status = pmo_ucfg_cache_arp_offload_req(arp_req); |
| 854 | if (status == QDF_STATUS_SUCCESS) { |
| 855 | status = pmo_ucfg_enable_arp_offload_in_fwr( |
| 856 | adapter->hdd_vdev, trigger); |
| 857 | if (status == QDF_STATUS_SUCCESS) |
| 858 | hdd_wlan_offload_event( |
| 859 | PMO_IPV4_ARP_REPLY_OFFLOAD, |
| 860 | PMO_OFFLOAD_ENABLE); |
| 861 | else |
| 862 | hdd_info("fail to enable arp offload in fwr"); |
| 863 | } else |
| 864 | hdd_info("fail to cache arp offload request"); |
| 865 | } else { |
| 866 | hdd_notice("IP Address is not assigned"); |
| 867 | status = QDF_STATUS_NOT_INITIALIZED; |
| 868 | } |
| 869 | out: |
| 870 | if (arp_req) |
| 871 | qdf_mem_free(arp_req); |
| 872 | EXIT(); |
| 873 | |
| 874 | } |
| 875 | |
| 876 | void hdd_disable_arp_offload(hdd_adapter_t *adapter, |
| 877 | enum pmo_offload_trigger trigger) |
| 878 | { |
| 879 | QDF_STATUS status; |
| 880 | |
| 881 | ENTER(); |
| 882 | status = pmo_ucfg_flush_arp_offload_req(adapter->hdd_vdev); |
| 883 | if (status != QDF_STATUS_SUCCESS) { |
| 884 | hdd_err("Failed to flush arp Offload"); |
| 885 | goto out; |
Jeff Johnson | 6875531 | 2017-02-10 11:46:55 -0800 | [diff] [blame] | 886 | } |
| 887 | |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 888 | status = pmo_ucfg_disable_arp_offload_in_fwr(adapter->hdd_vdev, trigger); |
| 889 | if (status == QDF_STATUS_SUCCESS) |
| 890 | hdd_wlan_offload_event(PMO_IPV4_ARP_REPLY_OFFLOAD, |
| 891 | PMO_OFFLOAD_DISABLE); |
| 892 | else |
| 893 | hdd_info("fail to disable arp offload"); |
| 894 | out: |
| 895 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 896 | } |
| 897 | |
Ravi Kumar Bokka | 794fd71 | 2017-03-21 20:52:46 +0530 | [diff] [blame^] | 898 | void hdd_enable_non_arp_hw_broadcast_filter(hdd_adapter_t *adapter) |
| 899 | { |
| 900 | QDF_STATUS status; |
| 901 | |
| 902 | ENTER(); |
| 903 | |
| 904 | status = pmo_ucfg_enable_non_arp_bcast_filter_in_fwr( |
| 905 | adapter->hdd_vdev); |
| 906 | |
| 907 | if (status != QDF_STATUS_SUCCESS) |
| 908 | hdd_info("Failed to enable broadcast filter"); |
| 909 | |
| 910 | EXIT(); |
| 911 | } |
| 912 | |
| 913 | void hdd_disable_non_arp_hw_broadcast_filter(hdd_adapter_t *adapter) |
| 914 | { |
| 915 | QDF_STATUS status; |
| 916 | |
| 917 | ENTER(); |
| 918 | |
| 919 | status = pmo_ucfg_disable_non_arp_bcast_filter_in_fwr( |
| 920 | adapter->hdd_vdev); |
| 921 | if (status != QDF_STATUS_SUCCESS) |
| 922 | hdd_info("Failed to disable broadcast filter"); |
| 923 | |
| 924 | EXIT(); |
| 925 | } |
| 926 | |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 927 | void hdd_enable_mc_addr_filtering(hdd_adapter_t *adapter, |
| 928 | enum pmo_offload_trigger trigger) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 929 | { |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 930 | hdd_context_t *hdd_ctx = (hdd_context_t *)adapter->pHddCtx; |
| 931 | QDF_STATUS status; |
| 932 | struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 933 | |
Ravi Joshi | 24477b7 | 2016-07-19 15:45:09 -0700 | [diff] [blame] | 934 | ENTER(); |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 935 | if (wlan_hdd_validate_context(hdd_ctx)) |
| 936 | goto out; |
Ravi Joshi | 24477b7 | 2016-07-19 15:45:09 -0700 | [diff] [blame] | 937 | |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 938 | status = pmo_ucfg_enable_mc_addr_filtering_in_fwr(psoc, |
| 939 | adapter->sessionId, trigger); |
| 940 | if (status != QDF_STATUS_SUCCESS) |
| 941 | hdd_info("failed to enable mc list status %d", status); |
| 942 | out: |
Ravi Joshi | 24477b7 | 2016-07-19 15:45:09 -0700 | [diff] [blame] | 943 | EXIT(); |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 944 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 945 | } |
Mukul Sharma | ff2ac2e | 2017-01-16 15:51:29 +0530 | [diff] [blame] | 946 | |
| 947 | void hdd_disable_mc_addr_filtering(hdd_adapter_t *adapter, |
| 948 | enum pmo_offload_trigger trigger) |
| 949 | { |
| 950 | hdd_context_t *hdd_ctx = (hdd_context_t *)adapter->pHddCtx; |
| 951 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 952 | struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc; |
| 953 | |
| 954 | ENTER(); |
| 955 | if (wlan_hdd_validate_context(hdd_ctx)) |
| 956 | goto out; |
| 957 | |
| 958 | status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc, |
| 959 | adapter->sessionId, trigger); |
| 960 | if (status != QDF_STATUS_SUCCESS) |
| 961 | hdd_info("failed to disable mc list status %d", status); |
| 962 | out: |
| 963 | EXIT(); |
| 964 | |
| 965 | } |
| 966 | |
| 967 | int hdd_cache_mc_addr_list(struct pmo_mc_addr_list_params *mc_list_config) |
| 968 | { |
| 969 | QDF_STATUS status; |
| 970 | int ret = 0; |
| 971 | |
| 972 | ENTER(); |
| 973 | /* cache mc addr list */ |
| 974 | status = pmo_ucfg_cache_mc_addr_list(mc_list_config); |
| 975 | if (status != QDF_STATUS_SUCCESS) { |
| 976 | hdd_info("fail to cache mc list status %d", status); |
| 977 | ret = -EINVAL; |
| 978 | } |
| 979 | EXIT(); |
| 980 | |
| 981 | return ret; |
| 982 | } |
| 983 | |
| 984 | void hdd_disable_and_flush_mc_addr_list(hdd_adapter_t *adapter, |
| 985 | enum pmo_offload_trigger trigger) |
| 986 | { |
| 987 | hdd_context_t *hdd_ctx = (hdd_context_t *)adapter->pHddCtx; |
| 988 | struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc; |
| 989 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 990 | |
| 991 | ENTER(); |
| 992 | /* disable mc list first */ |
| 993 | status = pmo_ucfg_disable_mc_addr_filtering_in_fwr(psoc, |
| 994 | adapter->sessionId, trigger); |
| 995 | if (status != QDF_STATUS_SUCCESS) |
| 996 | hdd_info("fail to disable mc list"); |
| 997 | |
| 998 | /* flush mc list */ |
| 999 | status = pmo_ucfg_flush_mc_addr_list(psoc, adapter->sessionId); |
| 1000 | if (status != QDF_STATUS_SUCCESS) |
| 1001 | hdd_info("fail to flush mc list status %d", status); |
| 1002 | EXIT(); |
| 1003 | |
| 1004 | return; |
| 1005 | |
| 1006 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1007 | |
| 1008 | /** |
Houston Hoffman | 7260ecb | 2015-10-05 18:43:07 -0700 | [diff] [blame] | 1009 | * hdd_update_conn_state_mask(): record info needed by wma_suspend_req |
| 1010 | * @adapter: adapter to get info from |
| 1011 | * @conn_state_mask: mask of connection info |
| 1012 | * |
| 1013 | * currently only need to send connection info. |
| 1014 | */ |
| 1015 | static void |
| 1016 | hdd_update_conn_state_mask(hdd_adapter_t *adapter, uint32_t *conn_state_mask) |
| 1017 | { |
| 1018 | |
| 1019 | eConnectionState connState; |
| 1020 | hdd_station_ctx_t *sta_ctx; |
| 1021 | sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter); |
| 1022 | connState = sta_ctx->conn_info.connState; |
| 1023 | |
| 1024 | if (connState == eConnectionState_Associated || |
| 1025 | connState == eConnectionState_IbssConnected) |
| 1026 | *conn_state_mask |= (1 << adapter->sessionId); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | /** |
| 1030 | * hdd_suspend_wlan() - Driver suspend function |
| 1031 | * @callback: Callback function to invoke when driver is ready to suspend |
| 1032 | * @callbackContext: Context to pass back to @callback function |
| 1033 | * |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1034 | * Return: 0 on success else error code. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1035 | */ |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1036 | static int |
| 1037 | hdd_suspend_wlan(void) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1038 | { |
| 1039 | hdd_context_t *pHddCtx; |
| 1040 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1041 | QDF_STATUS status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1042 | hdd_adapter_t *pAdapter = NULL; |
| 1043 | hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL; |
Houston Hoffman | 7260ecb | 2015-10-05 18:43:07 -0700 | [diff] [blame] | 1044 | uint32_t conn_state_mask = 0; |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1045 | hdd_info("WLAN being suspended by OS"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1046 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 1047 | pHddCtx = cds_get_context(QDF_MODULE_ID_HDD); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1048 | if (!pHddCtx) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1049 | hdd_err("HDD context is Null"); |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1050 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
Prashanth Bhatta | 9e14305 | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 1053 | if (cds_is_driver_recovering()) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1054 | hdd_info("Recovery in Progress. State: 0x%x Ignore suspend!!!", |
Prashanth Bhatta | 9e14305 | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 1055 | cds_get_driver_state()); |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1056 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | status = hdd_get_front_adapter(pHddCtx, &pAdapterNode); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1060 | while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1061 | pAdapter = pAdapterNode->pAdapter; |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1062 | if (wlan_hdd_validate_session_id(pAdapter->sessionId)) { |
| 1063 | hdd_err("invalid session id: %d", pAdapter->sessionId); |
| 1064 | goto next_adapter; |
| 1065 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1066 | |
| 1067 | /* stop all TX queues before suspend */ |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1068 | hdd_debug("Disabling queues"); |
Himanshu Agarwal | 865201d | 2017-04-12 15:45:31 +0530 | [diff] [blame] | 1069 | wlan_hdd_netif_queue_control(pAdapter, |
| 1070 | WLAN_STOP_ALL_NETIF_QUEUE, |
| 1071 | WLAN_CONTROL_PATH); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1072 | |
Houston Hoffman | 7260ecb | 2015-10-05 18:43:07 -0700 | [diff] [blame] | 1073 | /* Configure supported OffLoads */ |
Mukul Sharma | 3ba26b8 | 2017-01-12 21:59:41 +0530 | [diff] [blame] | 1074 | hdd_enable_host_offloads(pAdapter, pmo_apps_suspend); |
Houston Hoffman | 7260ecb | 2015-10-05 18:43:07 -0700 | [diff] [blame] | 1075 | hdd_update_conn_state_mask(pAdapter, &conn_state_mask); |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1076 | next_adapter: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1077 | status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext); |
| 1078 | pAdapterNode = pNext; |
| 1079 | } |
| 1080 | |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1081 | status = pmo_ucfg_psoc_user_space_suspend_req(pHddCtx->hdd_psoc, |
| 1082 | QDF_SYSTEM_SUSPEND); |
| 1083 | if (status != QDF_STATUS_SUCCESS) |
| 1084 | return -EAGAIN; |
Houston Hoffman | 7260ecb | 2015-10-05 18:43:07 -0700 | [diff] [blame] | 1085 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1086 | pHddCtx->hdd_wlan_suspended = true; |
Abhishek Singh | baea27d | 2016-04-27 13:29:30 +0530 | [diff] [blame] | 1087 | hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_SUSPEND); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1088 | |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1089 | return 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * hdd_resume_wlan() - Driver resume function |
| 1094 | * |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1095 | * Return: 0 on success else error code. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1096 | */ |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1097 | static int hdd_resume_wlan(void) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1098 | { |
| 1099 | hdd_context_t *pHddCtx; |
| 1100 | hdd_adapter_t *pAdapter = NULL; |
| 1101 | hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL; |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1102 | QDF_STATUS status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1103 | |
Dustin Brown | 2d22823 | 2016-09-22 15:06:19 -0700 | [diff] [blame] | 1104 | hdd_info("WLAN being resumed by OS"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1105 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 1106 | pHddCtx = cds_get_context(QDF_MODULE_ID_HDD); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1107 | if (!pHddCtx) { |
Dustin Brown | 2d22823 | 2016-09-22 15:06:19 -0700 | [diff] [blame] | 1108 | hdd_err("HDD context is Null"); |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1109 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Prashanth Bhatta | 9e14305 | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 1112 | if (cds_is_driver_recovering()) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1113 | hdd_info("Recovery in Progress. State: 0x%x Ignore resume!!!", |
Prashanth Bhatta | 9e14305 | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 1114 | cds_get_driver_state()); |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1115 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | pHddCtx->hdd_wlan_suspended = false; |
Abhishek Singh | baea27d | 2016-04-27 13:29:30 +0530 | [diff] [blame] | 1119 | hdd_wlan_suspend_resume_event(HDD_WLAN_EARLY_RESUME); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1120 | |
| 1121 | /*loop through all adapters. Concurrency */ |
| 1122 | status = hdd_get_front_adapter(pHddCtx, &pAdapterNode); |
| 1123 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1124 | while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1125 | pAdapter = pAdapterNode->pAdapter; |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1126 | if (wlan_hdd_validate_session_id(pAdapter->sessionId)) { |
| 1127 | hdd_err("invalid session id: %d", pAdapter->sessionId); |
| 1128 | goto next_adapter; |
| 1129 | } |
| 1130 | /* Disable supported OffLoads */ |
| 1131 | hdd_disable_host_offloads(pAdapter, pmo_apps_resume); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1132 | |
| 1133 | /* wake the tx queues */ |
Dustin Brown | 2d22823 | 2016-09-22 15:06:19 -0700 | [diff] [blame] | 1134 | hdd_info("Enabling queues"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1135 | wlan_hdd_netif_queue_control(pAdapter, |
| 1136 | WLAN_WAKE_ALL_NETIF_QUEUE, |
| 1137 | WLAN_CONTROL_PATH); |
| 1138 | |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1139 | next_adapter: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1140 | status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext); |
| 1141 | pAdapterNode = pNext; |
| 1142 | } |
| 1143 | hdd_ipa_resume(pHddCtx); |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1144 | status = pmo_ucfg_psoc_user_space_resume_req(pHddCtx->hdd_psoc, |
| 1145 | QDF_SYSTEM_SUSPEND); |
| 1146 | if (status != QDF_STATUS_SUCCESS) |
| 1147 | return -EAGAIN; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1148 | |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1149 | return 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /** |
| 1153 | * DOC: SSR Timer |
| 1154 | * |
| 1155 | * When SSR is initiated, an SSR timer is started. Under normal |
| 1156 | * circumstances SSR should complete amd the timer should be deleted |
| 1157 | * before it fires. If the SSR timer does fire, it indicates SSR has |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1158 | * taken too long, and our only recourse is to invoke the QDF_BUG() |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1159 | * API which can allow a crashdump to be captured. |
| 1160 | */ |
| 1161 | |
| 1162 | /** |
| 1163 | * hdd_ssr_timer_init() - Initialize SSR Timer |
| 1164 | * |
| 1165 | * Return: None. |
| 1166 | */ |
| 1167 | static void hdd_ssr_timer_init(void) |
| 1168 | { |
| 1169 | init_timer(&ssr_timer); |
| 1170 | } |
| 1171 | |
| 1172 | /** |
| 1173 | * hdd_ssr_timer_del() - Delete SSR Timer |
| 1174 | * |
| 1175 | * Return: None. |
| 1176 | */ |
| 1177 | static void hdd_ssr_timer_del(void) |
| 1178 | { |
| 1179 | del_timer(&ssr_timer); |
| 1180 | ssr_timer_started = false; |
| 1181 | } |
| 1182 | |
| 1183 | /** |
| 1184 | * hdd_ssr_timer_cb() - SSR Timer callback function |
| 1185 | * @data: opaque data registered with timer infrastructure |
| 1186 | * |
| 1187 | * Return: None. |
| 1188 | */ |
| 1189 | static void hdd_ssr_timer_cb(unsigned long data) |
| 1190 | { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1191 | hdd_info("HDD SSR timer expired!"); |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1192 | QDF_BUG(0); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * hdd_ssr_timer_start() - Start SSR Timer |
| 1197 | * @msec: Timer timeout value in milliseconds |
| 1198 | * |
| 1199 | * Return: None. |
| 1200 | */ |
| 1201 | static void hdd_ssr_timer_start(int msec) |
| 1202 | { |
| 1203 | if (ssr_timer_started) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1204 | hdd_debug("Trying to start SSR timer when " "it's running!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1205 | } |
| 1206 | ssr_timer.expires = jiffies + msecs_to_jiffies(msec); |
| 1207 | ssr_timer.function = hdd_ssr_timer_cb; |
| 1208 | add_timer(&ssr_timer); |
| 1209 | ssr_timer_started = true; |
| 1210 | } |
| 1211 | |
| 1212 | /** |
Komal Seelam | 78ff65a | 2016-08-18 15:25:24 +0530 | [diff] [blame] | 1213 | * hdd_svc_fw_shutdown_ind() - API to send FW SHUTDOWN IND to Userspace |
| 1214 | * |
| 1215 | * @dev: Device Pointer |
| 1216 | * |
| 1217 | * Return: None |
| 1218 | */ |
| 1219 | void hdd_svc_fw_shutdown_ind(struct device *dev) |
| 1220 | { |
| 1221 | hdd_context_t *hdd_ctx; |
| 1222 | v_CONTEXT_t g_context; |
| 1223 | |
| 1224 | g_context = cds_get_global_context(); |
| 1225 | |
| 1226 | if (!g_context) |
| 1227 | return; |
| 1228 | |
| 1229 | hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD); |
| 1230 | |
| 1231 | hdd_ctx ? wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index, |
| 1232 | WLAN_SVC_FW_SHUTDOWN_IND, |
| 1233 | NULL, 0) : 0; |
| 1234 | } |
| 1235 | |
| 1236 | /** |
Arun Khandavalli | cc544b3 | 2017-01-30 19:52:16 +0530 | [diff] [blame] | 1237 | * hdd_ssr_restart_sap() - restart sap on SSR |
| 1238 | * @hdd_ctx: hdd context |
| 1239 | * |
| 1240 | * Return: nothing |
| 1241 | */ |
| 1242 | static void hdd_ssr_restart_sap(hdd_context_t *hdd_ctx) |
| 1243 | { |
| 1244 | QDF_STATUS status; |
| 1245 | hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL; |
| 1246 | hdd_adapter_t *adapter; |
| 1247 | |
| 1248 | ENTER(); |
| 1249 | |
| 1250 | status = hdd_get_front_adapter(hdd_ctx, &adapter_node); |
| 1251 | while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) { |
| 1252 | adapter = adapter_node->pAdapter; |
| 1253 | if (adapter && adapter->device_mode == QDF_SAP_MODE) { |
Manikandan Mohan | 0a0ac95 | 2017-02-16 15:49:31 -0800 | [diff] [blame] | 1254 | if (test_bit(SOFTAP_INIT_DONE, &adapter->event_flags)) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1255 | hdd_debug("Restart prev SAP session"); |
Manikandan Mohan | 0a0ac95 | 2017-02-16 15:49:31 -0800 | [diff] [blame] | 1256 | wlan_hdd_start_sap(adapter, true); |
| 1257 | } |
Arun Khandavalli | cc544b3 | 2017-01-30 19:52:16 +0530 | [diff] [blame] | 1258 | } |
| 1259 | status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next); |
| 1260 | adapter_node = next; |
| 1261 | } |
| 1262 | |
| 1263 | EXIT(); |
| 1264 | } |
| 1265 | |
| 1266 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1267 | * hdd_wlan_shutdown() - HDD SSR shutdown function |
| 1268 | * |
| 1269 | * This function is called by the HIF to shutdown the driver during SSR. |
| 1270 | * |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1271 | * Return: QDF_STATUS_SUCCESS if the driver was shut down, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1272 | * or an error status otherwise |
| 1273 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1274 | QDF_STATUS hdd_wlan_shutdown(void) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1275 | { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1276 | v_CONTEXT_t p_cds_context = NULL; |
| 1277 | hdd_context_t *pHddCtx; |
| 1278 | p_cds_sched_context cds_sched_context = NULL; |
Prashanth Bhatta | 2ac92bd | 2016-10-11 16:08:00 -0700 | [diff] [blame] | 1279 | QDF_STATUS qdf_status; |
Manikandan Mohan | 8b4e201 | 2017-03-22 11:15:55 -0700 | [diff] [blame] | 1280 | void *soc = cds_get_context(QDF_MODULE_ID_SOC); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1281 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1282 | hdd_info("WLAN driver shutting down!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1283 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1284 | /* If SSR never completes, then do kernel panic. */ |
| 1285 | hdd_ssr_timer_init(); |
| 1286 | hdd_ssr_timer_start(HDD_SSR_BRING_UP_TIME); |
| 1287 | |
| 1288 | /* Get the global CDS context. */ |
| 1289 | p_cds_context = cds_get_global_context(); |
| 1290 | if (!p_cds_context) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1291 | hdd_err("Global CDS context is Null"); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1292 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | /* Get the HDD context. */ |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 1296 | pHddCtx = cds_get_context(QDF_MODULE_ID_HDD); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1297 | if (!pHddCtx) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1298 | hdd_err("HDD context is Null"); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1299 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1300 | } |
| 1301 | |
Tushnim Bhattacharyya | de1070d | 2017-03-09 13:23:55 -0800 | [diff] [blame] | 1302 | policy_mgr_clear_concurrent_session_count(pHddCtx->hdd_psoc); |
Himanshu Agarwal | f65bd4c | 2016-12-05 17:21:12 +0530 | [diff] [blame] | 1303 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1304 | hdd_debug("Invoking packetdump deregistration API"); |
Himanshu Agarwal | f65bd4c | 2016-12-05 17:21:12 +0530 | [diff] [blame] | 1305 | wlan_deregister_txrx_packetdump(); |
Sandeep Puligilla | 8de3c1c | 2017-04-13 17:56:18 -0700 | [diff] [blame] | 1306 | wlan_cfg80211_cleanup_scan_queue(pHddCtx->hdd_pdev); |
Govind Singh | 9c58eba | 2016-09-02 16:23:06 +0530 | [diff] [blame] | 1307 | hdd_ipa_uc_ssr_deinit(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1308 | hdd_reset_all_adapters(pHddCtx); |
| 1309 | |
Poddar, Siddarth | 1ab0a3d | 2016-09-29 18:58:45 +0530 | [diff] [blame] | 1310 | /* Flush cached rx frame queue */ |
Manikandan Mohan | 8b4e201 | 2017-03-22 11:15:55 -0700 | [diff] [blame] | 1311 | if (soc) |
| 1312 | cdp_flush_cache_rx_queue(soc); |
Poddar, Siddarth | 1ab0a3d | 2016-09-29 18:58:45 +0530 | [diff] [blame] | 1313 | |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 1314 | /* De-register the HDD callbacks */ |
| 1315 | hdd_deregister_cb(pHddCtx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1316 | |
| 1317 | cds_sched_context = get_cds_sched_ctxt(); |
| 1318 | |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1319 | if (pHddCtx->is_scheduler_suspended) { |
Rajeev Kumar | 0b73295 | 2016-12-08 17:51:39 -0800 | [diff] [blame] | 1320 | scheduler_resume(); |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1321 | pHddCtx->is_scheduler_suspended = false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1322 | } |
| 1323 | #ifdef QCA_CONFIG_SMP |
| 1324 | if (true == pHddCtx->is_ol_rx_thread_suspended) { |
| 1325 | complete(&cds_sched_context->ol_resume_rx_event); |
| 1326 | pHddCtx->is_ol_rx_thread_suspended = false; |
| 1327 | } |
| 1328 | #endif |
| 1329 | |
Prashanth Bhatta | 2ac92bd | 2016-10-11 16:08:00 -0700 | [diff] [blame] | 1330 | qdf_status = cds_sched_close(p_cds_context); |
| 1331 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
| 1332 | hdd_err("Failed to close CDS Scheduler"); |
| 1333 | QDF_ASSERT(false); |
| 1334 | } |
| 1335 | |
Nitesh Shah | 61c10d9 | 2016-10-19 19:29:15 +0530 | [diff] [blame] | 1336 | qdf_mc_timer_stop(&pHddCtx->tdls_source_timer); |
| 1337 | |
Prashanth Bhatta | ab00438 | 2016-10-11 16:08:11 -0700 | [diff] [blame] | 1338 | hdd_bus_bandwidth_destroy(pHddCtx); |
| 1339 | |
Rajeev Kumar | 3fef4e8 | 2017-03-31 20:25:23 -0700 | [diff] [blame] | 1340 | hdd_wlan_stop_modules(pHddCtx, false); |
Manishekar Chandrasekaran | f7a1dad | 2016-06-23 06:43:47 +0530 | [diff] [blame] | 1341 | |
Jeff Johnson | f7f66f0 | 2016-09-23 14:50:11 -0700 | [diff] [blame] | 1342 | hdd_lpass_notify_stop(pHddCtx); |
Yuanyuan Liu | 3e918e5 | 2016-08-17 15:41:35 -0700 | [diff] [blame] | 1343 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1344 | hdd_info("WLAN driver shutdown complete"); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1345 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1346 | } |
| 1347 | |
Sen, Devendra | 154b3c4 | 2017-02-13 20:44:15 +0530 | [diff] [blame] | 1348 | #ifdef FEATURE_WLAN_DIAG_SUPPORT |
| 1349 | /** |
| 1350 | * hdd_wlan_ssr_reinit_event()- send ssr reinit state |
| 1351 | * |
| 1352 | * This Function send send ssr reinit state diag event |
| 1353 | * |
| 1354 | * Return: void. |
| 1355 | */ |
| 1356 | static void hdd_wlan_ssr_reinit_event(void) |
| 1357 | { |
| 1358 | WLAN_HOST_DIAG_EVENT_DEF(ssr_reinit, struct host_event_wlan_ssr_reinit); |
| 1359 | qdf_mem_zero(&ssr_reinit, sizeof(ssr_reinit)); |
| 1360 | ssr_reinit.status = SSR_SUB_SYSTEM_REINIT; |
| 1361 | WLAN_HOST_DIAG_EVENT_REPORT(&ssr_reinit, |
| 1362 | EVENT_WLAN_SSR_REINIT_SUBSYSTEM); |
| 1363 | } |
| 1364 | #else |
| 1365 | static inline void hdd_wlan_ssr_reinit_event(void) |
| 1366 | { |
| 1367 | |
| 1368 | } |
| 1369 | #endif |
| 1370 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1371 | /** |
| 1372 | * hdd_wlan_re_init() - HDD SSR re-init function |
| 1373 | * |
| 1374 | * This function is called by the HIF to re-initialize the driver after SSR. |
| 1375 | * |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1376 | * Return: QDF_STATUS_SUCCESS if the driver was re-initialized, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1377 | * or an error status otherwise |
| 1378 | */ |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1379 | QDF_STATUS hdd_wlan_re_init(void) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1380 | { |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1381 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1382 | v_CONTEXT_t p_cds_context = NULL; |
| 1383 | hdd_context_t *pHddCtx = NULL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1384 | hdd_adapter_t *pAdapter; |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1385 | int ret; |
Mukul Sharma | f7d62e1 | 2016-09-03 15:16:22 +0530 | [diff] [blame] | 1386 | bool bug_on_reinit_failure = CFG_BUG_ON_REINIT_FAILURE_DEFAULT; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1387 | |
| 1388 | hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT); |
| 1389 | |
| 1390 | /* Get the CDS context */ |
| 1391 | p_cds_context = cds_get_global_context(); |
| 1392 | if (p_cds_context == NULL) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1393 | hdd_err("Failed cds_get_global_context"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1394 | goto err_re_init; |
| 1395 | } |
| 1396 | |
| 1397 | /* Get the HDD context */ |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 1398 | pHddCtx = cds_get_context(QDF_MODULE_ID_HDD); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1399 | if (!pHddCtx) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1400 | hdd_err("HDD context is Null"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1401 | goto err_re_init; |
| 1402 | } |
Mukul Sharma | f7d62e1 | 2016-09-03 15:16:22 +0530 | [diff] [blame] | 1403 | bug_on_reinit_failure = pHddCtx->config->bug_on_reinit_failure; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1404 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1405 | /* The driver should always be initialized in STA mode after SSR */ |
| 1406 | hdd_set_conparam(0); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1407 | /* Try to get an adapter from mode ID */ |
Krunal Soni | fb84cbd | 2016-03-10 13:09:07 -0800 | [diff] [blame] | 1408 | pAdapter = hdd_get_adapter(pHddCtx, QDF_STA_MODE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1409 | if (!pAdapter) { |
Krunal Soni | fb84cbd | 2016-03-10 13:09:07 -0800 | [diff] [blame] | 1410 | pAdapter = hdd_get_adapter(pHddCtx, QDF_SAP_MODE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1411 | if (!pAdapter) { |
Krunal Soni | fb84cbd | 2016-03-10 13:09:07 -0800 | [diff] [blame] | 1412 | pAdapter = hdd_get_adapter(pHddCtx, QDF_IBSS_MODE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1413 | if (!pAdapter) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1414 | hdd_err("Failed to get Adapter!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | |
Nirav Shah | cc1f1ae | 2016-04-26 11:41:29 +0530 | [diff] [blame] | 1419 | if (pHddCtx->config->enable_dp_trace) |
| 1420 | qdf_dp_trace_init(); |
| 1421 | |
Prashanth Bhatta | ab00438 | 2016-10-11 16:08:11 -0700 | [diff] [blame] | 1422 | hdd_bus_bandwidth_init(pHddCtx); |
| 1423 | |
Arun Khandavalli | cc544b3 | 2017-01-30 19:52:16 +0530 | [diff] [blame] | 1424 | |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1425 | ret = hdd_wlan_start_modules(pHddCtx, pAdapter, true); |
| 1426 | if (ret) { |
| 1427 | hdd_err("Failed to start wlan after error"); |
| 1428 | goto err_wiphy_unregister; |
| 1429 | } |
| 1430 | |
Arun Khandavalli | a96c2c0 | 2016-05-17 19:15:34 +0530 | [diff] [blame] | 1431 | hdd_wlan_get_version(pHddCtx, NULL, NULL); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1432 | |
Wu Gao | 3671743 | 2016-11-21 15:09:48 +0800 | [diff] [blame] | 1433 | wlan_hdd_send_svc_nlink_msg(pHddCtx->radio_index, |
| 1434 | WLAN_SVC_FW_CRASHED_IND, NULL, 0); |
| 1435 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1436 | /* Restart all adapters */ |
| 1437 | hdd_start_all_adapters(pHddCtx); |
| 1438 | |
Sreelakshmi Konamki | b53c629 | 2017-03-01 13:13:23 +0530 | [diff] [blame] | 1439 | pHddCtx->last_scan_reject_session_id = 0xFF; |
| 1440 | pHddCtx->last_scan_reject_reason = 0; |
| 1441 | pHddCtx->last_scan_reject_timestamp = 0; |
| 1442 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1443 | pHddCtx->btCoexModeSet = false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1444 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1445 | /* Allow the phone to go to sleep */ |
| 1446 | hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT); |
| 1447 | |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 1448 | ret = hdd_register_cb(pHddCtx); |
| 1449 | if (ret) { |
| 1450 | hdd_err("Failed to register HDD callbacks!"); |
Chandrasekaran Manishekar | cde33d7 | 2016-04-14 19:03:39 +0530 | [diff] [blame] | 1451 | goto err_cds_disable; |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 1452 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1453 | |
Jeff Johnson | 9afc501 | 2016-09-23 13:56:27 -0700 | [diff] [blame] | 1454 | hdd_lpass_notify_start(pHddCtx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1455 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1456 | hdd_info("WLAN host driver reinitiation completed!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1457 | goto success; |
| 1458 | |
| 1459 | err_cds_disable: |
Rajeev Kumar | 3fef4e8 | 2017-03-31 20:25:23 -0700 | [diff] [blame] | 1460 | hdd_wlan_stop_modules(pHddCtx, false); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1461 | |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1462 | err_wiphy_unregister: |
Ashish Kumar Dhanotiya | aa2b17c | 2017-03-29 00:41:32 +0530 | [diff] [blame] | 1463 | if (bug_on_reinit_failure) |
| 1464 | QDF_BUG(0); |
| 1465 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1466 | if (pHddCtx) { |
Ashish Kumar Dhanotiya | aa2b17c | 2017-03-29 00:41:32 +0530 | [diff] [blame] | 1467 | /* Unregister the Notifier's */ |
| 1468 | hdd_unregister_notifiers(pHddCtx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1469 | ptt_sock_deactivate_svc(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1470 | nl_srv_exit(); |
| 1471 | |
Ashish Kumar Dhanotiya | aa2b17c | 2017-03-29 00:41:32 +0530 | [diff] [blame] | 1472 | hdd_close_all_adapters(pHddCtx, false); |
| 1473 | wlan_hdd_cfg80211_deinit(pHddCtx->wiphy); |
| 1474 | hdd_lpass_notify_stop(pHddCtx); |
Nirav Shah | ed34b21 | 2016-04-25 10:59:16 +0530 | [diff] [blame] | 1475 | wlan_hdd_deinit_tx_rx_histogram(pHddCtx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1476 | wiphy_unregister(pHddCtx->wiphy); |
Ashish Kumar Dhanotiya | aa2b17c | 2017-03-29 00:41:32 +0530 | [diff] [blame] | 1477 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | err_re_init: |
Ashish Kumar Dhanotiya | aa2b17c | 2017-03-29 00:41:32 +0530 | [diff] [blame] | 1481 | hdd_ssr_timer_del(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1482 | /* Allow the phone to go to sleep */ |
| 1483 | hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DRIVER_REINIT); |
Mukul Sharma | f7d62e1 | 2016-09-03 15:16:22 +0530 | [diff] [blame] | 1484 | if (bug_on_reinit_failure) |
| 1485 | QDF_BUG(0); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1486 | return -EPERM; |
| 1487 | |
| 1488 | success: |
Arun Khandavalli | cc544b3 | 2017-01-30 19:52:16 +0530 | [diff] [blame] | 1489 | if (pHddCtx->config->sap_internal_restart) |
| 1490 | hdd_ssr_restart_sap(pHddCtx); |
Srinivas Girigowda | 02c084d | 2016-10-18 15:27:21 -0700 | [diff] [blame] | 1491 | hdd_ssr_timer_del(); |
Sen, Devendra | 154b3c4 | 2017-02-13 20:44:15 +0530 | [diff] [blame] | 1492 | hdd_wlan_ssr_reinit_event(); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1493 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | /** |
| 1497 | * wlan_hdd_set_powersave() - Set powersave mode |
| 1498 | * @adapter: adapter upon which the request was received |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1499 | * @allow_power_save: is wlan allowed to go into power save mode |
| 1500 | * @timeout: timeout period in ms |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1501 | * |
| 1502 | * Return: 0 on success, non-zero on any error |
| 1503 | */ |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1504 | static int wlan_hdd_set_powersave(hdd_adapter_t *adapter, |
| 1505 | bool allow_power_save, uint32_t timeout) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1506 | { |
| 1507 | tHalHandle hal; |
| 1508 | hdd_context_t *hdd_ctx; |
| 1509 | |
| 1510 | if (NULL == adapter) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1511 | hdd_err("Adapter NULL"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1512 | return -ENODEV; |
| 1513 | } |
| 1514 | |
| 1515 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 1516 | if (!hdd_ctx) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1517 | hdd_err("hdd context is NULL"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1518 | return -EINVAL; |
| 1519 | } |
| 1520 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1521 | hdd_debug("Allow power save: %d", allow_power_save); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1522 | hal = WLAN_HDD_GET_HAL_CTX(adapter); |
| 1523 | |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1524 | if (allow_power_save) { |
| 1525 | if (QDF_STA_MODE == adapter->device_mode || |
| 1526 | QDF_P2P_CLIENT_MODE == adapter->device_mode) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1527 | hdd_debug("Disabling Auto Power save timer"); |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1528 | sme_ps_disable_auto_ps_timer( |
| 1529 | WLAN_HDD_GET_HAL_CTX(adapter), |
| 1530 | adapter->sessionId); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1531 | } |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1532 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1533 | if (hdd_ctx->config && hdd_ctx->config->is_ps_enabled) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1534 | hdd_debug("Wlan driver Entering Power save"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1535 | |
| 1536 | /* |
| 1537 | * Enter Power Save command received from GUI |
| 1538 | * this means DHCP is completed |
| 1539 | */ |
| 1540 | sme_ps_enable_disable(hal, adapter->sessionId, |
| 1541 | SME_PS_ENABLE); |
| 1542 | } else { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1543 | hdd_debug("Power Save is not enabled in the cfg"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1544 | } |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1545 | } else { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1546 | hdd_debug("Wlan driver Entering Full Power"); |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1547 | |
| 1548 | /* |
| 1549 | * Enter Full power command received from GUI |
| 1550 | * this means we are disconnected |
| 1551 | */ |
| 1552 | sme_ps_disable_auto_ps_timer(WLAN_HDD_GET_HAL_CTX(adapter), |
| 1553 | adapter->sessionId); |
| 1554 | sme_ps_enable_disable(hal, adapter->sessionId, SME_PS_DISABLE); |
| 1555 | sme_ps_enable_auto_ps_timer(WLAN_HDD_GET_HAL_CTX(adapter), |
| 1556 | adapter->sessionId, timeout); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1557 | } |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1558 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1559 | return 0; |
| 1560 | } |
| 1561 | |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1562 | static void wlan_hdd_print_suspend_fail_stats(hdd_context_t *hdd_ctx) |
| 1563 | { |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1564 | struct suspend_resume_stats *stats = &hdd_ctx->suspend_resume_stats; |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1565 | hdd_err("ipa:%d, radar:%d, roam:%d, scan:%d, initial_wakeup:%d", |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1566 | stats->suspend_fail[SUSPEND_FAIL_IPA], |
| 1567 | stats->suspend_fail[SUSPEND_FAIL_RADAR], |
| 1568 | stats->suspend_fail[SUSPEND_FAIL_ROAM], |
| 1569 | stats->suspend_fail[SUSPEND_FAIL_SCAN], |
| 1570 | stats->suspend_fail[SUSPEND_FAIL_INITIAL_WAKEUP]); |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | void wlan_hdd_inc_suspend_stats(hdd_context_t *hdd_ctx, |
| 1574 | enum suspend_fail_reason reason) |
| 1575 | { |
| 1576 | wlan_hdd_print_suspend_fail_stats(hdd_ctx); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1577 | hdd_ctx->suspend_resume_stats.suspend_fail[reason]++; |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1578 | wlan_hdd_print_suspend_fail_stats(hdd_ctx); |
| 1579 | } |
| 1580 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1581 | /** |
| 1582 | * __wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback |
| 1583 | * @wiphy: Pointer to wiphy |
| 1584 | * |
| 1585 | * This API is called when cfg80211 driver resumes driver updates |
| 1586 | * latest sched_scan scan result(if any) to cfg80211 database |
| 1587 | * |
| 1588 | * Return: integer status |
| 1589 | */ |
| 1590 | static int __wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy) |
| 1591 | { |
| 1592 | hdd_context_t *pHddCtx = wiphy_priv(wiphy); |
| 1593 | hdd_adapter_t *pAdapter; |
| 1594 | hdd_adapter_list_node_t *pAdapterNode, *pNext; |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1595 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1596 | int exit_code; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1597 | p_cds_sched_context cds_sched_context = get_cds_sched_ctxt(); |
| 1598 | |
| 1599 | ENTER(); |
| 1600 | |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1601 | if (cds_is_driver_recovering()) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1602 | hdd_debug("Driver is recovering; Skipping resume"); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1603 | exit_code = 0; |
| 1604 | goto exit_with_code; |
| 1605 | } |
Prashanth Bhatta | 697dd0c | 2016-10-20 18:42:41 -0700 | [diff] [blame] | 1606 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 1607 | if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1608 | hdd_err("Command not allowed in FTM mode"); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1609 | exit_code = -EINVAL; |
| 1610 | goto exit_with_code; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1611 | } |
| 1612 | |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1613 | exit_code = wlan_hdd_validate_context(pHddCtx); |
| 1614 | if (exit_code) { |
| 1615 | hdd_err("Invalid HDD context"); |
| 1616 | goto exit_with_code; |
| 1617 | } |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1618 | |
| 1619 | mutex_lock(&pHddCtx->iface_change_lock); |
| 1620 | if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) { |
| 1621 | mutex_unlock(&pHddCtx->iface_change_lock); |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1622 | hdd_debug("Driver is not enabled; Skipping resume"); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1623 | exit_code = 0; |
| 1624 | goto exit_with_code; |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1625 | } |
| 1626 | mutex_unlock(&pHddCtx->iface_change_lock); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1627 | |
Yuanyuan Liu | 1373850 | 2016-04-06 17:41:37 -0700 | [diff] [blame] | 1628 | pld_request_bus_bandwidth(pHddCtx->parent_dev, PLD_BUS_WIDTH_MEDIUM); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1629 | |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1630 | status = hdd_resume_wlan(); |
| 1631 | if (status != QDF_STATUS_SUCCESS) { |
| 1632 | exit_code = 0; |
| 1633 | goto exit_with_code; |
| 1634 | } |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1635 | /* Resume control path scheduler */ |
| 1636 | if (pHddCtx->is_scheduler_suspended) { |
Rajeev Kumar | 0b73295 | 2016-12-08 17:51:39 -0800 | [diff] [blame] | 1637 | scheduler_resume(); |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1638 | pHddCtx->is_scheduler_suspended = false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1639 | } |
| 1640 | #ifdef QCA_CONFIG_SMP |
| 1641 | /* Resume tlshim Rx thread */ |
| 1642 | if (pHddCtx->is_ol_rx_thread_suspended) { |
| 1643 | complete(&cds_sched_context->ol_resume_rx_event); |
| 1644 | pHddCtx->is_ol_rx_thread_suspended = false; |
| 1645 | } |
| 1646 | #endif |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1647 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1648 | MTRACE(qdf_trace(QDF_MODULE_ID_HDD, |
Sreelakshmi Konamki | 6744cff | 2015-09-07 12:10:39 +0530 | [diff] [blame] | 1649 | TRACE_CODE_HDD_CFG80211_RESUME_WLAN, |
| 1650 | NO_SESSION, pHddCtx->isWiphySuspended)); |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 1651 | qdf_spin_lock(&pHddCtx->sched_scan_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1652 | pHddCtx->isWiphySuspended = false; |
| 1653 | if (true != pHddCtx->isSchedScanUpdatePending) { |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 1654 | qdf_spin_unlock(&pHddCtx->sched_scan_lock); |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1655 | hdd_debug("Return resume is not due to PNO indication"); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1656 | goto exit_with_success; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1657 | } |
| 1658 | /* Reset flag to avoid updatating cfg80211 data old results again */ |
| 1659 | pHddCtx->isSchedScanUpdatePending = false; |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 1660 | qdf_spin_unlock(&pHddCtx->sched_scan_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1661 | |
| 1662 | status = hdd_get_front_adapter(pHddCtx, &pAdapterNode); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1663 | while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1664 | pAdapter = pAdapterNode->pAdapter; |
| 1665 | if ((NULL != pAdapter) && |
Krunal Soni | fb84cbd | 2016-03-10 13:09:07 -0800 | [diff] [blame] | 1666 | (QDF_STA_MODE == pAdapter->device_mode)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1667 | if (0 != |
| 1668 | wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, |
| 1669 | pAdapter, 0)) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1670 | hdd_warn("NO SCAN result"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1671 | } else { |
| 1672 | /* Acquire wakelock to handle the case where |
| 1673 | * APP's tries to suspend immediately after |
| 1674 | * updating the scan results. Whis results in |
| 1675 | * app's is in suspended state and not able to |
| 1676 | * process the connect request to AP |
| 1677 | */ |
Sreelakshmi Konamki | 2252853 | 2016-09-06 16:34:50 +0530 | [diff] [blame] | 1678 | hdd_prevent_suspend_timeout( |
| 1679 | HDD_WAKE_LOCK_RESUME_DURATION, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1680 | WIFI_POWER_EVENT_WAKELOCK_RESUME_WLAN); |
| 1681 | cfg80211_sched_scan_results(pHddCtx->wiphy); |
| 1682 | } |
| 1683 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1684 | hdd_debug("cfg80211 scan result database updated"); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1685 | goto exit_with_success; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1686 | } |
| 1687 | status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext); |
| 1688 | pAdapterNode = pNext; |
| 1689 | } |
| 1690 | |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1691 | exit_with_success: |
| 1692 | pHddCtx->suspend_resume_stats.resumes++; |
| 1693 | exit_code = 0; |
| 1694 | |
| 1695 | exit_with_code: |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 1696 | EXIT(); |
Dustin Brown | d932248 | 2017-01-09 12:46:03 -0800 | [diff] [blame] | 1697 | return exit_code; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1701 | * wlan_hdd_cfg80211_resume_wlan() - cfg80211 resume callback |
| 1702 | * @wiphy: Pointer to wiphy |
| 1703 | * |
| 1704 | * This API is called when cfg80211 driver resumes driver updates |
| 1705 | * latest sched_scan scan result(if any) to cfg80211 database |
| 1706 | * |
| 1707 | * Return: integer status |
| 1708 | */ |
| 1709 | int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy) |
| 1710 | { |
| 1711 | int ret; |
| 1712 | |
| 1713 | cds_ssr_protect(__func__); |
| 1714 | ret = __wlan_hdd_cfg80211_resume_wlan(wiphy); |
| 1715 | cds_ssr_unprotect(__func__); |
| 1716 | |
| 1717 | return ret; |
| 1718 | } |
| 1719 | |
Krunal Soni | d32c6bc | 2016-10-18 18:00:21 -0700 | [diff] [blame] | 1720 | static void hdd_suspend_cb(void) |
| 1721 | { |
| 1722 | hdd_context_t *hdd_ctx; |
| 1723 | |
| 1724 | hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD); |
| 1725 | if (!hdd_ctx) { |
| 1726 | cds_err("HDD context is NULL"); |
| 1727 | return; |
| 1728 | } |
| 1729 | |
| 1730 | complete(&hdd_ctx->mc_sus_event_var); |
| 1731 | } |
| 1732 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1733 | /** |
| 1734 | * __wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback |
| 1735 | * @wiphy: Pointer to wiphy |
| 1736 | * @wow: Pointer to wow |
| 1737 | * |
| 1738 | * This API is called when cfg80211 driver suspends |
| 1739 | * |
| 1740 | * Return: integer status |
| 1741 | */ |
| 1742 | static int __wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy, |
| 1743 | struct cfg80211_wowlan *wow) |
| 1744 | { |
| 1745 | #ifdef QCA_CONFIG_SMP |
| 1746 | #define RX_TLSHIM_SUSPEND_TIMEOUT 200 /* msecs */ |
| 1747 | #endif |
| 1748 | hdd_context_t *pHddCtx = wiphy_priv(wiphy); |
| 1749 | p_cds_sched_context cds_sched_context = get_cds_sched_ctxt(); |
| 1750 | hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL; |
| 1751 | hdd_adapter_t *pAdapter; |
| 1752 | hdd_scaninfo_t *pScanInfo; |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1753 | QDF_STATUS status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1754 | int rc; |
| 1755 | |
| 1756 | ENTER(); |
| 1757 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 1758 | if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1759 | hdd_err("Command not allowed in FTM mode"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1760 | return -EINVAL; |
| 1761 | } |
| 1762 | |
| 1763 | rc = wlan_hdd_validate_context(pHddCtx); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 1764 | if (0 != rc) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1765 | return rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1766 | |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1767 | mutex_lock(&pHddCtx->iface_change_lock); |
| 1768 | if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) { |
| 1769 | mutex_unlock(&pHddCtx->iface_change_lock); |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1770 | hdd_debug("Driver Modules not Enabled "); |
Arun Khandavalli | fae9294 | 2016-08-01 13:31:08 +0530 | [diff] [blame] | 1771 | return 0; |
| 1772 | } |
| 1773 | mutex_unlock(&pHddCtx->iface_change_lock); |
| 1774 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1775 | /* If RADAR detection is in progress (HDD), prevent suspend. The flag |
| 1776 | * "dfs_cac_block_tx" is set to true when RADAR is found and stay true |
| 1777 | * until CAC is done for a SoftAP which is in started state. |
| 1778 | */ |
| 1779 | status = hdd_get_front_adapter(pHddCtx, &pAdapterNode); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1780 | while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1781 | pAdapter = pAdapterNode->pAdapter; |
Hanumanth Reddy Pothula | d9491f4 | 2016-10-24 19:08:38 +0530 | [diff] [blame] | 1782 | |
| 1783 | if (wlan_hdd_validate_session_id(pAdapter->sessionId)) { |
| 1784 | hdd_err("invalid session id: %d", pAdapter->sessionId); |
| 1785 | goto next_adapter; |
| 1786 | } |
| 1787 | |
Krunal Soni | fb84cbd | 2016-03-10 13:09:07 -0800 | [diff] [blame] | 1788 | if (QDF_SAP_MODE == pAdapter->device_mode) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1789 | if (BSS_START == |
| 1790 | WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter)->bssState && |
| 1791 | true == |
| 1792 | WLAN_HDD_GET_AP_CTX_PTR(pAdapter)-> |
| 1793 | dfs_cac_block_tx) { |
Dustin Brown | 2d22823 | 2016-09-22 15:06:19 -0700 | [diff] [blame] | 1794 | hdd_err("RADAR detection in progress, do not allow suspend"); |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1795 | wlan_hdd_inc_suspend_stats(pHddCtx, |
| 1796 | SUSPEND_FAIL_RADAR); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1797 | return -EAGAIN; |
| 1798 | } else if (!pHddCtx->config->enableSapSuspend) { |
| 1799 | /* return -EOPNOTSUPP if SAP does not support |
| 1800 | * suspend |
| 1801 | */ |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1802 | hdd_err("SAP does not support suspend!!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1803 | return -EOPNOTSUPP; |
| 1804 | } |
Krunal Soni | fb84cbd | 2016-03-10 13:09:07 -0800 | [diff] [blame] | 1805 | } else if (QDF_P2P_GO_MODE == pAdapter->device_mode) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1806 | if (!pHddCtx->config->enableSapSuspend) { |
| 1807 | /* return -EOPNOTSUPP if GO does not support |
| 1808 | * suspend |
| 1809 | */ |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1810 | hdd_err("GO does not support suspend!!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1811 | return -EOPNOTSUPP; |
| 1812 | } |
| 1813 | } |
Masti, Narayanraddi | 3e26de6 | 2016-08-19 14:33:22 +0530 | [diff] [blame] | 1814 | if (pAdapter->is_roc_inprogress) |
| 1815 | wlan_hdd_cleanup_remain_on_channel_ctx(pAdapter); |
Hanumanth Reddy Pothula | d9491f4 | 2016-10-24 19:08:38 +0530 | [diff] [blame] | 1816 | next_adapter: |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1817 | status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext); |
| 1818 | pAdapterNode = pNext; |
| 1819 | } |
| 1820 | |
| 1821 | /* Stop ongoing scan on each interface */ |
| 1822 | status = hdd_get_front_adapter(pHddCtx, &pAdapterNode); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1823 | while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1824 | pAdapter = pAdapterNode->pAdapter; |
| 1825 | pScanInfo = &pAdapter->scan_info; |
| 1826 | |
Sandeep Puligilla | f852712 | 2016-11-16 18:35:16 -0800 | [diff] [blame] | 1827 | if (sme_neighbor_middle_of_roaming |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1828 | (pHddCtx->hHal, pAdapter->sessionId)) { |
Dustin Brown | 2d22823 | 2016-09-22 15:06:19 -0700 | [diff] [blame] | 1829 | hdd_err("Roaming in progress, do not allow suspend"); |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1830 | wlan_hdd_inc_suspend_stats(pHddCtx, |
| 1831 | SUSPEND_FAIL_ROAM); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1832 | return -EAGAIN; |
| 1833 | } |
| 1834 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1835 | if (pScanInfo->mScanPending) { |
| 1836 | INIT_COMPLETION(pScanInfo->abortscan_event_var); |
| 1837 | hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId, |
yeshwanth sriram guntuka | 310b3ac | 2016-11-15 23:25:26 +0530 | [diff] [blame] | 1838 | INVALID_SCAN_ID, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1839 | eCSR_SCAN_ABORT_DEFAULT); |
| 1840 | |
| 1841 | status = |
| 1842 | wait_for_completion_timeout(&pScanInfo-> |
| 1843 | abortscan_event_var, |
| 1844 | msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN)); |
| 1845 | if (!status) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1846 | hdd_err("Timeout occurred while waiting for abort scan"); |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1847 | wlan_hdd_inc_suspend_stats(pHddCtx, |
| 1848 | SUSPEND_FAIL_SCAN); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1849 | return -ETIME; |
| 1850 | } |
| 1851 | } |
| 1852 | status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext); |
| 1853 | pAdapterNode = pNext; |
| 1854 | } |
| 1855 | |
| 1856 | /* |
| 1857 | * Suspend IPA early before proceeding to suspend other entities like |
| 1858 | * firmware to avoid any race conditions. |
| 1859 | */ |
| 1860 | if (hdd_ipa_suspend(pHddCtx)) { |
Dustin Brown | 2d22823 | 2016-09-22 15:06:19 -0700 | [diff] [blame] | 1861 | hdd_err("IPA not ready to suspend!"); |
Dustin Brown | 105d790 | 2016-10-03 16:27:59 -0700 | [diff] [blame] | 1862 | wlan_hdd_inc_suspend_stats(pHddCtx, SUSPEND_FAIL_IPA); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1863 | return -EAGAIN; |
| 1864 | } |
| 1865 | |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1866 | /* Suspend control path scheduler */ |
Krunal Soni | d32c6bc | 2016-10-18 18:00:21 -0700 | [diff] [blame] | 1867 | scheduler_register_hdd_suspend_callback(hdd_suspend_cb); |
Manjeet Singh | 1a376ce | 2016-10-06 19:31:10 +0530 | [diff] [blame] | 1868 | scheduler_set_event_mask(MC_SUSPEND_EVENT); |
Krunal Soni | d32c6bc | 2016-10-18 18:00:21 -0700 | [diff] [blame] | 1869 | scheduler_wake_up_controller_thread(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1870 | |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1871 | /* Wait for suspend confirmation from scheduler */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1872 | rc = wait_for_completion_timeout(&pHddCtx->mc_sus_event_var, |
| 1873 | msecs_to_jiffies(WLAN_WAIT_TIME_MCTHREAD_SUSPEND)); |
| 1874 | if (!rc) { |
Manjeet Singh | 1a376ce | 2016-10-06 19:31:10 +0530 | [diff] [blame] | 1875 | scheduler_clear_event_mask(MC_SUSPEND_EVENT); |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1876 | hdd_err("Failed to stop mc thread"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1877 | goto resume_tx; |
| 1878 | } |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1879 | pHddCtx->is_scheduler_suspended = true; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1880 | |
| 1881 | #ifdef QCA_CONFIG_SMP |
| 1882 | /* Suspend tlshim rx thread */ |
Manjeet Singh | 1a376ce | 2016-10-06 19:31:10 +0530 | [diff] [blame] | 1883 | set_bit(RX_SUSPEND_EVENT, &cds_sched_context->ol_rx_event_flag); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1884 | wake_up_interruptible(&cds_sched_context->ol_rx_wait_queue); |
| 1885 | rc = wait_for_completion_timeout(&cds_sched_context-> |
| 1886 | ol_suspend_rx_event, |
| 1887 | msecs_to_jiffies |
| 1888 | (RX_TLSHIM_SUSPEND_TIMEOUT)); |
| 1889 | if (!rc) { |
Manjeet Singh | 1a376ce | 2016-10-06 19:31:10 +0530 | [diff] [blame] | 1890 | clear_bit(RX_SUSPEND_EVENT, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1891 | &cds_sched_context->ol_rx_event_flag); |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 1892 | hdd_err("Failed to stop tl_shim rx thread"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1893 | goto resume_all; |
| 1894 | } |
| 1895 | pHddCtx->is_ol_rx_thread_suspended = true; |
| 1896 | #endif |
Mukul Sharma | 4c60a7e | 2017-03-06 19:42:18 +0530 | [diff] [blame] | 1897 | if (hdd_suspend_wlan() < 0) |
| 1898 | goto resume_all; |
| 1899 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 1900 | MTRACE(qdf_trace(QDF_MODULE_ID_HDD, |
Sreelakshmi Konamki | 6744cff | 2015-09-07 12:10:39 +0530 | [diff] [blame] | 1901 | TRACE_CODE_HDD_CFG80211_SUSPEND_WLAN, |
| 1902 | NO_SESSION, pHddCtx->isWiphySuspended)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1903 | pHddCtx->isWiphySuspended = true; |
| 1904 | |
Yuanyuan Liu | 1373850 | 2016-04-06 17:41:37 -0700 | [diff] [blame] | 1905 | pld_request_bus_bandwidth(pHddCtx->parent_dev, PLD_BUS_WIDTH_NONE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1906 | |
| 1907 | EXIT(); |
| 1908 | return 0; |
| 1909 | |
| 1910 | #ifdef QCA_CONFIG_SMP |
| 1911 | resume_all: |
| 1912 | |
Rajeev Kumar | 0b73295 | 2016-12-08 17:51:39 -0800 | [diff] [blame] | 1913 | scheduler_resume(); |
Rajeev Kumar | eada0d0 | 2016-12-08 17:44:17 -0800 | [diff] [blame] | 1914 | pHddCtx->is_scheduler_suspended = false; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1915 | #endif |
| 1916 | |
| 1917 | resume_tx: |
| 1918 | |
| 1919 | hdd_resume_wlan(); |
| 1920 | return -ETIME; |
| 1921 | |
| 1922 | } |
| 1923 | |
| 1924 | /** |
| 1925 | * wlan_hdd_cfg80211_suspend_wlan() - cfg80211 suspend callback |
| 1926 | * @wiphy: Pointer to wiphy |
| 1927 | * @wow: Pointer to wow |
| 1928 | * |
| 1929 | * This API is called when cfg80211 driver suspends |
| 1930 | * |
| 1931 | * Return: integer status |
| 1932 | */ |
| 1933 | int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy, |
| 1934 | struct cfg80211_wowlan *wow) |
| 1935 | { |
| 1936 | int ret; |
| 1937 | |
| 1938 | cds_ssr_protect(__func__); |
| 1939 | ret = __wlan_hdd_cfg80211_suspend_wlan(wiphy, wow); |
| 1940 | cds_ssr_unprotect(__func__); |
| 1941 | |
| 1942 | return ret; |
| 1943 | } |
| 1944 | |
| 1945 | /** |
Komal Seelam | a89be8d | 2016-09-29 11:09:26 +0530 | [diff] [blame] | 1946 | * hdd_stop_dhcp_ind() - API to stop DHCP sequence |
| 1947 | * @adapter: Adapter on which DHCP needs to be stopped |
| 1948 | * |
| 1949 | * Release the wakelock held for DHCP process and allow |
| 1950 | * the runtime pm to continue |
| 1951 | * |
| 1952 | * Return: None |
| 1953 | */ |
| 1954 | static void hdd_stop_dhcp_ind(hdd_adapter_t *adapter) |
| 1955 | { |
| 1956 | hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 1957 | |
Srinivas Girigowda | c06543c | 2017-03-09 15:10:03 -0800 | [diff] [blame] | 1958 | hdd_debug("DHCP stop indicated through power save"); |
Komal Seelam | a89be8d | 2016-09-29 11:09:26 +0530 | [diff] [blame] | 1959 | sme_dhcp_stop_ind(hdd_ctx->hHal, adapter->device_mode, |
| 1960 | adapter->macAddressCurrent.bytes, |
| 1961 | adapter->sessionId); |
| 1962 | hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_DHCP); |
| 1963 | qdf_runtime_pm_allow_suspend(adapter->connect_rpm_ctx.connect); |
| 1964 | } |
| 1965 | |
| 1966 | /** |
| 1967 | * hdd_start_dhcp_ind() - API to start DHCP sequence |
| 1968 | * @adapter: Adapter on which DHCP needs to be stopped |
| 1969 | * |
| 1970 | * Prevent APPS suspend and the runtime suspend during |
| 1971 | * DHCP sequence |
| 1972 | * |
| 1973 | * Return: None |
| 1974 | */ |
| 1975 | static void hdd_start_dhcp_ind(hdd_adapter_t *adapter) |
| 1976 | { |
| 1977 | hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 1978 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 1979 | hdd_debug("DHCP start indicated through power save"); |
Komal Seelam | a89be8d | 2016-09-29 11:09:26 +0530 | [diff] [blame] | 1980 | qdf_runtime_pm_prevent_suspend(adapter->connect_rpm_ctx.connect); |
| 1981 | hdd_prevent_suspend_timeout(1000, WIFI_POWER_EVENT_WAKELOCK_DHCP); |
| 1982 | sme_dhcp_start_ind(hdd_ctx->hHal, adapter->device_mode, |
| 1983 | adapter->macAddressCurrent.bytes, |
| 1984 | adapter->sessionId); |
| 1985 | } |
| 1986 | |
| 1987 | /** |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1988 | * __wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config |
| 1989 | * @wiphy: Pointer to wiphy |
| 1990 | * @dev: Pointer to network device |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1991 | * @allow_power_save: is wlan allowed to go into power save mode |
| 1992 | * @timeout: Timeout value in ms |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1993 | * |
| 1994 | * Return: 0 for success, non-zero for failure |
| 1995 | */ |
| 1996 | static int __wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy, |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 1997 | struct net_device *dev, |
| 1998 | bool allow_power_save, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1999 | int timeout) |
| 2000 | { |
| 2001 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 2002 | hdd_context_t *pHddCtx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2003 | int status; |
| 2004 | |
Dustin Brown | ecfce63 | 2016-09-13 10:41:45 -0700 | [diff] [blame] | 2005 | ENTER(); |
| 2006 | |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 2007 | if (timeout < 0) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2008 | hdd_debug("User space timeout: %d; Using default instead: %d", |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 2009 | timeout, AUTO_PS_ENTRY_USER_TIMER_DEFAULT_VALUE); |
| 2010 | timeout = AUTO_PS_ENTRY_USER_TIMER_DEFAULT_VALUE; |
| 2011 | } |
| 2012 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 2013 | if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 2014 | hdd_err("Command not allowed in FTM mode"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2015 | return -EINVAL; |
| 2016 | } |
| 2017 | |
Hanumanth Reddy Pothula | d9491f4 | 2016-10-24 19:08:38 +0530 | [diff] [blame] | 2018 | if (wlan_hdd_validate_session_id(pAdapter->sessionId)) { |
| 2019 | hdd_err("invalid session id: %d", pAdapter->sessionId); |
| 2020 | return -EINVAL; |
| 2021 | } |
| 2022 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2023 | MTRACE(qdf_trace(QDF_MODULE_ID_HDD, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2024 | TRACE_CODE_HDD_CFG80211_SET_POWER_MGMT, |
| 2025 | pAdapter->sessionId, timeout)); |
| 2026 | |
| 2027 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 2028 | status = wlan_hdd_validate_context(pHddCtx); |
| 2029 | |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 2030 | if (0 != status) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2031 | return status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2032 | |
Arun Khandavalli | 9928645 | 2016-08-22 12:13:41 +0530 | [diff] [blame] | 2033 | mutex_lock(&pHddCtx->iface_change_lock); |
| 2034 | if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) { |
| 2035 | mutex_unlock(&pHddCtx->iface_change_lock); |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2036 | hdd_debug("Driver Module not enabled return success"); |
Arun Khandavalli | 9928645 | 2016-08-22 12:13:41 +0530 | [diff] [blame] | 2037 | return 0; |
| 2038 | } |
| 2039 | mutex_unlock(&pHddCtx->iface_change_lock); |
| 2040 | |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 2041 | status = wlan_hdd_set_powersave(pAdapter, allow_power_save, timeout); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2042 | |
Komal Seelam | a89be8d | 2016-09-29 11:09:26 +0530 | [diff] [blame] | 2043 | allow_power_save ? hdd_stop_dhcp_ind(pAdapter) : |
| 2044 | hdd_start_dhcp_ind(pAdapter); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2045 | |
| 2046 | EXIT(); |
| 2047 | return status; |
| 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * wlan_hdd_cfg80211_set_power_mgmt() - set cfg80211 power management config |
| 2052 | * @wiphy: Pointer to wiphy |
| 2053 | * @dev: Pointer to network device |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 2054 | * @allow_power_save: is wlan allowed to go into power save mode |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2055 | * @timeout: Timeout value |
| 2056 | * |
| 2057 | * Return: 0 for success, non-zero for failure |
| 2058 | */ |
| 2059 | int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy, |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 2060 | struct net_device *dev, |
| 2061 | bool allow_power_save, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2062 | int timeout) |
| 2063 | { |
| 2064 | int ret; |
| 2065 | |
| 2066 | cds_ssr_protect(__func__); |
Dustin Brown | f660fb4 | 2016-09-09 12:04:00 -0700 | [diff] [blame] | 2067 | ret = __wlan_hdd_cfg80211_set_power_mgmt(wiphy, dev, |
| 2068 | allow_power_save, timeout); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2069 | cds_ssr_unprotect(__func__); |
| 2070 | |
| 2071 | return ret; |
| 2072 | } |
| 2073 | |
| 2074 | /** |
| 2075 | * __wlan_hdd_cfg80211_set_txpower() - set TX power |
| 2076 | * @wiphy: Pointer to wiphy |
| 2077 | * @wdev: Pointer to network device |
| 2078 | * @type: TX power setting type |
| 2079 | * @dbm: TX power in dbm |
| 2080 | * |
| 2081 | * Return: 0 for success, non-zero for failure |
| 2082 | */ |
| 2083 | static int __wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2084 | struct wireless_dev *wdev, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2085 | enum nl80211_tx_power_setting type, |
| 2086 | int dbm) |
| 2087 | { |
| 2088 | hdd_context_t *pHddCtx = (hdd_context_t *) wiphy_priv(wiphy); |
| 2089 | tHalHandle hHal = NULL; |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 2090 | struct qdf_mac_addr bssid = QDF_MAC_ADDR_BROADCAST_INITIALIZER; |
| 2091 | struct qdf_mac_addr selfMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2092 | int status; |
| 2093 | |
| 2094 | ENTER(); |
| 2095 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 2096 | if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 2097 | hdd_err("Command not allowed in FTM mode"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2098 | return -EINVAL; |
| 2099 | } |
| 2100 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2101 | MTRACE(qdf_trace(QDF_MODULE_ID_HDD, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2102 | TRACE_CODE_HDD_CFG80211_SET_TXPOWER, |
| 2103 | NO_SESSION, type)); |
| 2104 | |
| 2105 | status = wlan_hdd_validate_context(pHddCtx); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 2106 | if (0 != status) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2107 | return status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2108 | |
| 2109 | hHal = pHddCtx->hHal; |
| 2110 | |
| 2111 | if (0 != sme_cfg_set_int(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL, dbm)) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 2112 | hdd_err("sme_cfg_set_int failed for tx power %hu", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2113 | dbm); |
| 2114 | return -EIO; |
| 2115 | } |
| 2116 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2117 | hdd_debug("Set tx power level %d dbm", dbm); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2118 | |
| 2119 | switch (type) { |
| 2120 | /* Automatically determine transmit power */ |
| 2121 | case NL80211_TX_POWER_AUTOMATIC: |
| 2122 | /* Fall through */ |
| 2123 | case NL80211_TX_POWER_LIMITED: /* Limit TX power by the mBm parameter */ |
| 2124 | if (sme_set_max_tx_power(hHal, bssid, selfMac, dbm) != |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 2125 | QDF_STATUS_SUCCESS) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 2126 | hdd_err("Setting maximum tx power failed"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2127 | return -EIO; |
| 2128 | } |
| 2129 | break; |
| 2130 | |
| 2131 | case NL80211_TX_POWER_FIXED: /* Fix TX power to the mBm parameter */ |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 2132 | hdd_err("NL80211_TX_POWER_FIXED not supported"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2133 | return -EOPNOTSUPP; |
| 2134 | break; |
| 2135 | |
| 2136 | default: |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 2137 | hdd_err("Invalid power setting type %d", type); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2138 | return -EIO; |
| 2139 | } |
| 2140 | |
| 2141 | EXIT(); |
| 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * wlan_hdd_cfg80211_set_txpower() - set TX power |
| 2147 | * @wiphy: Pointer to wiphy |
| 2148 | * @wdev: Pointer to network device |
| 2149 | * @type: TX power setting type |
| 2150 | * @dbm: TX power in dbm |
| 2151 | * |
| 2152 | * Return: 0 for success, non-zero for failure |
| 2153 | */ |
| 2154 | int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2155 | struct wireless_dev *wdev, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2156 | enum nl80211_tx_power_setting type, |
| 2157 | int dbm) |
| 2158 | { |
| 2159 | int ret; |
| 2160 | cds_ssr_protect(__func__); |
| 2161 | ret = __wlan_hdd_cfg80211_set_txpower(wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2162 | wdev, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2163 | type, dbm); |
| 2164 | cds_ssr_unprotect(__func__); |
| 2165 | |
| 2166 | return ret; |
| 2167 | } |
| 2168 | |
| 2169 | /** |
| 2170 | * __wlan_hdd_cfg80211_get_txpower() - get TX power |
| 2171 | * @wiphy: Pointer to wiphy |
| 2172 | * @wdev: Pointer to network device |
| 2173 | * @dbm: Pointer to TX power in dbm |
| 2174 | * |
| 2175 | * Return: 0 for success, non-zero for failure |
| 2176 | */ |
| 2177 | static int __wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2178 | struct wireless_dev *wdev, |
Srinivas Girigowda | 86ecc01 | 2017-03-10 12:26:57 -0800 | [diff] [blame] | 2179 | int *dbm, hdd_adapter_t *adapter) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2180 | { |
| 2181 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2182 | hdd_context_t *pHddCtx = (hdd_context_t *) wiphy_priv(wiphy); |
| 2183 | int status; |
| 2184 | |
| 2185 | ENTER(); |
| 2186 | |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 2187 | if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Jeff Johnson | c327332 | 2016-07-06 15:28:17 -0700 | [diff] [blame] | 2188 | hdd_err("Command not allowed in FTM mode"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2189 | return -EINVAL; |
| 2190 | } |
| 2191 | |
| 2192 | status = wlan_hdd_validate_context(pHddCtx); |
| 2193 | if (0 != status) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2194 | *dbm = 0; |
| 2195 | return status; |
| 2196 | } |
| 2197 | |
Arun Khandavalli | 9928645 | 2016-08-22 12:13:41 +0530 | [diff] [blame] | 2198 | /* Validate adapter sessionId */ |
Hanumanth Reddy Pothula | d9491f4 | 2016-10-24 19:08:38 +0530 | [diff] [blame] | 2199 | if (wlan_hdd_validate_session_id(adapter->sessionId)) { |
| 2200 | hdd_err("invalid session id: %d", adapter->sessionId); |
Arun Khandavalli | 9928645 | 2016-08-22 12:13:41 +0530 | [diff] [blame] | 2201 | return -ENOTSUPP; |
| 2202 | } |
| 2203 | |
| 2204 | mutex_lock(&pHddCtx->iface_change_lock); |
| 2205 | if (pHddCtx->driver_status != DRIVER_MODULES_ENABLED) { |
| 2206 | mutex_unlock(&pHddCtx->iface_change_lock); |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2207 | hdd_debug("Driver Module not enabled return success"); |
Arun Khandavalli | 9928645 | 2016-08-22 12:13:41 +0530 | [diff] [blame] | 2208 | /* Send cached data to upperlayer*/ |
| 2209 | *dbm = adapter->hdd_stats.ClassA_stat.max_pwr; |
| 2210 | return 0; |
| 2211 | } |
| 2212 | mutex_unlock(&pHddCtx->iface_change_lock); |
| 2213 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 2214 | MTRACE(qdf_trace(QDF_MODULE_ID_HDD, |
Sreelakshmi Konamki | 6744cff | 2015-09-07 12:10:39 +0530 | [diff] [blame] | 2215 | TRACE_CODE_HDD_CFG80211_GET_TXPOWER, |
Arun Khandavalli | 9928645 | 2016-08-22 12:13:41 +0530 | [diff] [blame] | 2216 | adapter->sessionId, adapter->device_mode)); |
| 2217 | wlan_hdd_get_class_astats(adapter); |
| 2218 | *dbm = adapter->hdd_stats.ClassA_stat.max_pwr; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2219 | |
| 2220 | EXIT(); |
| 2221 | return 0; |
| 2222 | } |
| 2223 | |
| 2224 | /** |
| 2225 | * wlan_hdd_cfg80211_get_txpower() - cfg80211 get power handler function |
| 2226 | * @wiphy: Pointer to wiphy structure. |
| 2227 | * @wdev: Pointer to wireless_dev structure. |
| 2228 | * @dbm: dbm |
| 2229 | * |
| 2230 | * This is the cfg80211 get txpower handler function which invokes |
| 2231 | * the internal function @__wlan_hdd_cfg80211_get_txpower with |
| 2232 | * SSR protection. |
| 2233 | * |
| 2234 | * Return: 0 for success, error number on failure. |
| 2235 | */ |
| 2236 | int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2237 | struct wireless_dev *wdev, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2238 | int *dbm) |
| 2239 | { |
Srinivas Girigowda | 86ecc01 | 2017-03-10 12:26:57 -0800 | [diff] [blame] | 2240 | int ret = -ENOTSUPP; |
| 2241 | struct net_device *ndev = wdev->netdev; |
| 2242 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(ndev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2243 | |
| 2244 | cds_ssr_protect(__func__); |
Srinivas Girigowda | 86ecc01 | 2017-03-10 12:26:57 -0800 | [diff] [blame] | 2245 | if (adapter->sessionId != HDD_SESSION_ID_INVALID) |
| 2246 | ret = __wlan_hdd_cfg80211_get_txpower(wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2247 | wdev, |
Srinivas Girigowda | 86ecc01 | 2017-03-10 12:26:57 -0800 | [diff] [blame] | 2248 | dbm, adapter); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2249 | cds_ssr_unprotect(__func__); |
| 2250 | |
| 2251 | return ret; |
| 2252 | } |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2253 | |
| 2254 | /** |
| 2255 | * hdd_set_qpower_config() - set qpower config to firmware |
| 2256 | * @adapter: HDD adapter |
| 2257 | * @qpower: new qpower config value |
| 2258 | * |
| 2259 | * Return: 0 on success; Errno on failure |
| 2260 | */ |
| 2261 | int hdd_set_qpower_config(hdd_context_t *hddctx, hdd_adapter_t *adapter, |
Dustin Brown | 10a7b71 | 2016-10-07 10:31:16 -0700 | [diff] [blame] | 2262 | u8 qpower) |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2263 | { |
Dustin Brown | 10a7b71 | 2016-10-07 10:31:16 -0700 | [diff] [blame] | 2264 | QDF_STATUS status; |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2265 | |
| 2266 | if (!hddctx->config->enablePowersaveOffload) { |
| 2267 | hdd_err("qpower is disabled in configuration"); |
| 2268 | return -EINVAL; |
| 2269 | } |
Dustin Brown | 10a7b71 | 2016-10-07 10:31:16 -0700 | [diff] [blame] | 2270 | |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2271 | if (qpower > PS_DUTY_CYCLING_QPOWER || |
| 2272 | qpower < PS_LEGACY_NODEEPSLEEP) { |
Dustin Brown | 10a7b71 | 2016-10-07 10:31:16 -0700 | [diff] [blame] | 2273 | hdd_err("invalid qpower value: %d", qpower); |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2274 | return -EINVAL; |
| 2275 | } |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2276 | |
Kiran Kumar Lokere | 7006e0a | 2017-03-07 19:28:36 -0800 | [diff] [blame] | 2277 | if (hddctx->config->nMaxPsPoll) { |
| 2278 | if ((qpower == PS_QPOWER_NODEEPSLEEP) || |
| 2279 | (qpower == PS_LEGACY_NODEEPSLEEP)) |
| 2280 | qpower = PS_LEGACY_NODEEPSLEEP; |
| 2281 | else |
| 2282 | qpower = PS_LEGACY_DEEPSLEEP; |
| 2283 | hdd_info("Qpower disabled, %d", qpower); |
| 2284 | } |
Dustin Brown | 10a7b71 | 2016-10-07 10:31:16 -0700 | [diff] [blame] | 2285 | status = wma_set_qpower_config(adapter->sessionId, qpower); |
| 2286 | if (status != QDF_STATUS_SUCCESS) { |
| 2287 | hdd_err("failed to configure qpower: %d", status); |
| 2288 | return -EINVAL; |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2289 | } |
Dustin Brown | 10a7b71 | 2016-10-07 10:31:16 -0700 | [diff] [blame] | 2290 | |
Kapil Gupta | 6213c01 | 2016-09-02 19:39:09 +0530 | [diff] [blame] | 2291 | return 0; |
| 2292 | } |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2293 | |
Dustin Brown | 5409643 | 2017-02-23 13:00:44 -0800 | [diff] [blame] | 2294 | |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2295 | #ifdef WLAN_SUSPEND_RESUME_TEST |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2296 | static struct net_device *g_dev; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2297 | static struct wiphy *g_wiphy; |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2298 | static enum wow_resume_trigger g_resume_trigger; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2299 | |
| 2300 | #define HDD_FA_SUSPENDED_BIT (0) |
| 2301 | static unsigned long fake_apps_state; |
| 2302 | |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2303 | /** |
| 2304 | * __hdd_wlan_fake_apps_resume() - The core logic for |
| 2305 | * hdd_wlan_fake_apps_resume() skipping the call to hif_fake_apps_resume(), |
| 2306 | * which is only need for non-irq resume |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2307 | * @wiphy: the kernel wiphy struct for the device being resumed |
| 2308 | * @dev: the kernel net_device struct for the device being resumed |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2309 | * |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2310 | * Return: none, calls QDF_BUG() on failure |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2311 | */ |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2312 | static void __hdd_wlan_fake_apps_resume(struct wiphy *wiphy, |
| 2313 | struct net_device *dev) |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2314 | { |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2315 | struct hif_opaque_softc *hif_ctx; |
Dustin Brown | ddb5970 | 2017-01-12 16:20:31 -0800 | [diff] [blame] | 2316 | qdf_device_t qdf_dev; |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2317 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2318 | hdd_debug("Unit-test resume WLAN"); |
Dustin Brown | ddb5970 | 2017-01-12 16:20:31 -0800 | [diff] [blame] | 2319 | |
| 2320 | qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE); |
| 2321 | if (!qdf_dev) { |
| 2322 | hdd_err("Failed to get QDF device context"); |
| 2323 | QDF_BUG(0); |
| 2324 | return; |
| 2325 | } |
| 2326 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2327 | hif_ctx = cds_get_context(QDF_MODULE_ID_HIF); |
| 2328 | if (!hif_ctx) { |
| 2329 | hdd_err("Failed to get HIF context"); |
| 2330 | return; |
| 2331 | } |
| 2332 | |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2333 | if (!test_and_clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2334 | hdd_debug("Not unit-test suspended; Nothing to do"); |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2335 | return; |
| 2336 | } |
| 2337 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2338 | /* simulate kernel disable irqs */ |
| 2339 | QDF_BUG(!hif_apps_wake_irq_disable(hif_ctx)); |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2340 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2341 | QDF_BUG(!wlan_hdd_bus_resume_noirq()); |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2342 | |
| 2343 | /* simulate kernel enable irqs */ |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2344 | QDF_BUG(!hif_apps_irqs_enable(hif_ctx)); |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2345 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2346 | QDF_BUG(!wlan_hdd_bus_resume()); |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2347 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2348 | QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy)); |
| 2349 | |
| 2350 | if (g_resume_trigger == WOW_RESUME_TRIGGER_HTC_WAKEUP) |
| 2351 | hif_vote_link_down(hif_ctx); |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2352 | |
| 2353 | dev->watchdog_timeo = HDD_TX_TIMEOUT; |
Dustin Brown | 562b967 | 2016-12-22 15:25:33 -0800 | [diff] [blame] | 2354 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2355 | hdd_debug("Unit-test resume succeeded"); |
Dustin Brown | d53d1a8 | 2016-10-03 12:57:33 -0700 | [diff] [blame] | 2356 | } |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2357 | |
| 2358 | /** |
| 2359 | * hdd_wlan_fake_apps_resume_irq_callback() - Irq callback function for resuming |
| 2360 | * from unit-test initiated suspend from irq wakeup signal |
| 2361 | * @val: interrupt val |
| 2362 | * |
| 2363 | * Resume wlan after getting very 1st CE interrupt from target |
| 2364 | * |
| 2365 | * Return: none |
| 2366 | */ |
| 2367 | static void hdd_wlan_fake_apps_resume_irq_callback(uint32_t val) |
| 2368 | { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2369 | hdd_debug("Trigger unit-test resume WLAN; val: 0x%x", val); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2370 | |
| 2371 | QDF_BUG(g_wiphy); |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2372 | QDF_BUG(g_dev); |
| 2373 | __hdd_wlan_fake_apps_resume(g_wiphy, g_dev); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2374 | g_wiphy = NULL; |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2375 | g_dev = NULL; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Dustin Brown | 5409643 | 2017-02-23 13:00:44 -0800 | [diff] [blame] | 2378 | int hdd_wlan_fake_apps_suspend(struct wiphy *wiphy, struct net_device *dev, |
| 2379 | enum wow_interface_pause pause_setting, |
| 2380 | enum wow_resume_trigger resume_setting) |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2381 | { |
Dustin Brown | ddb5970 | 2017-01-12 16:20:31 -0800 | [diff] [blame] | 2382 | qdf_device_t qdf_dev; |
| 2383 | struct hif_opaque_softc *hif_ctx; |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2384 | int errno; |
Dustin Brown | 5409643 | 2017-02-23 13:00:44 -0800 | [diff] [blame] | 2385 | struct wow_enable_params wow_params = { |
| 2386 | .is_unit_test = true, |
| 2387 | .interface_pause = pause_setting, |
| 2388 | .resume_trigger = resume_setting |
| 2389 | }; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2390 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2391 | hdd_debug("Unit-test suspend WLAN"); |
Dustin Brown | ddb5970 | 2017-01-12 16:20:31 -0800 | [diff] [blame] | 2392 | |
Dustin Brown | 5409643 | 2017-02-23 13:00:44 -0800 | [diff] [blame] | 2393 | if (pause_setting < WOW_INTERFACE_PAUSE_DEFAULT || |
| 2394 | pause_setting >= WOW_INTERFACE_PAUSE_COUNT) { |
| 2395 | hdd_err("Invalid interface pause %d (expected range [0, 2])", |
| 2396 | pause_setting); |
| 2397 | return -EINVAL; |
| 2398 | } |
| 2399 | |
| 2400 | if (resume_setting < WOW_RESUME_TRIGGER_DEFAULT || |
| 2401 | resume_setting >= WOW_RESUME_TRIGGER_COUNT) { |
| 2402 | hdd_err("Invalid resume trigger %d (expected range [0, 2])", |
| 2403 | resume_setting); |
| 2404 | return -EINVAL; |
| 2405 | } |
| 2406 | |
Dustin Brown | ddb5970 | 2017-01-12 16:20:31 -0800 | [diff] [blame] | 2407 | qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE); |
| 2408 | if (!qdf_dev) { |
| 2409 | hdd_err("Failed to get QDF device context"); |
| 2410 | return -EINVAL; |
| 2411 | } |
| 2412 | |
| 2413 | hif_ctx = cds_get_context(QDF_MODULE_ID_HIF); |
| 2414 | if (!hif_ctx) { |
| 2415 | hdd_err("Failed to get HIF context"); |
| 2416 | return -EINVAL; |
| 2417 | } |
| 2418 | |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2419 | if (test_and_set_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state)) { |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2420 | hdd_debug("Already unit-test suspended; Nothing to do"); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2421 | return 0; |
| 2422 | } |
| 2423 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2424 | /* pci link is needed to wakeup from HTC wakeup trigger */ |
| 2425 | if (resume_setting == WOW_RESUME_TRIGGER_HTC_WAKEUP) |
| 2426 | hif_vote_link_up(hif_ctx); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2427 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2428 | errno = wlan_hdd_cfg80211_suspend_wlan(wiphy, NULL); |
| 2429 | if (errno) |
| 2430 | goto link_down; |
| 2431 | |
| 2432 | errno = wlan_hdd_unit_test_bus_suspend(wow_params); |
| 2433 | if (errno) |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2434 | goto cfg80211_resume; |
| 2435 | |
| 2436 | /* simulate kernel disabling irqs */ |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2437 | errno = hif_apps_irqs_disable(hif_ctx); |
| 2438 | if (errno) |
| 2439 | goto bus_resume; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2440 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2441 | errno = wlan_hdd_bus_suspend_noirq(); |
| 2442 | if (errno) |
| 2443 | goto enable_irqs; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2444 | |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2445 | /* pass wiphy/dev to callback via global variables */ |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2446 | g_wiphy = wiphy; |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2447 | g_dev = dev; |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2448 | g_resume_trigger = resume_setting; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2449 | hif_fake_apps_suspend(hif_ctx, hdd_wlan_fake_apps_resume_irq_callback); |
| 2450 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2451 | /* re-enable wake irq */ |
| 2452 | errno = hif_apps_wake_irq_enable(hif_ctx); |
| 2453 | if (errno) |
| 2454 | goto fake_apps_resume; |
| 2455 | |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2456 | /* |
| 2457 | * Tell the kernel not to worry if TX queues aren't moving. This is |
| 2458 | * expected since we are suspending the wifi hardware, but not APPS |
| 2459 | */ |
| 2460 | dev->watchdog_timeo = INT_MAX; |
| 2461 | |
Srinivas Girigowda | 5d6bde6 | 2017-03-06 18:26:02 -0800 | [diff] [blame] | 2462 | hdd_debug("Unit-test suspend succeeded"); |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2463 | |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2464 | return 0; |
| 2465 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2466 | fake_apps_resume: |
| 2467 | hif_fake_apps_resume(hif_ctx); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2468 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2469 | enable_irqs: |
| 2470 | QDF_BUG(!hif_apps_irqs_enable(hif_ctx)); |
| 2471 | |
| 2472 | bus_resume: |
| 2473 | QDF_BUG(!wlan_hdd_bus_resume()); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2474 | |
| 2475 | cfg80211_resume: |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2476 | QDF_BUG(!wlan_hdd_cfg80211_resume_wlan(wiphy)); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2477 | |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2478 | link_down: |
| 2479 | hif_vote_link_down(hif_ctx); |
| 2480 | |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2481 | clear_bit(HDD_FA_SUSPENDED_BIT, &fake_apps_state); |
Dustin Brown | 3ed3e9b | 2017-03-23 12:57:58 -0700 | [diff] [blame] | 2482 | hdd_err("Unit-test suspend failed: %d", errno); |
| 2483 | |
| 2484 | return errno; |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2487 | int hdd_wlan_fake_apps_resume(struct wiphy *wiphy, struct net_device *dev) |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2488 | { |
Dustin Brown | ddb5970 | 2017-01-12 16:20:31 -0800 | [diff] [blame] | 2489 | struct hif_opaque_softc *hif_ctx; |
| 2490 | |
| 2491 | hif_ctx = cds_get_context(QDF_MODULE_ID_HIF); |
| 2492 | if (!hif_ctx) { |
| 2493 | hdd_err("Failed to get HIF context"); |
| 2494 | return -EINVAL; |
| 2495 | } |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2496 | |
| 2497 | hif_fake_apps_resume(hif_ctx); |
Dustin Brown | bc81a47 | 2016-10-26 16:56:59 -0700 | [diff] [blame] | 2498 | __hdd_wlan_fake_apps_resume(wiphy, dev); |
Rajeev Kumar | 9bb2e85 | 2016-09-24 12:29:25 -0700 | [diff] [blame] | 2499 | |
| 2500 | return 0; |
| 2501 | } |
| 2502 | #endif |