Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #define pr_fmt(fmt) "icnss: " fmt |
| 14 | |
| 15 | #include <asm/dma-iommu.h> |
Hardik Kantilal Patel | 420482e | 2017-05-05 16:57:48 +0530 | [diff] [blame] | 16 | #include <linux/of_address.h> |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 17 | #include <linux/clk.h> |
| 18 | #include <linux/iommu.h> |
| 19 | #include <linux/export.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/of.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/debugfs.h> |
| 27 | #include <linux/seq_file.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/platform_device.h> |
| 30 | #include <linux/regulator/consumer.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/sched.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/dma-mapping.h> |
| 35 | #include <linux/qmi_encdec.h> |
| 36 | #include <linux/ipc_logging.h> |
| 37 | #include <linux/thread_info.h> |
| 38 | #include <linux/uaccess.h> |
| 39 | #include <linux/qpnp/qpnp-adc.h> |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 40 | #include <linux/etherdevice.h> |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 41 | #include <soc/qcom/memory_dump.h> |
| 42 | #include <soc/qcom/icnss.h> |
| 43 | #include <soc/qcom/msm_qmi_interface.h> |
| 44 | #include <soc/qcom/secure_buffer.h> |
| 45 | #include <soc/qcom/subsystem_notif.h> |
| 46 | #include <soc/qcom/subsystem_restart.h> |
| 47 | #include <soc/qcom/service-locator.h> |
| 48 | #include <soc/qcom/service-notifier.h> |
| 49 | #include <soc/qcom/socinfo.h> |
| 50 | #include <soc/qcom/ramdump.h> |
| 51 | |
| 52 | #include "wlan_firmware_service_v01.h" |
| 53 | |
| 54 | #ifdef CONFIG_ICNSS_DEBUG |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 55 | unsigned long qmi_timeout = 10000; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 56 | module_param(qmi_timeout, ulong, 0600); |
| 57 | |
| 58 | #define WLFW_TIMEOUT_MS qmi_timeout |
| 59 | #else |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 60 | #define WLFW_TIMEOUT_MS 10000 |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 61 | #endif |
| 62 | #define WLFW_SERVICE_INS_ID_V01 0 |
| 63 | #define WLFW_CLIENT_ID 0x4b4e454c |
| 64 | #define MAX_PROP_SIZE 32 |
| 65 | #define NUM_LOG_PAGES 10 |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 66 | #define NUM_LOG_LONG_PAGES 4 |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 67 | #define ICNSS_MAGIC 0x5abc5abc |
| 68 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 69 | #define ICNSS_SERVICE_LOCATION_CLIENT_NAME "ICNSS-WLAN" |
| 70 | #define ICNSS_WLAN_SERVICE_NAME "wlan/fw" |
| 71 | |
| 72 | #define ICNSS_THRESHOLD_HIGH 3600000 |
| 73 | #define ICNSS_THRESHOLD_LOW 3450000 |
| 74 | #define ICNSS_THRESHOLD_GUARD 20000 |
| 75 | |
Yuanyuan Liu | 237c0ad | 2017-10-09 17:58:17 -0700 | [diff] [blame] | 76 | #define ICNSS_MAX_PROBE_CNT 2 |
| 77 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 78 | #define icnss_ipc_log_string(_x...) do { \ |
| 79 | if (icnss_ipc_log_context) \ |
| 80 | ipc_log_string(icnss_ipc_log_context, _x); \ |
| 81 | } while (0) |
| 82 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 83 | #define icnss_ipc_log_long_string(_x...) do { \ |
| 84 | if (icnss_ipc_log_long_context) \ |
| 85 | ipc_log_string(icnss_ipc_log_long_context, _x); \ |
| 86 | } while (0) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 87 | |
| 88 | #define icnss_pr_err(_fmt, ...) do { \ |
Yuanyuan Liu | 795d6c5 | 2017-07-11 16:53:14 -0700 | [diff] [blame] | 89 | printk("%s" pr_fmt(_fmt), KERN_ERR, ##__VA_ARGS__); \ |
| 90 | icnss_ipc_log_string("%s" pr_fmt(_fmt), "", \ |
| 91 | ##__VA_ARGS__); \ |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 92 | } while (0) |
| 93 | |
| 94 | #define icnss_pr_warn(_fmt, ...) do { \ |
Yuanyuan Liu | 795d6c5 | 2017-07-11 16:53:14 -0700 | [diff] [blame] | 95 | printk("%s" pr_fmt(_fmt), KERN_WARNING, ##__VA_ARGS__); \ |
| 96 | icnss_ipc_log_string("%s" pr_fmt(_fmt), "", \ |
| 97 | ##__VA_ARGS__); \ |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 98 | } while (0) |
| 99 | |
| 100 | #define icnss_pr_info(_fmt, ...) do { \ |
Yuanyuan Liu | 795d6c5 | 2017-07-11 16:53:14 -0700 | [diff] [blame] | 101 | printk("%s" pr_fmt(_fmt), KERN_INFO, ##__VA_ARGS__); \ |
| 102 | icnss_ipc_log_string("%s" pr_fmt(_fmt), "", \ |
| 103 | ##__VA_ARGS__); \ |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 104 | } while (0) |
| 105 | |
Yuanyuan Liu | 795d6c5 | 2017-07-11 16:53:14 -0700 | [diff] [blame] | 106 | #if defined(CONFIG_DYNAMIC_DEBUG) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 107 | #define icnss_pr_dbg(_fmt, ...) do { \ |
Yuanyuan Liu | 795d6c5 | 2017-07-11 16:53:14 -0700 | [diff] [blame] | 108 | pr_debug(_fmt, ##__VA_ARGS__); \ |
| 109 | icnss_ipc_log_string(pr_fmt(_fmt), ##__VA_ARGS__); \ |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 110 | } while (0) |
| 111 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 112 | #define icnss_pr_vdbg(_fmt, ...) do { \ |
Yuanyuan Liu | 795d6c5 | 2017-07-11 16:53:14 -0700 | [diff] [blame] | 113 | pr_debug(_fmt, ##__VA_ARGS__); \ |
| 114 | icnss_ipc_log_long_string(pr_fmt(_fmt), ##__VA_ARGS__); \ |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 115 | } while (0) |
Yuanyuan Liu | 795d6c5 | 2017-07-11 16:53:14 -0700 | [diff] [blame] | 116 | #elif defined(DEBUG) |
| 117 | #define icnss_pr_dbg(_fmt, ...) do { \ |
| 118 | printk("%s" pr_fmt(_fmt), KERN_DEBUG, ##__VA_ARGS__); \ |
| 119 | icnss_ipc_log_string("%s" pr_fmt(_fmt), "", \ |
| 120 | ##__VA_ARGS__); \ |
| 121 | } while (0) |
| 122 | |
| 123 | #define icnss_pr_vdbg(_fmt, ...) do { \ |
| 124 | printk("%s" pr_fmt(_fmt), KERN_DEBUG, ##__VA_ARGS__); \ |
| 125 | icnss_ipc_log_long_string("%s" pr_fmt(_fmt), "", \ |
| 126 | ##__VA_ARGS__); \ |
| 127 | } while (0) |
| 128 | #else |
| 129 | #define icnss_pr_dbg(_fmt, ...) do { \ |
| 130 | no_printk("%s" pr_fmt(_fmt), KERN_DEBUG, ##__VA_ARGS__); \ |
| 131 | icnss_ipc_log_string("%s" pr_fmt(_fmt), "", \ |
| 132 | ##__VA_ARGS__); \ |
| 133 | } while (0) |
| 134 | |
| 135 | #define icnss_pr_vdbg(_fmt, ...) do { \ |
| 136 | no_printk("%s" pr_fmt(_fmt), KERN_DEBUG, ##__VA_ARGS__); \ |
| 137 | icnss_ipc_log_long_string("%s" pr_fmt(_fmt), "", \ |
| 138 | ##__VA_ARGS__); \ |
| 139 | } while (0) |
| 140 | #endif |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 141 | |
| 142 | #ifdef CONFIG_ICNSS_DEBUG |
| 143 | #define ICNSS_ASSERT(_condition) do { \ |
| 144 | if (!(_condition)) { \ |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 145 | icnss_pr_err("ASSERT at line %d\n", __LINE__); \ |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 146 | BUG_ON(1); \ |
| 147 | } \ |
| 148 | } while (0) |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 149 | |
| 150 | bool ignore_qmi_timeout; |
| 151 | #define ICNSS_QMI_ASSERT() ICNSS_ASSERT(ignore_qmi_timeout) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 152 | #else |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 153 | #define ICNSS_ASSERT(_condition) do { } while (0) |
| 154 | #define ICNSS_QMI_ASSERT() do { } while (0) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 155 | #endif |
| 156 | |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 157 | #define QMI_ERR_PLAT_CCPM_CLK_INIT_FAILED 0x77 |
| 158 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 159 | enum icnss_debug_quirks { |
| 160 | HW_ALWAYS_ON, |
| 161 | HW_DEBUG_ENABLE, |
| 162 | SKIP_QMI, |
| 163 | HW_ONLY_TOP_LEVEL_RESET, |
| 164 | RECOVERY_DISABLE, |
| 165 | SSR_ONLY, |
| 166 | PDR_ONLY, |
| 167 | VBATT_DISABLE, |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 168 | FW_REJUVENATE_ENABLE, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 169 | }; |
| 170 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 171 | #define ICNSS_QUIRKS_DEFAULT (BIT(VBATT_DISABLE) | \ |
| 172 | BIT(FW_REJUVENATE_ENABLE)) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 173 | |
| 174 | unsigned long quirks = ICNSS_QUIRKS_DEFAULT; |
| 175 | module_param(quirks, ulong, 0600); |
| 176 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 177 | uint64_t dynamic_feature_mask = QMI_WLFW_FW_REJUVENATE_V01; |
| 178 | module_param(dynamic_feature_mask, ullong, 0600); |
| 179 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 180 | void *icnss_ipc_log_context; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 181 | void *icnss_ipc_log_long_context; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 182 | |
| 183 | #define ICNSS_EVENT_PENDING 2989 |
| 184 | |
| 185 | #define ICNSS_EVENT_SYNC BIT(0) |
| 186 | #define ICNSS_EVENT_UNINTERRUPTIBLE BIT(1) |
| 187 | #define ICNSS_EVENT_SYNC_UNINTERRUPTIBLE (ICNSS_EVENT_UNINTERRUPTIBLE | \ |
| 188 | ICNSS_EVENT_SYNC) |
| 189 | |
| 190 | enum icnss_driver_event_type { |
| 191 | ICNSS_DRIVER_EVENT_SERVER_ARRIVE, |
| 192 | ICNSS_DRIVER_EVENT_SERVER_EXIT, |
| 193 | ICNSS_DRIVER_EVENT_FW_READY_IND, |
| 194 | ICNSS_DRIVER_EVENT_REGISTER_DRIVER, |
| 195 | ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER, |
| 196 | ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN, |
| 197 | ICNSS_DRIVER_EVENT_MAX, |
| 198 | }; |
| 199 | |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 200 | enum icnss_msa_perm { |
| 201 | ICNSS_MSA_PERM_HLOS_ALL = 0, |
| 202 | ICNSS_MSA_PERM_WLAN_HW_RW = 1, |
| 203 | ICNSS_MSA_PERM_DUMP_COLLECT = 2, |
| 204 | ICNSS_MSA_PERM_MAX, |
| 205 | }; |
| 206 | |
| 207 | #define ICNSS_MAX_VMIDS 4 |
| 208 | |
| 209 | struct icnss_mem_region_info { |
| 210 | uint64_t reg_addr; |
| 211 | uint32_t size; |
| 212 | uint8_t secure_flag; |
| 213 | enum icnss_msa_perm perm; |
| 214 | }; |
| 215 | |
| 216 | struct icnss_msa_perm_list_t { |
| 217 | int vmids[ICNSS_MAX_VMIDS]; |
| 218 | int perms[ICNSS_MAX_VMIDS]; |
| 219 | int nelems; |
| 220 | }; |
| 221 | |
| 222 | struct icnss_msa_perm_list_t msa_perm_secure_list[ICNSS_MSA_PERM_MAX] = { |
| 223 | [ICNSS_MSA_PERM_HLOS_ALL] = { |
| 224 | .vmids = {VMID_HLOS}, |
| 225 | .perms = {PERM_READ | PERM_WRITE | PERM_EXEC}, |
| 226 | .nelems = 1, |
| 227 | }, |
| 228 | |
| 229 | [ICNSS_MSA_PERM_WLAN_HW_RW] = { |
| 230 | .vmids = {VMID_MSS_MSA, VMID_WLAN}, |
| 231 | .perms = {PERM_READ | PERM_WRITE, |
| 232 | PERM_READ | PERM_WRITE}, |
| 233 | .nelems = 2, |
| 234 | }, |
| 235 | |
| 236 | [ICNSS_MSA_PERM_DUMP_COLLECT] = { |
| 237 | .vmids = {VMID_MSS_MSA, VMID_WLAN, VMID_HLOS}, |
| 238 | .perms = {PERM_READ | PERM_WRITE, |
| 239 | PERM_READ | PERM_WRITE, |
| 240 | PERM_READ}, |
| 241 | .nelems = 3, |
| 242 | }, |
| 243 | }; |
| 244 | |
| 245 | struct icnss_msa_perm_list_t msa_perm_list[ICNSS_MSA_PERM_MAX] = { |
| 246 | [ICNSS_MSA_PERM_HLOS_ALL] = { |
| 247 | .vmids = {VMID_HLOS}, |
| 248 | .perms = {PERM_READ | PERM_WRITE | PERM_EXEC}, |
| 249 | .nelems = 1, |
| 250 | }, |
| 251 | |
| 252 | [ICNSS_MSA_PERM_WLAN_HW_RW] = { |
| 253 | .vmids = {VMID_MSS_MSA, VMID_WLAN, VMID_WLAN_CE}, |
| 254 | .perms = {PERM_READ | PERM_WRITE, |
| 255 | PERM_READ | PERM_WRITE, |
| 256 | PERM_READ | PERM_WRITE}, |
| 257 | .nelems = 3, |
| 258 | }, |
| 259 | |
| 260 | [ICNSS_MSA_PERM_DUMP_COLLECT] = { |
| 261 | .vmids = {VMID_MSS_MSA, VMID_WLAN, VMID_WLAN_CE, VMID_HLOS}, |
| 262 | .perms = {PERM_READ | PERM_WRITE, |
| 263 | PERM_READ | PERM_WRITE, |
| 264 | PERM_READ | PERM_WRITE, |
| 265 | PERM_READ}, |
| 266 | .nelems = 4, |
| 267 | }, |
| 268 | }; |
| 269 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 270 | struct icnss_event_pd_service_down_data { |
| 271 | bool crashed; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 272 | bool fw_rejuvenate; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | struct icnss_driver_event { |
| 276 | struct list_head list; |
| 277 | enum icnss_driver_event_type type; |
| 278 | bool sync; |
| 279 | struct completion complete; |
| 280 | int ret; |
| 281 | void *data; |
| 282 | }; |
| 283 | |
| 284 | enum icnss_driver_state { |
| 285 | ICNSS_WLFW_QMI_CONNECTED, |
| 286 | ICNSS_POWER_ON, |
| 287 | ICNSS_FW_READY, |
| 288 | ICNSS_DRIVER_PROBED, |
| 289 | ICNSS_FW_TEST_MODE, |
| 290 | ICNSS_PM_SUSPEND, |
| 291 | ICNSS_PM_SUSPEND_NOIRQ, |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 292 | ICNSS_SSR_REGISTERED, |
| 293 | ICNSS_PDR_REGISTERED, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 294 | ICNSS_PD_RESTART, |
| 295 | ICNSS_MSA0_ASSIGNED, |
| 296 | ICNSS_WLFW_EXISTS, |
Anurag Chouhan | fa0c70d | 2017-04-10 17:26:47 +0530 | [diff] [blame] | 297 | ICNSS_SHUTDOWN_DONE, |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 298 | ICNSS_HOST_TRIGGERED_PDR, |
Sameer Thalappil | 93c0073 | 2017-08-18 13:02:32 -0700 | [diff] [blame] | 299 | ICNSS_FW_DOWN, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | struct ce_irq_list { |
| 303 | int irq; |
| 304 | irqreturn_t (*handler)(int, void *); |
| 305 | }; |
| 306 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 307 | struct icnss_vreg_info { |
| 308 | struct regulator *reg; |
| 309 | const char *name; |
| 310 | u32 min_v; |
| 311 | u32 max_v; |
| 312 | u32 load_ua; |
| 313 | unsigned long settle_delay; |
| 314 | bool required; |
| 315 | }; |
| 316 | |
| 317 | struct icnss_clk_info { |
| 318 | struct clk *handle; |
| 319 | const char *name; |
| 320 | u32 freq; |
| 321 | bool required; |
| 322 | }; |
| 323 | |
| 324 | static struct icnss_vreg_info icnss_vreg_info[] = { |
| 325 | {NULL, "vdd-0.8-cx-mx", 800000, 800000, 0, 0, false}, |
| 326 | {NULL, "vdd-1.8-xo", 1800000, 1800000, 0, 0, false}, |
| 327 | {NULL, "vdd-1.3-rfa", 1304000, 1304000, 0, 0, false}, |
| 328 | {NULL, "vdd-3.3-ch0", 3312000, 3312000, 0, 0, false}, |
| 329 | }; |
| 330 | |
| 331 | #define ICNSS_VREG_INFO_SIZE ARRAY_SIZE(icnss_vreg_info) |
| 332 | |
| 333 | static struct icnss_clk_info icnss_clk_info[] = { |
| 334 | {NULL, "cxo_ref_clk_pin", 0, false}, |
| 335 | }; |
| 336 | |
| 337 | #define ICNSS_CLK_INFO_SIZE ARRAY_SIZE(icnss_clk_info) |
| 338 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 339 | struct icnss_stats { |
| 340 | struct { |
| 341 | uint32_t posted; |
| 342 | uint32_t processed; |
| 343 | } events[ICNSS_DRIVER_EVENT_MAX]; |
| 344 | |
| 345 | struct { |
| 346 | uint32_t request; |
| 347 | uint32_t free; |
| 348 | uint32_t enable; |
| 349 | uint32_t disable; |
| 350 | } ce_irqs[ICNSS_MAX_IRQ_REGISTRATIONS]; |
| 351 | |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 352 | struct { |
| 353 | uint32_t pdr_fw_crash; |
| 354 | uint32_t pdr_host_error; |
| 355 | uint32_t root_pd_crash; |
| 356 | uint32_t root_pd_shutdown; |
| 357 | } recovery; |
| 358 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 359 | uint32_t pm_suspend; |
| 360 | uint32_t pm_suspend_err; |
| 361 | uint32_t pm_resume; |
| 362 | uint32_t pm_resume_err; |
| 363 | uint32_t pm_suspend_noirq; |
| 364 | uint32_t pm_suspend_noirq_err; |
| 365 | uint32_t pm_resume_noirq; |
| 366 | uint32_t pm_resume_noirq_err; |
| 367 | uint32_t pm_stay_awake; |
| 368 | uint32_t pm_relax; |
| 369 | |
| 370 | uint32_t ind_register_req; |
| 371 | uint32_t ind_register_resp; |
| 372 | uint32_t ind_register_err; |
| 373 | uint32_t msa_info_req; |
| 374 | uint32_t msa_info_resp; |
| 375 | uint32_t msa_info_err; |
| 376 | uint32_t msa_ready_req; |
| 377 | uint32_t msa_ready_resp; |
| 378 | uint32_t msa_ready_err; |
| 379 | uint32_t msa_ready_ind; |
| 380 | uint32_t cap_req; |
| 381 | uint32_t cap_resp; |
| 382 | uint32_t cap_err; |
| 383 | uint32_t pin_connect_result; |
| 384 | uint32_t cfg_req; |
| 385 | uint32_t cfg_resp; |
| 386 | uint32_t cfg_req_err; |
| 387 | uint32_t mode_req; |
| 388 | uint32_t mode_resp; |
| 389 | uint32_t mode_req_err; |
| 390 | uint32_t ini_req; |
| 391 | uint32_t ini_resp; |
| 392 | uint32_t ini_req_err; |
| 393 | uint32_t vbatt_req; |
| 394 | uint32_t vbatt_resp; |
| 395 | uint32_t vbatt_req_err; |
Yuanyuan Liu | 4c497ff | 2016-12-16 16:36:08 -0800 | [diff] [blame] | 396 | u32 rejuvenate_ind; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 397 | uint32_t rejuvenate_ack_req; |
| 398 | uint32_t rejuvenate_ack_resp; |
| 399 | uint32_t rejuvenate_ack_err; |
| 400 | }; |
| 401 | |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 402 | enum icnss_pdr_cause_index { |
| 403 | ICNSS_FW_CRASH, |
| 404 | ICNSS_ROOT_PD_CRASH, |
| 405 | ICNSS_ROOT_PD_SHUTDOWN, |
| 406 | ICNSS_HOST_ERROR, |
| 407 | }; |
| 408 | |
| 409 | static const char * const icnss_pdr_cause[] = { |
| 410 | [ICNSS_FW_CRASH] = "FW crash", |
| 411 | [ICNSS_ROOT_PD_CRASH] = "Root PD crashed", |
| 412 | [ICNSS_ROOT_PD_SHUTDOWN] = "Root PD shutdown", |
| 413 | [ICNSS_HOST_ERROR] = "Host error", |
| 414 | }; |
| 415 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 416 | struct service_notifier_context { |
| 417 | void *handle; |
| 418 | uint32_t instance_id; |
| 419 | char name[QMI_SERVREG_LOC_NAME_LENGTH_V01 + 1]; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | static struct icnss_priv { |
| 423 | uint32_t magic; |
| 424 | struct platform_device *pdev; |
| 425 | struct icnss_driver_ops *ops; |
| 426 | struct ce_irq_list ce_irq_list[ICNSS_MAX_IRQ_REGISTRATIONS]; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 427 | struct icnss_vreg_info vreg_info[ICNSS_VREG_INFO_SIZE]; |
| 428 | struct icnss_clk_info clk_info[ICNSS_CLK_INFO_SIZE]; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 429 | u32 ce_irqs[ICNSS_MAX_IRQ_REGISTRATIONS]; |
| 430 | phys_addr_t mem_base_pa; |
| 431 | void __iomem *mem_base_va; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 432 | struct dma_iommu_mapping *smmu_mapping; |
| 433 | dma_addr_t smmu_iova_start; |
| 434 | size_t smmu_iova_len; |
| 435 | dma_addr_t smmu_iova_ipa_start; |
| 436 | size_t smmu_iova_ipa_len; |
| 437 | struct qmi_handle *wlfw_clnt; |
| 438 | struct list_head event_list; |
| 439 | spinlock_t event_lock; |
| 440 | struct work_struct event_work; |
| 441 | struct work_struct qmi_recv_msg_work; |
| 442 | struct workqueue_struct *event_wq; |
| 443 | phys_addr_t msa_pa; |
| 444 | uint32_t msa_mem_size; |
| 445 | void *msa_va; |
| 446 | unsigned long state; |
| 447 | struct wlfw_rf_chip_info_s_v01 chip_info; |
| 448 | struct wlfw_rf_board_info_s_v01 board_info; |
| 449 | struct wlfw_soc_info_s_v01 soc_info; |
| 450 | struct wlfw_fw_version_info_s_v01 fw_version_info; |
| 451 | char fw_build_id[QMI_WLFW_MAX_BUILD_ID_LEN_V01 + 1]; |
| 452 | u32 pwr_pin_result; |
| 453 | u32 phy_io_pin_result; |
| 454 | u32 rf_pin_result; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 455 | uint32_t nr_mem_region; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 456 | struct icnss_mem_region_info |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 457 | mem_region[QMI_WLFW_MAX_NUM_MEMORY_REGIONS_V01]; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 458 | struct dentry *root_dentry; |
| 459 | spinlock_t on_off_lock; |
| 460 | struct icnss_stats stats; |
| 461 | struct work_struct service_notifier_work; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 462 | struct service_notifier_context *service_notifier; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 463 | struct notifier_block service_notifier_nb; |
| 464 | int total_domains; |
| 465 | struct notifier_block get_service_nb; |
| 466 | void *modem_notify_handler; |
| 467 | struct notifier_block modem_ssr_nb; |
| 468 | uint32_t diag_reg_read_addr; |
| 469 | uint32_t diag_reg_read_mem_type; |
| 470 | uint32_t diag_reg_read_len; |
| 471 | uint8_t *diag_reg_read_buf; |
| 472 | struct qpnp_adc_tm_btm_param vph_monitor_params; |
| 473 | struct qpnp_adc_tm_chip *adc_tm_dev; |
| 474 | struct qpnp_vadc_chip *vadc_dev; |
| 475 | uint64_t vph_pwr; |
| 476 | atomic_t pm_count; |
| 477 | struct ramdump_device *msa0_dump_dev; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 478 | bool bypass_s1_smmu; |
Yuanyuan Liu | 4c497ff | 2016-12-16 16:36:08 -0800 | [diff] [blame] | 479 | u8 cause_for_rejuvenation; |
| 480 | u8 requesting_sub_system; |
| 481 | u16 line_number; |
| 482 | char function_name[QMI_WLFW_FUNCTION_NAME_LEN_V01 + 1]; |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 483 | struct mutex dev_lock; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 484 | } *penv; |
| 485 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 486 | #ifdef CONFIG_ICNSS_DEBUG |
| 487 | static void icnss_ignore_qmi_timeout(bool ignore) |
| 488 | { |
| 489 | ignore_qmi_timeout = ignore; |
| 490 | } |
| 491 | #else |
| 492 | static void icnss_ignore_qmi_timeout(bool ignore) { } |
| 493 | #endif |
| 494 | |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 495 | static int icnss_assign_msa_perm(struct icnss_mem_region_info |
| 496 | *mem_region, enum icnss_msa_perm new_perm) |
| 497 | { |
| 498 | int ret = 0; |
| 499 | phys_addr_t addr; |
| 500 | u32 size; |
| 501 | u32 i = 0; |
Anurag Chouhan | a8b5683 | 2017-08-31 16:54:48 +0530 | [diff] [blame] | 502 | u32 source_vmids[ICNSS_MAX_VMIDS] = {0}; |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 503 | u32 source_nelems; |
Anurag Chouhan | a8b5683 | 2017-08-31 16:54:48 +0530 | [diff] [blame] | 504 | u32 dest_vmids[ICNSS_MAX_VMIDS] = {0}; |
| 505 | u32 dest_perms[ICNSS_MAX_VMIDS] = {0}; |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 506 | u32 dest_nelems; |
| 507 | enum icnss_msa_perm cur_perm = mem_region->perm; |
| 508 | struct icnss_msa_perm_list_t *new_perm_list, *old_perm_list; |
| 509 | |
| 510 | addr = mem_region->reg_addr; |
| 511 | size = mem_region->size; |
| 512 | |
| 513 | if (mem_region->secure_flag) { |
| 514 | new_perm_list = &msa_perm_secure_list[new_perm]; |
| 515 | old_perm_list = &msa_perm_secure_list[cur_perm]; |
| 516 | } else { |
| 517 | new_perm_list = &msa_perm_list[new_perm]; |
| 518 | old_perm_list = &msa_perm_list[cur_perm]; |
| 519 | } |
| 520 | |
| 521 | source_nelems = old_perm_list->nelems; |
| 522 | dest_nelems = new_perm_list->nelems; |
| 523 | |
| 524 | for (i = 0; i < source_nelems; ++i) |
| 525 | source_vmids[i] = old_perm_list->vmids[i]; |
| 526 | |
| 527 | for (i = 0; i < dest_nelems; ++i) { |
| 528 | dest_vmids[i] = new_perm_list->vmids[i]; |
| 529 | dest_perms[i] = new_perm_list->perms[i]; |
| 530 | } |
| 531 | |
| 532 | ret = hyp_assign_phys(addr, size, source_vmids, source_nelems, |
| 533 | dest_vmids, dest_perms, dest_nelems); |
| 534 | if (ret) { |
| 535 | icnss_pr_err("Hyperviser map failed for PA=%pa size=%u err=%d\n", |
| 536 | &addr, size, ret); |
| 537 | goto out; |
| 538 | } |
| 539 | |
| 540 | icnss_pr_dbg("Hypervisor map for source_nelems=%d, source[0]=%x, source[1]=%x, source[2]=%x," |
| 541 | "source[3]=%x, dest_nelems=%d, dest[0]=%x, dest[1]=%x, dest[2]=%x, dest[3]=%x\n", |
| 542 | source_nelems, source_vmids[0], source_vmids[1], |
| 543 | source_vmids[2], source_vmids[3], dest_nelems, |
| 544 | dest_vmids[0], dest_vmids[1], dest_vmids[2], |
| 545 | dest_vmids[3]); |
| 546 | out: |
| 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | static int icnss_assign_msa_perm_all(struct icnss_priv *priv, |
| 551 | enum icnss_msa_perm new_perm) |
| 552 | { |
| 553 | int ret; |
| 554 | int i; |
| 555 | enum icnss_msa_perm old_perm; |
| 556 | |
Yuanyuan Liu | 26ec221 | 2017-09-01 10:34:25 -0700 | [diff] [blame] | 557 | if (priv->nr_mem_region > QMI_WLFW_MAX_NUM_MEMORY_REGIONS_V01) { |
| 558 | icnss_pr_err("Invalid memory region len %d\n", |
| 559 | priv->nr_mem_region); |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 563 | for (i = 0; i < priv->nr_mem_region; i++) { |
| 564 | old_perm = priv->mem_region[i].perm; |
| 565 | ret = icnss_assign_msa_perm(&priv->mem_region[i], new_perm); |
| 566 | if (ret) |
| 567 | goto err_unmap; |
| 568 | priv->mem_region[i].perm = new_perm; |
| 569 | } |
| 570 | return 0; |
| 571 | |
| 572 | err_unmap: |
| 573 | for (i--; i >= 0; i--) { |
| 574 | icnss_assign_msa_perm(&priv->mem_region[i], old_perm); |
| 575 | } |
| 576 | return ret; |
| 577 | } |
| 578 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 579 | static void icnss_pm_stay_awake(struct icnss_priv *priv) |
| 580 | { |
| 581 | if (atomic_inc_return(&priv->pm_count) != 1) |
| 582 | return; |
| 583 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 584 | icnss_pr_vdbg("PM stay awake, state: 0x%lx, count: %d\n", priv->state, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 585 | atomic_read(&priv->pm_count)); |
| 586 | |
| 587 | pm_stay_awake(&priv->pdev->dev); |
| 588 | |
| 589 | priv->stats.pm_stay_awake++; |
| 590 | } |
| 591 | |
| 592 | static void icnss_pm_relax(struct icnss_priv *priv) |
| 593 | { |
| 594 | int r = atomic_dec_return(&priv->pm_count); |
| 595 | |
| 596 | WARN_ON(r < 0); |
| 597 | |
| 598 | if (r != 0) |
| 599 | return; |
| 600 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 601 | icnss_pr_vdbg("PM relax, state: 0x%lx, count: %d\n", priv->state, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 602 | atomic_read(&priv->pm_count)); |
| 603 | |
| 604 | pm_relax(&priv->pdev->dev); |
| 605 | priv->stats.pm_relax++; |
| 606 | } |
| 607 | |
| 608 | static char *icnss_driver_event_to_str(enum icnss_driver_event_type type) |
| 609 | { |
| 610 | switch (type) { |
| 611 | case ICNSS_DRIVER_EVENT_SERVER_ARRIVE: |
| 612 | return "SERVER_ARRIVE"; |
| 613 | case ICNSS_DRIVER_EVENT_SERVER_EXIT: |
| 614 | return "SERVER_EXIT"; |
| 615 | case ICNSS_DRIVER_EVENT_FW_READY_IND: |
| 616 | return "FW_READY"; |
| 617 | case ICNSS_DRIVER_EVENT_REGISTER_DRIVER: |
| 618 | return "REGISTER_DRIVER"; |
| 619 | case ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER: |
| 620 | return "UNREGISTER_DRIVER"; |
| 621 | case ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN: |
| 622 | return "PD_SERVICE_DOWN"; |
| 623 | case ICNSS_DRIVER_EVENT_MAX: |
| 624 | return "EVENT_MAX"; |
| 625 | } |
| 626 | |
| 627 | return "UNKNOWN"; |
| 628 | }; |
| 629 | |
| 630 | static int icnss_driver_event_post(enum icnss_driver_event_type type, |
| 631 | u32 flags, void *data) |
| 632 | { |
| 633 | struct icnss_driver_event *event; |
| 634 | unsigned long irq_flags; |
| 635 | int gfp = GFP_KERNEL; |
| 636 | int ret = 0; |
| 637 | |
| 638 | icnss_pr_dbg("Posting event: %s(%d), %s, flags: 0x%x, state: 0x%lx\n", |
| 639 | icnss_driver_event_to_str(type), type, current->comm, |
| 640 | flags, penv->state); |
| 641 | |
| 642 | if (type >= ICNSS_DRIVER_EVENT_MAX) { |
| 643 | icnss_pr_err("Invalid Event type: %d, can't post", type); |
| 644 | return -EINVAL; |
| 645 | } |
| 646 | |
| 647 | if (in_interrupt() || irqs_disabled()) |
| 648 | gfp = GFP_ATOMIC; |
| 649 | |
| 650 | event = kzalloc(sizeof(*event), gfp); |
| 651 | if (event == NULL) |
| 652 | return -ENOMEM; |
| 653 | |
| 654 | icnss_pm_stay_awake(penv); |
| 655 | |
| 656 | event->type = type; |
| 657 | event->data = data; |
| 658 | init_completion(&event->complete); |
| 659 | event->ret = ICNSS_EVENT_PENDING; |
| 660 | event->sync = !!(flags & ICNSS_EVENT_SYNC); |
| 661 | |
| 662 | spin_lock_irqsave(&penv->event_lock, irq_flags); |
| 663 | list_add_tail(&event->list, &penv->event_list); |
| 664 | spin_unlock_irqrestore(&penv->event_lock, irq_flags); |
| 665 | |
| 666 | penv->stats.events[type].posted++; |
| 667 | queue_work(penv->event_wq, &penv->event_work); |
| 668 | |
| 669 | if (!(flags & ICNSS_EVENT_SYNC)) |
| 670 | goto out; |
| 671 | |
| 672 | if (flags & ICNSS_EVENT_UNINTERRUPTIBLE) |
| 673 | wait_for_completion(&event->complete); |
| 674 | else |
| 675 | ret = wait_for_completion_interruptible(&event->complete); |
| 676 | |
| 677 | icnss_pr_dbg("Completed event: %s(%d), state: 0x%lx, ret: %d/%d\n", |
| 678 | icnss_driver_event_to_str(type), type, penv->state, ret, |
| 679 | event->ret); |
| 680 | |
| 681 | spin_lock_irqsave(&penv->event_lock, irq_flags); |
| 682 | if (ret == -ERESTARTSYS && event->ret == ICNSS_EVENT_PENDING) { |
| 683 | event->sync = false; |
| 684 | spin_unlock_irqrestore(&penv->event_lock, irq_flags); |
| 685 | ret = -EINTR; |
| 686 | goto out; |
| 687 | } |
| 688 | spin_unlock_irqrestore(&penv->event_lock, irq_flags); |
| 689 | |
| 690 | ret = event->ret; |
| 691 | kfree(event); |
| 692 | |
| 693 | out: |
| 694 | icnss_pm_relax(penv); |
| 695 | return ret; |
| 696 | } |
| 697 | |
| 698 | static int wlfw_vbatt_send_sync_msg(struct icnss_priv *priv, |
| 699 | uint64_t voltage_uv) |
| 700 | { |
| 701 | int ret; |
| 702 | struct wlfw_vbatt_req_msg_v01 req; |
| 703 | struct wlfw_vbatt_resp_msg_v01 resp; |
| 704 | struct msg_desc req_desc, resp_desc; |
| 705 | |
| 706 | if (!priv->wlfw_clnt) { |
| 707 | ret = -ENODEV; |
| 708 | goto out; |
| 709 | } |
| 710 | |
| 711 | icnss_pr_dbg("Sending Vbatt message, state: 0x%lx\n", |
| 712 | penv->state); |
| 713 | |
| 714 | memset(&req, 0, sizeof(req)); |
| 715 | memset(&resp, 0, sizeof(resp)); |
| 716 | |
| 717 | req.voltage_uv = voltage_uv; |
| 718 | |
| 719 | req_desc.max_msg_len = WLFW_VBATT_REQ_MSG_V01_MAX_MSG_LEN; |
| 720 | req_desc.msg_id = QMI_WLFW_VBATT_REQ_V01; |
| 721 | req_desc.ei_array = wlfw_vbatt_req_msg_v01_ei; |
| 722 | |
| 723 | resp_desc.max_msg_len = WLFW_VBATT_RESP_MSG_V01_MAX_MSG_LEN; |
| 724 | resp_desc.msg_id = QMI_WLFW_VBATT_RESP_V01; |
| 725 | resp_desc.ei_array = wlfw_vbatt_resp_msg_v01_ei; |
| 726 | |
| 727 | priv->stats.vbatt_req++; |
| 728 | |
| 729 | ret = qmi_send_req_wait(priv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 730 | &resp_desc, &resp, sizeof(resp), WLFW_TIMEOUT_MS); |
| 731 | if (ret < 0) { |
| 732 | icnss_pr_err("Send vbatt req failed %d\n", ret); |
| 733 | goto out; |
| 734 | } |
| 735 | |
| 736 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 737 | icnss_pr_err("QMI vbatt request rejected, result:%d error:%d\n", |
| 738 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 739 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 740 | goto out; |
| 741 | } |
| 742 | priv->stats.vbatt_resp++; |
| 743 | |
| 744 | out: |
| 745 | priv->stats.vbatt_req_err++; |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | static int icnss_get_phone_power(struct icnss_priv *priv, uint64_t *result_uv) |
| 750 | { |
| 751 | int ret = 0; |
| 752 | struct qpnp_vadc_result adc_result; |
| 753 | |
| 754 | if (!priv->vadc_dev) { |
| 755 | icnss_pr_err("VADC dev doesn't exists\n"); |
| 756 | ret = -EINVAL; |
| 757 | goto out; |
| 758 | } |
| 759 | |
| 760 | ret = qpnp_vadc_read(penv->vadc_dev, VADC_VPH_PWR, &adc_result); |
| 761 | if (ret) { |
| 762 | icnss_pr_err("Error reading ADC channel %d, ret = %d\n", |
| 763 | VADC_VPH_PWR, ret); |
| 764 | goto out; |
| 765 | } |
| 766 | |
| 767 | icnss_pr_dbg("Phone power read phy=%lld meas=0x%llx\n", |
| 768 | adc_result.physical, adc_result.measurement); |
| 769 | |
| 770 | *result_uv = adc_result.physical; |
| 771 | out: |
| 772 | return ret; |
| 773 | } |
| 774 | |
| 775 | static void icnss_vph_notify(enum qpnp_tm_state state, void *ctx) |
| 776 | { |
| 777 | struct icnss_priv *priv = ctx; |
| 778 | uint64_t vph_pwr = 0; |
| 779 | uint64_t vph_pwr_prev; |
| 780 | int ret = 0; |
| 781 | bool update = true; |
| 782 | |
| 783 | if (!priv) { |
| 784 | icnss_pr_err("Priv pointer is NULL\n"); |
| 785 | return; |
| 786 | } |
| 787 | |
| 788 | vph_pwr_prev = priv->vph_pwr; |
| 789 | |
| 790 | ret = icnss_get_phone_power(priv, &vph_pwr); |
| 791 | if (ret) |
| 792 | return; |
| 793 | |
| 794 | if (vph_pwr < ICNSS_THRESHOLD_LOW) { |
| 795 | if (vph_pwr_prev < ICNSS_THRESHOLD_LOW) |
| 796 | update = false; |
| 797 | priv->vph_monitor_params.state_request = |
| 798 | ADC_TM_HIGH_THR_ENABLE; |
| 799 | priv->vph_monitor_params.high_thr = ICNSS_THRESHOLD_LOW + |
| 800 | ICNSS_THRESHOLD_GUARD; |
| 801 | priv->vph_monitor_params.low_thr = 0; |
| 802 | } else if (vph_pwr > ICNSS_THRESHOLD_HIGH) { |
| 803 | if (vph_pwr_prev > ICNSS_THRESHOLD_HIGH) |
| 804 | update = false; |
| 805 | priv->vph_monitor_params.state_request = |
| 806 | ADC_TM_LOW_THR_ENABLE; |
| 807 | priv->vph_monitor_params.low_thr = ICNSS_THRESHOLD_HIGH - |
| 808 | ICNSS_THRESHOLD_GUARD; |
| 809 | priv->vph_monitor_params.high_thr = 0; |
| 810 | } else { |
| 811 | if (vph_pwr_prev > ICNSS_THRESHOLD_LOW && |
| 812 | vph_pwr_prev < ICNSS_THRESHOLD_HIGH) |
| 813 | update = false; |
| 814 | priv->vph_monitor_params.state_request = |
| 815 | ADC_TM_HIGH_LOW_THR_ENABLE; |
| 816 | priv->vph_monitor_params.low_thr = ICNSS_THRESHOLD_LOW; |
| 817 | priv->vph_monitor_params.high_thr = ICNSS_THRESHOLD_HIGH; |
| 818 | } |
| 819 | |
| 820 | priv->vph_pwr = vph_pwr; |
| 821 | |
| 822 | if (update) |
| 823 | wlfw_vbatt_send_sync_msg(priv, vph_pwr); |
| 824 | |
| 825 | icnss_pr_dbg("set low threshold to %d, high threshold to %d\n", |
| 826 | priv->vph_monitor_params.low_thr, |
| 827 | priv->vph_monitor_params.high_thr); |
| 828 | ret = qpnp_adc_tm_channel_measure(priv->adc_tm_dev, |
| 829 | &priv->vph_monitor_params); |
| 830 | if (ret) |
| 831 | icnss_pr_err("TM channel setup failed %d\n", ret); |
| 832 | } |
| 833 | |
| 834 | static int icnss_setup_vph_monitor(struct icnss_priv *priv) |
| 835 | { |
| 836 | int ret = 0; |
| 837 | |
| 838 | if (!priv->adc_tm_dev) { |
| 839 | icnss_pr_err("ADC TM handler is NULL\n"); |
| 840 | ret = -EINVAL; |
| 841 | goto out; |
| 842 | } |
| 843 | |
| 844 | priv->vph_monitor_params.low_thr = ICNSS_THRESHOLD_LOW; |
| 845 | priv->vph_monitor_params.high_thr = ICNSS_THRESHOLD_HIGH; |
| 846 | priv->vph_monitor_params.state_request = ADC_TM_HIGH_LOW_THR_ENABLE; |
| 847 | priv->vph_monitor_params.channel = VADC_VPH_PWR; |
| 848 | priv->vph_monitor_params.btm_ctx = priv; |
| 849 | priv->vph_monitor_params.timer_interval = ADC_MEAS1_INTERVAL_1S; |
| 850 | priv->vph_monitor_params.threshold_notification = &icnss_vph_notify; |
| 851 | icnss_pr_dbg("Set low threshold to %d, high threshold to %d\n", |
| 852 | priv->vph_monitor_params.low_thr, |
| 853 | priv->vph_monitor_params.high_thr); |
| 854 | |
| 855 | ret = qpnp_adc_tm_channel_measure(priv->adc_tm_dev, |
| 856 | &priv->vph_monitor_params); |
| 857 | if (ret) |
| 858 | icnss_pr_err("TM channel setup failed %d\n", ret); |
| 859 | out: |
| 860 | return ret; |
| 861 | } |
| 862 | |
| 863 | static int icnss_init_vph_monitor(struct icnss_priv *priv) |
| 864 | { |
| 865 | int ret = 0; |
| 866 | |
| 867 | if (test_bit(VBATT_DISABLE, &quirks)) |
| 868 | goto out; |
| 869 | |
| 870 | ret = icnss_get_phone_power(priv, &priv->vph_pwr); |
| 871 | if (ret) |
| 872 | goto out; |
| 873 | |
| 874 | wlfw_vbatt_send_sync_msg(priv, priv->vph_pwr); |
| 875 | |
| 876 | ret = icnss_setup_vph_monitor(priv); |
| 877 | if (ret) |
| 878 | goto out; |
| 879 | out: |
| 880 | return ret; |
| 881 | } |
| 882 | |
| 883 | |
| 884 | static int icnss_qmi_pin_connect_result_ind(void *msg, unsigned int msg_len) |
| 885 | { |
| 886 | struct msg_desc ind_desc; |
| 887 | struct wlfw_pin_connect_result_ind_msg_v01 ind_msg; |
| 888 | int ret = 0; |
| 889 | |
| 890 | if (!penv || !penv->wlfw_clnt) { |
| 891 | ret = -ENODEV; |
| 892 | goto out; |
| 893 | } |
| 894 | |
Hardik Kantilal Patel | 27501b0 | 2017-05-03 14:01:16 +0530 | [diff] [blame] | 895 | memset(&ind_msg, 0, sizeof(ind_msg)); |
| 896 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 897 | ind_desc.msg_id = QMI_WLFW_PIN_CONNECT_RESULT_IND_V01; |
| 898 | ind_desc.max_msg_len = WLFW_PIN_CONNECT_RESULT_IND_MSG_V01_MAX_MSG_LEN; |
| 899 | ind_desc.ei_array = wlfw_pin_connect_result_ind_msg_v01_ei; |
| 900 | |
| 901 | ret = qmi_kernel_decode(&ind_desc, &ind_msg, msg, msg_len); |
| 902 | if (ret < 0) { |
| 903 | icnss_pr_err("Failed to decode message: %d, msg_len: %u\n", |
| 904 | ret, msg_len); |
| 905 | goto out; |
| 906 | } |
| 907 | |
| 908 | /* store pin result locally */ |
| 909 | if (ind_msg.pwr_pin_result_valid) |
| 910 | penv->pwr_pin_result = ind_msg.pwr_pin_result; |
| 911 | if (ind_msg.phy_io_pin_result_valid) |
| 912 | penv->phy_io_pin_result = ind_msg.phy_io_pin_result; |
| 913 | if (ind_msg.rf_pin_result_valid) |
| 914 | penv->rf_pin_result = ind_msg.rf_pin_result; |
| 915 | |
| 916 | icnss_pr_dbg("Pin connect Result: pwr_pin: 0x%x phy_io_pin: 0x%x rf_io_pin: 0x%x\n", |
| 917 | ind_msg.pwr_pin_result, ind_msg.phy_io_pin_result, |
| 918 | ind_msg.rf_pin_result); |
| 919 | |
| 920 | penv->stats.pin_connect_result++; |
| 921 | out: |
| 922 | return ret; |
| 923 | } |
| 924 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 925 | static int icnss_vreg_on(struct icnss_priv *priv) |
| 926 | { |
| 927 | int ret = 0; |
| 928 | struct icnss_vreg_info *vreg_info; |
| 929 | int i; |
| 930 | |
| 931 | for (i = 0; i < ICNSS_VREG_INFO_SIZE; i++) { |
| 932 | vreg_info = &priv->vreg_info[i]; |
| 933 | |
| 934 | if (!vreg_info->reg) |
| 935 | continue; |
| 936 | |
| 937 | icnss_pr_vdbg("Regulator %s being enabled\n", vreg_info->name); |
| 938 | |
| 939 | ret = regulator_set_voltage(vreg_info->reg, vreg_info->min_v, |
| 940 | vreg_info->max_v); |
| 941 | if (ret) { |
| 942 | icnss_pr_err("Regulator %s, can't set voltage: min_v: %u, max_v: %u, ret: %d\n", |
| 943 | vreg_info->name, vreg_info->min_v, |
| 944 | vreg_info->max_v, ret); |
| 945 | break; |
| 946 | } |
| 947 | |
| 948 | if (vreg_info->load_ua) { |
| 949 | ret = regulator_set_load(vreg_info->reg, |
| 950 | vreg_info->load_ua); |
| 951 | if (ret < 0) { |
| 952 | icnss_pr_err("Regulator %s, can't set load: %u, ret: %d\n", |
| 953 | vreg_info->name, |
| 954 | vreg_info->load_ua, ret); |
| 955 | break; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | ret = regulator_enable(vreg_info->reg); |
| 960 | if (ret) { |
| 961 | icnss_pr_err("Regulator %s, can't enable: %d\n", |
| 962 | vreg_info->name, ret); |
| 963 | break; |
| 964 | } |
| 965 | |
| 966 | if (vreg_info->settle_delay) |
| 967 | udelay(vreg_info->settle_delay); |
| 968 | } |
| 969 | |
| 970 | if (!ret) |
| 971 | return 0; |
| 972 | |
| 973 | for (; i >= 0; i--) { |
| 974 | vreg_info = &priv->vreg_info[i]; |
| 975 | |
| 976 | if (!vreg_info->reg) |
| 977 | continue; |
| 978 | |
| 979 | regulator_disable(vreg_info->reg); |
| 980 | regulator_set_load(vreg_info->reg, 0); |
| 981 | regulator_set_voltage(vreg_info->reg, 0, vreg_info->max_v); |
| 982 | } |
| 983 | |
| 984 | return ret; |
| 985 | } |
| 986 | |
| 987 | static int icnss_vreg_off(struct icnss_priv *priv) |
| 988 | { |
| 989 | int ret = 0; |
| 990 | struct icnss_vreg_info *vreg_info; |
| 991 | int i; |
| 992 | |
| 993 | for (i = ICNSS_VREG_INFO_SIZE - 1; i >= 0; i--) { |
| 994 | vreg_info = &priv->vreg_info[i]; |
| 995 | |
| 996 | if (!vreg_info->reg) |
| 997 | continue; |
| 998 | |
| 999 | icnss_pr_vdbg("Regulator %s being disabled\n", vreg_info->name); |
| 1000 | |
| 1001 | ret = regulator_disable(vreg_info->reg); |
| 1002 | if (ret) |
| 1003 | icnss_pr_err("Regulator %s, can't disable: %d\n", |
| 1004 | vreg_info->name, ret); |
| 1005 | |
| 1006 | ret = regulator_set_load(vreg_info->reg, 0); |
| 1007 | if (ret < 0) |
| 1008 | icnss_pr_err("Regulator %s, can't set load: %d\n", |
| 1009 | vreg_info->name, ret); |
| 1010 | |
| 1011 | ret = regulator_set_voltage(vreg_info->reg, 0, |
| 1012 | vreg_info->max_v); |
| 1013 | if (ret) |
| 1014 | icnss_pr_err("Regulator %s, can't set voltage: %d\n", |
| 1015 | vreg_info->name, ret); |
| 1016 | } |
| 1017 | |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
| 1021 | static int icnss_clk_init(struct icnss_priv *priv) |
| 1022 | { |
| 1023 | struct icnss_clk_info *clk_info; |
| 1024 | int i; |
| 1025 | int ret = 0; |
| 1026 | |
| 1027 | for (i = 0; i < ICNSS_CLK_INFO_SIZE; i++) { |
| 1028 | clk_info = &priv->clk_info[i]; |
| 1029 | |
| 1030 | if (!clk_info->handle) |
| 1031 | continue; |
| 1032 | |
| 1033 | icnss_pr_vdbg("Clock %s being enabled\n", clk_info->name); |
| 1034 | |
| 1035 | if (clk_info->freq) { |
| 1036 | ret = clk_set_rate(clk_info->handle, clk_info->freq); |
| 1037 | |
| 1038 | if (ret) { |
| 1039 | icnss_pr_err("Clock %s, can't set frequency: %u, ret: %d\n", |
| 1040 | clk_info->name, clk_info->freq, |
| 1041 | ret); |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | ret = clk_prepare_enable(clk_info->handle); |
| 1047 | if (ret) { |
| 1048 | icnss_pr_err("Clock %s, can't enable: %d\n", |
| 1049 | clk_info->name, ret); |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | if (ret == 0) |
| 1055 | return 0; |
| 1056 | |
| 1057 | for (; i >= 0; i--) { |
| 1058 | clk_info = &priv->clk_info[i]; |
| 1059 | |
| 1060 | if (!clk_info->handle) |
| 1061 | continue; |
| 1062 | |
| 1063 | clk_disable_unprepare(clk_info->handle); |
| 1064 | } |
| 1065 | |
| 1066 | return ret; |
| 1067 | } |
| 1068 | |
| 1069 | static int icnss_clk_deinit(struct icnss_priv *priv) |
| 1070 | { |
| 1071 | struct icnss_clk_info *clk_info; |
| 1072 | int i; |
| 1073 | |
| 1074 | for (i = 0; i < ICNSS_CLK_INFO_SIZE; i++) { |
| 1075 | clk_info = &priv->clk_info[i]; |
| 1076 | |
| 1077 | if (!clk_info->handle) |
| 1078 | continue; |
| 1079 | |
| 1080 | icnss_pr_vdbg("Clock %s being disabled\n", clk_info->name); |
| 1081 | |
| 1082 | clk_disable_unprepare(clk_info->handle); |
| 1083 | } |
| 1084 | |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1088 | static int icnss_hw_power_on(struct icnss_priv *priv) |
| 1089 | { |
| 1090 | int ret = 0; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1091 | |
| 1092 | icnss_pr_dbg("HW Power on: state: 0x%lx\n", priv->state); |
| 1093 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1094 | spin_lock(&priv->on_off_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1095 | if (test_bit(ICNSS_POWER_ON, &priv->state)) { |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1096 | spin_unlock(&priv->on_off_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1097 | return ret; |
| 1098 | } |
| 1099 | set_bit(ICNSS_POWER_ON, &priv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1100 | spin_unlock(&priv->on_off_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1101 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1102 | ret = icnss_vreg_on(priv); |
| 1103 | if (ret) |
| 1104 | goto out; |
| 1105 | |
| 1106 | ret = icnss_clk_init(priv); |
| 1107 | if (ret) |
| 1108 | goto vreg_off; |
| 1109 | |
| 1110 | return ret; |
| 1111 | |
| 1112 | vreg_off: |
| 1113 | icnss_vreg_off(priv); |
| 1114 | out: |
| 1115 | clear_bit(ICNSS_POWER_ON, &priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1116 | return ret; |
| 1117 | } |
| 1118 | |
| 1119 | static int icnss_hw_power_off(struct icnss_priv *priv) |
| 1120 | { |
| 1121 | int ret = 0; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1122 | |
| 1123 | if (test_bit(HW_ALWAYS_ON, &quirks)) |
| 1124 | return 0; |
| 1125 | |
| 1126 | icnss_pr_dbg("HW Power off: 0x%lx\n", priv->state); |
| 1127 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1128 | spin_lock(&priv->on_off_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1129 | if (!test_bit(ICNSS_POWER_ON, &priv->state)) { |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1130 | spin_unlock(&priv->on_off_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1131 | return ret; |
| 1132 | } |
| 1133 | clear_bit(ICNSS_POWER_ON, &priv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1134 | spin_unlock(&priv->on_off_lock); |
| 1135 | |
| 1136 | icnss_clk_deinit(priv); |
| 1137 | |
| 1138 | ret = icnss_vreg_off(priv); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1139 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1140 | return ret; |
| 1141 | } |
| 1142 | |
| 1143 | int icnss_power_on(struct device *dev) |
| 1144 | { |
| 1145 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 1146 | |
| 1147 | if (!priv) { |
| 1148 | icnss_pr_err("Invalid drvdata: dev %p, data %p\n", |
| 1149 | dev, priv); |
| 1150 | return -EINVAL; |
| 1151 | } |
| 1152 | |
| 1153 | icnss_pr_dbg("Power On: 0x%lx\n", priv->state); |
| 1154 | |
| 1155 | return icnss_hw_power_on(priv); |
| 1156 | } |
| 1157 | EXPORT_SYMBOL(icnss_power_on); |
| 1158 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1159 | bool icnss_is_fw_ready(void) |
| 1160 | { |
| 1161 | if (!penv) |
| 1162 | return false; |
| 1163 | else |
| 1164 | return test_bit(ICNSS_FW_READY, &penv->state); |
| 1165 | } |
| 1166 | EXPORT_SYMBOL(icnss_is_fw_ready); |
| 1167 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1168 | int icnss_power_off(struct device *dev) |
| 1169 | { |
| 1170 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 1171 | |
| 1172 | if (!priv) { |
| 1173 | icnss_pr_err("Invalid drvdata: dev %p, data %p\n", |
| 1174 | dev, priv); |
| 1175 | return -EINVAL; |
| 1176 | } |
| 1177 | |
| 1178 | icnss_pr_dbg("Power Off: 0x%lx\n", priv->state); |
| 1179 | |
| 1180 | return icnss_hw_power_off(priv); |
| 1181 | } |
| 1182 | EXPORT_SYMBOL(icnss_power_off); |
| 1183 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1184 | static int wlfw_msa_mem_info_send_sync_msg(void) |
| 1185 | { |
| 1186 | int ret; |
| 1187 | int i; |
| 1188 | struct wlfw_msa_info_req_msg_v01 req; |
| 1189 | struct wlfw_msa_info_resp_msg_v01 resp; |
| 1190 | struct msg_desc req_desc, resp_desc; |
| 1191 | |
| 1192 | if (!penv || !penv->wlfw_clnt) |
| 1193 | return -ENODEV; |
| 1194 | |
| 1195 | icnss_pr_dbg("Sending MSA mem info, state: 0x%lx\n", penv->state); |
| 1196 | |
| 1197 | memset(&req, 0, sizeof(req)); |
| 1198 | memset(&resp, 0, sizeof(resp)); |
| 1199 | |
| 1200 | req.msa_addr = penv->msa_pa; |
| 1201 | req.size = penv->msa_mem_size; |
| 1202 | |
| 1203 | req_desc.max_msg_len = WLFW_MSA_INFO_REQ_MSG_V01_MAX_MSG_LEN; |
| 1204 | req_desc.msg_id = QMI_WLFW_MSA_INFO_REQ_V01; |
| 1205 | req_desc.ei_array = wlfw_msa_info_req_msg_v01_ei; |
| 1206 | |
| 1207 | resp_desc.max_msg_len = WLFW_MSA_INFO_RESP_MSG_V01_MAX_MSG_LEN; |
| 1208 | resp_desc.msg_id = QMI_WLFW_MSA_INFO_RESP_V01; |
| 1209 | resp_desc.ei_array = wlfw_msa_info_resp_msg_v01_ei; |
| 1210 | |
| 1211 | penv->stats.msa_info_req++; |
| 1212 | |
| 1213 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1214 | &resp_desc, &resp, sizeof(resp), WLFW_TIMEOUT_MS); |
| 1215 | if (ret < 0) { |
| 1216 | icnss_pr_err("Send MSA Mem info req failed %d\n", ret); |
| 1217 | goto out; |
| 1218 | } |
| 1219 | |
| 1220 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1221 | icnss_pr_err("QMI MSA Mem info request rejected, result:%d error:%d\n", |
| 1222 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1223 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1224 | goto out; |
| 1225 | } |
| 1226 | |
| 1227 | icnss_pr_dbg("Receive mem_region_info_len: %d\n", |
| 1228 | resp.mem_region_info_len); |
| 1229 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1230 | if (resp.mem_region_info_len > QMI_WLFW_MAX_NUM_MEMORY_REGIONS_V01) { |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1231 | icnss_pr_err("Invalid memory region length received: %d\n", |
| 1232 | resp.mem_region_info_len); |
| 1233 | ret = -EINVAL; |
| 1234 | goto out; |
| 1235 | } |
| 1236 | |
| 1237 | penv->stats.msa_info_resp++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1238 | penv->nr_mem_region = resp.mem_region_info_len; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1239 | for (i = 0; i < resp.mem_region_info_len; i++) { |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1240 | penv->mem_region[i].reg_addr = |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1241 | resp.mem_region_info[i].region_addr; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1242 | penv->mem_region[i].size = |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1243 | resp.mem_region_info[i].size; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1244 | penv->mem_region[i].secure_flag = |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1245 | resp.mem_region_info[i].secure_flag; |
| 1246 | icnss_pr_dbg("Memory Region: %d Addr: 0x%llx Size: 0x%x Flag: 0x%08x\n", |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1247 | i, penv->mem_region[i].reg_addr, |
| 1248 | penv->mem_region[i].size, |
| 1249 | penv->mem_region[i].secure_flag); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | return 0; |
| 1253 | |
| 1254 | out: |
| 1255 | penv->stats.msa_info_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1256 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1257 | return ret; |
| 1258 | } |
| 1259 | |
| 1260 | static int wlfw_msa_ready_send_sync_msg(void) |
| 1261 | { |
| 1262 | int ret; |
| 1263 | struct wlfw_msa_ready_req_msg_v01 req; |
| 1264 | struct wlfw_msa_ready_resp_msg_v01 resp; |
| 1265 | struct msg_desc req_desc, resp_desc; |
| 1266 | |
| 1267 | if (!penv || !penv->wlfw_clnt) |
| 1268 | return -ENODEV; |
| 1269 | |
| 1270 | icnss_pr_dbg("Sending MSA ready request message, state: 0x%lx\n", |
| 1271 | penv->state); |
| 1272 | |
| 1273 | memset(&req, 0, sizeof(req)); |
| 1274 | memset(&resp, 0, sizeof(resp)); |
| 1275 | |
| 1276 | req_desc.max_msg_len = WLFW_MSA_READY_REQ_MSG_V01_MAX_MSG_LEN; |
| 1277 | req_desc.msg_id = QMI_WLFW_MSA_READY_REQ_V01; |
| 1278 | req_desc.ei_array = wlfw_msa_ready_req_msg_v01_ei; |
| 1279 | |
| 1280 | resp_desc.max_msg_len = WLFW_MSA_READY_RESP_MSG_V01_MAX_MSG_LEN; |
| 1281 | resp_desc.msg_id = QMI_WLFW_MSA_READY_RESP_V01; |
| 1282 | resp_desc.ei_array = wlfw_msa_ready_resp_msg_v01_ei; |
| 1283 | |
| 1284 | penv->stats.msa_ready_req++; |
| 1285 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1286 | &resp_desc, &resp, sizeof(resp), WLFW_TIMEOUT_MS); |
| 1287 | if (ret < 0) { |
| 1288 | icnss_pr_err("Send MSA ready req failed %d\n", ret); |
| 1289 | goto out; |
| 1290 | } |
| 1291 | |
| 1292 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1293 | icnss_pr_err("QMI MSA ready request rejected: result:%d error:%d\n", |
| 1294 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1295 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1296 | goto out; |
| 1297 | } |
| 1298 | penv->stats.msa_ready_resp++; |
| 1299 | |
| 1300 | return 0; |
| 1301 | |
| 1302 | out: |
| 1303 | penv->stats.msa_ready_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1304 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1305 | return ret; |
| 1306 | } |
| 1307 | |
| 1308 | static int wlfw_ind_register_send_sync_msg(void) |
| 1309 | { |
| 1310 | int ret; |
| 1311 | struct wlfw_ind_register_req_msg_v01 req; |
| 1312 | struct wlfw_ind_register_resp_msg_v01 resp; |
| 1313 | struct msg_desc req_desc, resp_desc; |
| 1314 | |
| 1315 | if (!penv || !penv->wlfw_clnt) |
| 1316 | return -ENODEV; |
| 1317 | |
| 1318 | icnss_pr_dbg("Sending indication register message, state: 0x%lx\n", |
| 1319 | penv->state); |
| 1320 | |
| 1321 | memset(&req, 0, sizeof(req)); |
| 1322 | memset(&resp, 0, sizeof(resp)); |
| 1323 | |
| 1324 | req.client_id_valid = 1; |
| 1325 | req.client_id = WLFW_CLIENT_ID; |
| 1326 | req.fw_ready_enable_valid = 1; |
| 1327 | req.fw_ready_enable = 1; |
| 1328 | req.msa_ready_enable_valid = 1; |
| 1329 | req.msa_ready_enable = 1; |
| 1330 | req.pin_connect_result_enable_valid = 1; |
| 1331 | req.pin_connect_result_enable = 1; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1332 | if (test_bit(FW_REJUVENATE_ENABLE, &quirks)) { |
| 1333 | req.rejuvenate_enable_valid = 1; |
| 1334 | req.rejuvenate_enable = 1; |
| 1335 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1336 | |
| 1337 | req_desc.max_msg_len = WLFW_IND_REGISTER_REQ_MSG_V01_MAX_MSG_LEN; |
| 1338 | req_desc.msg_id = QMI_WLFW_IND_REGISTER_REQ_V01; |
| 1339 | req_desc.ei_array = wlfw_ind_register_req_msg_v01_ei; |
| 1340 | |
| 1341 | resp_desc.max_msg_len = WLFW_IND_REGISTER_RESP_MSG_V01_MAX_MSG_LEN; |
| 1342 | resp_desc.msg_id = QMI_WLFW_IND_REGISTER_RESP_V01; |
| 1343 | resp_desc.ei_array = wlfw_ind_register_resp_msg_v01_ei; |
| 1344 | |
| 1345 | penv->stats.ind_register_req++; |
| 1346 | |
| 1347 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1348 | &resp_desc, &resp, sizeof(resp), |
| 1349 | WLFW_TIMEOUT_MS); |
| 1350 | if (ret < 0) { |
| 1351 | icnss_pr_err("Send indication register req failed %d\n", ret); |
| 1352 | goto out; |
| 1353 | } |
| 1354 | |
| 1355 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1356 | icnss_pr_err("QMI indication register request rejected, resut:%d error:%d\n", |
| 1357 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1358 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1359 | goto out; |
| 1360 | } |
| 1361 | penv->stats.ind_register_resp++; |
| 1362 | |
| 1363 | return 0; |
| 1364 | |
| 1365 | out: |
| 1366 | penv->stats.ind_register_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1367 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1368 | return ret; |
| 1369 | } |
| 1370 | |
| 1371 | static int wlfw_cap_send_sync_msg(void) |
| 1372 | { |
| 1373 | int ret; |
| 1374 | struct wlfw_cap_req_msg_v01 req; |
| 1375 | struct wlfw_cap_resp_msg_v01 resp; |
| 1376 | struct msg_desc req_desc, resp_desc; |
| 1377 | |
| 1378 | if (!penv || !penv->wlfw_clnt) |
| 1379 | return -ENODEV; |
| 1380 | |
| 1381 | icnss_pr_dbg("Sending capability message, state: 0x%lx\n", penv->state); |
| 1382 | |
| 1383 | memset(&resp, 0, sizeof(resp)); |
| 1384 | |
| 1385 | req_desc.max_msg_len = WLFW_CAP_REQ_MSG_V01_MAX_MSG_LEN; |
| 1386 | req_desc.msg_id = QMI_WLFW_CAP_REQ_V01; |
| 1387 | req_desc.ei_array = wlfw_cap_req_msg_v01_ei; |
| 1388 | |
| 1389 | resp_desc.max_msg_len = WLFW_CAP_RESP_MSG_V01_MAX_MSG_LEN; |
| 1390 | resp_desc.msg_id = QMI_WLFW_CAP_RESP_V01; |
| 1391 | resp_desc.ei_array = wlfw_cap_resp_msg_v01_ei; |
| 1392 | |
| 1393 | penv->stats.cap_req++; |
| 1394 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1395 | &resp_desc, &resp, sizeof(resp), |
| 1396 | WLFW_TIMEOUT_MS); |
| 1397 | if (ret < 0) { |
| 1398 | icnss_pr_err("Send capability req failed %d\n", ret); |
| 1399 | goto out; |
| 1400 | } |
| 1401 | |
| 1402 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1403 | icnss_pr_err("QMI capability request rejected, result:%d error:%d\n", |
| 1404 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1405 | ret = -resp.resp.result; |
| 1406 | if (resp.resp.error == QMI_ERR_PLAT_CCPM_CLK_INIT_FAILED) |
| 1407 | icnss_pr_err("RF card Not present"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1408 | goto out; |
| 1409 | } |
| 1410 | |
| 1411 | penv->stats.cap_resp++; |
| 1412 | /* store cap locally */ |
| 1413 | if (resp.chip_info_valid) |
| 1414 | penv->chip_info = resp.chip_info; |
| 1415 | if (resp.board_info_valid) |
| 1416 | penv->board_info = resp.board_info; |
| 1417 | else |
| 1418 | penv->board_info.board_id = 0xFF; |
| 1419 | if (resp.soc_info_valid) |
| 1420 | penv->soc_info = resp.soc_info; |
| 1421 | if (resp.fw_version_info_valid) |
| 1422 | penv->fw_version_info = resp.fw_version_info; |
| 1423 | if (resp.fw_build_id_valid) |
| 1424 | strlcpy(penv->fw_build_id, resp.fw_build_id, |
| 1425 | QMI_WLFW_MAX_BUILD_ID_LEN_V01 + 1); |
| 1426 | |
| 1427 | icnss_pr_dbg("Capability, chip_id: 0x%x, chip_family: 0x%x, board_id: 0x%x, soc_id: 0x%x, fw_version: 0x%x, fw_build_timestamp: %s, fw_build_id: %s", |
| 1428 | penv->chip_info.chip_id, penv->chip_info.chip_family, |
| 1429 | penv->board_info.board_id, penv->soc_info.soc_id, |
| 1430 | penv->fw_version_info.fw_version, |
| 1431 | penv->fw_version_info.fw_build_timestamp, |
| 1432 | penv->fw_build_id); |
| 1433 | |
| 1434 | return 0; |
| 1435 | |
| 1436 | out: |
| 1437 | penv->stats.cap_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1438 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1439 | return ret; |
| 1440 | } |
| 1441 | |
| 1442 | static int wlfw_wlan_mode_send_sync_msg(enum wlfw_driver_mode_enum_v01 mode) |
| 1443 | { |
| 1444 | int ret; |
| 1445 | struct wlfw_wlan_mode_req_msg_v01 req; |
| 1446 | struct wlfw_wlan_mode_resp_msg_v01 resp; |
| 1447 | struct msg_desc req_desc, resp_desc; |
| 1448 | |
| 1449 | if (!penv || !penv->wlfw_clnt) |
| 1450 | return -ENODEV; |
| 1451 | |
| 1452 | /* During recovery do not send mode request for WLAN OFF as |
| 1453 | * FW not able to process it. |
| 1454 | */ |
| 1455 | if (test_bit(ICNSS_PD_RESTART, &penv->state) && |
| 1456 | mode == QMI_WLFW_OFF_V01) |
| 1457 | return 0; |
| 1458 | |
| 1459 | icnss_pr_dbg("Sending Mode request, state: 0x%lx, mode: %d\n", |
| 1460 | penv->state, mode); |
| 1461 | |
| 1462 | memset(&req, 0, sizeof(req)); |
| 1463 | memset(&resp, 0, sizeof(resp)); |
| 1464 | |
| 1465 | req.mode = mode; |
| 1466 | req.hw_debug_valid = 1; |
| 1467 | req.hw_debug = !!test_bit(HW_DEBUG_ENABLE, &quirks); |
| 1468 | |
| 1469 | req_desc.max_msg_len = WLFW_WLAN_MODE_REQ_MSG_V01_MAX_MSG_LEN; |
| 1470 | req_desc.msg_id = QMI_WLFW_WLAN_MODE_REQ_V01; |
| 1471 | req_desc.ei_array = wlfw_wlan_mode_req_msg_v01_ei; |
| 1472 | |
| 1473 | resp_desc.max_msg_len = WLFW_WLAN_MODE_RESP_MSG_V01_MAX_MSG_LEN; |
| 1474 | resp_desc.msg_id = QMI_WLFW_WLAN_MODE_RESP_V01; |
| 1475 | resp_desc.ei_array = wlfw_wlan_mode_resp_msg_v01_ei; |
| 1476 | |
| 1477 | penv->stats.mode_req++; |
| 1478 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1479 | &resp_desc, &resp, sizeof(resp), |
| 1480 | WLFW_TIMEOUT_MS); |
| 1481 | if (ret < 0) { |
| 1482 | icnss_pr_err("Send mode req failed, mode: %d ret: %d\n", |
| 1483 | mode, ret); |
| 1484 | goto out; |
| 1485 | } |
| 1486 | |
| 1487 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1488 | icnss_pr_err("QMI mode request rejected, mode:%d result:%d error:%d\n", |
| 1489 | mode, resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1490 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1491 | goto out; |
| 1492 | } |
| 1493 | penv->stats.mode_resp++; |
| 1494 | |
| 1495 | return 0; |
| 1496 | |
| 1497 | out: |
| 1498 | penv->stats.mode_req_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1499 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1500 | return ret; |
| 1501 | } |
| 1502 | |
| 1503 | static int wlfw_wlan_cfg_send_sync_msg(struct wlfw_wlan_cfg_req_msg_v01 *data) |
| 1504 | { |
| 1505 | int ret; |
| 1506 | struct wlfw_wlan_cfg_req_msg_v01 req; |
| 1507 | struct wlfw_wlan_cfg_resp_msg_v01 resp; |
| 1508 | struct msg_desc req_desc, resp_desc; |
| 1509 | |
| 1510 | if (!penv || !penv->wlfw_clnt) |
| 1511 | return -ENODEV; |
| 1512 | |
| 1513 | icnss_pr_dbg("Sending config request, state: 0x%lx\n", penv->state); |
| 1514 | |
| 1515 | memset(&req, 0, sizeof(req)); |
| 1516 | memset(&resp, 0, sizeof(resp)); |
| 1517 | |
| 1518 | memcpy(&req, data, sizeof(req)); |
| 1519 | |
| 1520 | req_desc.max_msg_len = WLFW_WLAN_CFG_REQ_MSG_V01_MAX_MSG_LEN; |
| 1521 | req_desc.msg_id = QMI_WLFW_WLAN_CFG_REQ_V01; |
| 1522 | req_desc.ei_array = wlfw_wlan_cfg_req_msg_v01_ei; |
| 1523 | |
| 1524 | resp_desc.max_msg_len = WLFW_WLAN_CFG_RESP_MSG_V01_MAX_MSG_LEN; |
| 1525 | resp_desc.msg_id = QMI_WLFW_WLAN_CFG_RESP_V01; |
| 1526 | resp_desc.ei_array = wlfw_wlan_cfg_resp_msg_v01_ei; |
| 1527 | |
| 1528 | penv->stats.cfg_req++; |
| 1529 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1530 | &resp_desc, &resp, sizeof(resp), |
| 1531 | WLFW_TIMEOUT_MS); |
| 1532 | if (ret < 0) { |
| 1533 | icnss_pr_err("Send config req failed %d\n", ret); |
| 1534 | goto out; |
| 1535 | } |
| 1536 | |
| 1537 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1538 | icnss_pr_err("QMI config request rejected, result:%d error:%d\n", |
| 1539 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1540 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1541 | goto out; |
| 1542 | } |
| 1543 | penv->stats.cfg_resp++; |
| 1544 | |
| 1545 | return 0; |
| 1546 | |
| 1547 | out: |
| 1548 | penv->stats.cfg_req_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1549 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1550 | return ret; |
| 1551 | } |
| 1552 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1553 | static int wlfw_ini_send_sync_msg(uint8_t fw_log_mode) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1554 | { |
| 1555 | int ret; |
| 1556 | struct wlfw_ini_req_msg_v01 req; |
| 1557 | struct wlfw_ini_resp_msg_v01 resp; |
| 1558 | struct msg_desc req_desc, resp_desc; |
| 1559 | |
| 1560 | if (!penv || !penv->wlfw_clnt) |
| 1561 | return -ENODEV; |
| 1562 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1563 | icnss_pr_dbg("Sending ini sync request, state: 0x%lx, fw_log_mode: %d\n", |
| 1564 | penv->state, fw_log_mode); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1565 | |
| 1566 | memset(&req, 0, sizeof(req)); |
| 1567 | memset(&resp, 0, sizeof(resp)); |
| 1568 | |
| 1569 | req.enablefwlog_valid = 1; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1570 | req.enablefwlog = fw_log_mode; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1571 | |
| 1572 | req_desc.max_msg_len = WLFW_INI_REQ_MSG_V01_MAX_MSG_LEN; |
| 1573 | req_desc.msg_id = QMI_WLFW_INI_REQ_V01; |
| 1574 | req_desc.ei_array = wlfw_ini_req_msg_v01_ei; |
| 1575 | |
| 1576 | resp_desc.max_msg_len = WLFW_INI_RESP_MSG_V01_MAX_MSG_LEN; |
| 1577 | resp_desc.msg_id = QMI_WLFW_INI_RESP_V01; |
| 1578 | resp_desc.ei_array = wlfw_ini_resp_msg_v01_ei; |
| 1579 | |
| 1580 | penv->stats.ini_req++; |
| 1581 | |
| 1582 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1583 | &resp_desc, &resp, sizeof(resp), WLFW_TIMEOUT_MS); |
| 1584 | if (ret < 0) { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1585 | icnss_pr_err("Send INI req failed fw_log_mode: %d, ret: %d\n", |
| 1586 | fw_log_mode, ret); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1587 | goto out; |
| 1588 | } |
| 1589 | |
| 1590 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1591 | icnss_pr_err("QMI INI request rejected, fw_log_mode:%d result:%d error:%d\n", |
| 1592 | fw_log_mode, resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1593 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1594 | goto out; |
| 1595 | } |
| 1596 | penv->stats.ini_resp++; |
| 1597 | |
| 1598 | return 0; |
| 1599 | |
| 1600 | out: |
| 1601 | penv->stats.ini_req_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1602 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1603 | return ret; |
| 1604 | } |
| 1605 | |
| 1606 | static int wlfw_athdiag_read_send_sync_msg(struct icnss_priv *priv, |
| 1607 | uint32_t offset, uint32_t mem_type, |
| 1608 | uint32_t data_len, uint8_t *data) |
| 1609 | { |
| 1610 | int ret; |
| 1611 | struct wlfw_athdiag_read_req_msg_v01 req; |
| 1612 | struct wlfw_athdiag_read_resp_msg_v01 *resp = NULL; |
| 1613 | struct msg_desc req_desc, resp_desc; |
| 1614 | |
| 1615 | if (!priv->wlfw_clnt) { |
| 1616 | ret = -ENODEV; |
| 1617 | goto out; |
| 1618 | } |
| 1619 | |
| 1620 | icnss_pr_dbg("Diag read: state 0x%lx, offset %x, mem_type %x, data_len %u\n", |
| 1621 | priv->state, offset, mem_type, data_len); |
| 1622 | |
| 1623 | resp = kzalloc(sizeof(*resp), GFP_KERNEL); |
| 1624 | if (!resp) { |
| 1625 | ret = -ENOMEM; |
| 1626 | goto out; |
| 1627 | } |
| 1628 | memset(&req, 0, sizeof(req)); |
| 1629 | |
| 1630 | req.offset = offset; |
| 1631 | req.mem_type = mem_type; |
| 1632 | req.data_len = data_len; |
| 1633 | |
| 1634 | req_desc.max_msg_len = WLFW_ATHDIAG_READ_REQ_MSG_V01_MAX_MSG_LEN; |
| 1635 | req_desc.msg_id = QMI_WLFW_ATHDIAG_READ_REQ_V01; |
| 1636 | req_desc.ei_array = wlfw_athdiag_read_req_msg_v01_ei; |
| 1637 | |
| 1638 | resp_desc.max_msg_len = WLFW_ATHDIAG_READ_RESP_MSG_V01_MAX_MSG_LEN; |
| 1639 | resp_desc.msg_id = QMI_WLFW_ATHDIAG_READ_RESP_V01; |
| 1640 | resp_desc.ei_array = wlfw_athdiag_read_resp_msg_v01_ei; |
| 1641 | |
| 1642 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1643 | &resp_desc, resp, sizeof(*resp), |
| 1644 | WLFW_TIMEOUT_MS); |
| 1645 | if (ret < 0) { |
| 1646 | icnss_pr_err("send athdiag read req failed %d\n", ret); |
| 1647 | goto out; |
| 1648 | } |
| 1649 | |
| 1650 | if (resp->resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1651 | icnss_pr_err("QMI athdiag read request rejected, result:%d error:%d\n", |
| 1652 | resp->resp.result, resp->resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1653 | ret = -resp->resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1654 | goto out; |
| 1655 | } |
| 1656 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1657 | if (!resp->data_valid || resp->data_len < data_len) { |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1658 | icnss_pr_err("Athdiag read data is invalid, data_valid = %u, data_len = %u\n", |
| 1659 | resp->data_valid, resp->data_len); |
| 1660 | ret = -EINVAL; |
| 1661 | goto out; |
| 1662 | } |
| 1663 | |
| 1664 | memcpy(data, resp->data, resp->data_len); |
| 1665 | |
| 1666 | out: |
| 1667 | kfree(resp); |
| 1668 | return ret; |
| 1669 | } |
| 1670 | |
| 1671 | static int wlfw_athdiag_write_send_sync_msg(struct icnss_priv *priv, |
| 1672 | uint32_t offset, uint32_t mem_type, |
| 1673 | uint32_t data_len, uint8_t *data) |
| 1674 | { |
| 1675 | int ret; |
| 1676 | struct wlfw_athdiag_write_req_msg_v01 *req = NULL; |
| 1677 | struct wlfw_athdiag_write_resp_msg_v01 resp; |
| 1678 | struct msg_desc req_desc, resp_desc; |
| 1679 | |
| 1680 | if (!priv->wlfw_clnt) { |
| 1681 | ret = -ENODEV; |
| 1682 | goto out; |
| 1683 | } |
| 1684 | |
| 1685 | icnss_pr_dbg("Diag write: state 0x%lx, offset %x, mem_type %x, data_len %u, data %p\n", |
| 1686 | priv->state, offset, mem_type, data_len, data); |
| 1687 | |
| 1688 | req = kzalloc(sizeof(*req), GFP_KERNEL); |
| 1689 | if (!req) { |
| 1690 | ret = -ENOMEM; |
| 1691 | goto out; |
| 1692 | } |
| 1693 | memset(&resp, 0, sizeof(resp)); |
| 1694 | |
| 1695 | req->offset = offset; |
| 1696 | req->mem_type = mem_type; |
| 1697 | req->data_len = data_len; |
| 1698 | memcpy(req->data, data, data_len); |
| 1699 | |
| 1700 | req_desc.max_msg_len = WLFW_ATHDIAG_WRITE_REQ_MSG_V01_MAX_MSG_LEN; |
| 1701 | req_desc.msg_id = QMI_WLFW_ATHDIAG_WRITE_REQ_V01; |
| 1702 | req_desc.ei_array = wlfw_athdiag_write_req_msg_v01_ei; |
| 1703 | |
| 1704 | resp_desc.max_msg_len = WLFW_ATHDIAG_WRITE_RESP_MSG_V01_MAX_MSG_LEN; |
| 1705 | resp_desc.msg_id = QMI_WLFW_ATHDIAG_WRITE_RESP_V01; |
| 1706 | resp_desc.ei_array = wlfw_athdiag_write_resp_msg_v01_ei; |
| 1707 | |
| 1708 | ret = qmi_send_req_wait(penv->wlfw_clnt, &req_desc, req, sizeof(*req), |
| 1709 | &resp_desc, &resp, sizeof(resp), |
| 1710 | WLFW_TIMEOUT_MS); |
| 1711 | if (ret < 0) { |
| 1712 | icnss_pr_err("send athdiag write req failed %d\n", ret); |
| 1713 | goto out; |
| 1714 | } |
| 1715 | |
| 1716 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1717 | icnss_pr_err("QMI athdiag write request rejected, result:%d error:%d\n", |
| 1718 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1719 | ret = -resp.resp.result; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1720 | goto out; |
| 1721 | } |
| 1722 | out: |
| 1723 | kfree(req); |
| 1724 | return ret; |
| 1725 | } |
| 1726 | |
Yuanyuan Liu | 4c497ff | 2016-12-16 16:36:08 -0800 | [diff] [blame] | 1727 | static int icnss_decode_rejuvenate_ind(void *msg, unsigned int msg_len) |
| 1728 | { |
| 1729 | struct msg_desc ind_desc; |
| 1730 | struct wlfw_rejuvenate_ind_msg_v01 ind_msg; |
| 1731 | int ret = 0; |
| 1732 | |
| 1733 | if (!penv || !penv->wlfw_clnt) { |
| 1734 | ret = -ENODEV; |
| 1735 | goto out; |
| 1736 | } |
| 1737 | |
| 1738 | memset(&ind_msg, 0, sizeof(ind_msg)); |
| 1739 | |
| 1740 | ind_desc.msg_id = QMI_WLFW_REJUVENATE_IND_V01; |
| 1741 | ind_desc.max_msg_len = WLFW_REJUVENATE_IND_MSG_V01_MAX_MSG_LEN; |
| 1742 | ind_desc.ei_array = wlfw_rejuvenate_ind_msg_v01_ei; |
| 1743 | |
| 1744 | ret = qmi_kernel_decode(&ind_desc, &ind_msg, msg, msg_len); |
| 1745 | if (ret < 0) { |
| 1746 | icnss_pr_err("Failed to decode rejuvenate ind message: ret %d, msg_len %u\n", |
| 1747 | ret, msg_len); |
| 1748 | goto out; |
| 1749 | } |
| 1750 | |
| 1751 | if (ind_msg.cause_for_rejuvenation_valid) |
| 1752 | penv->cause_for_rejuvenation = ind_msg.cause_for_rejuvenation; |
| 1753 | else |
| 1754 | penv->cause_for_rejuvenation = 0; |
| 1755 | if (ind_msg.requesting_sub_system_valid) |
| 1756 | penv->requesting_sub_system = ind_msg.requesting_sub_system; |
| 1757 | else |
| 1758 | penv->requesting_sub_system = 0; |
| 1759 | if (ind_msg.line_number_valid) |
| 1760 | penv->line_number = ind_msg.line_number; |
| 1761 | else |
| 1762 | penv->line_number = 0; |
| 1763 | if (ind_msg.function_name_valid) |
| 1764 | memcpy(penv->function_name, ind_msg.function_name, |
| 1765 | QMI_WLFW_FUNCTION_NAME_LEN_V01 + 1); |
| 1766 | else |
| 1767 | memset(penv->function_name, 0, |
| 1768 | QMI_WLFW_FUNCTION_NAME_LEN_V01 + 1); |
| 1769 | |
| 1770 | icnss_pr_info("Cause for rejuvenation: 0x%x, requesting sub-system: 0x%x, line number: %u, function name: %s\n", |
| 1771 | penv->cause_for_rejuvenation, |
| 1772 | penv->requesting_sub_system, |
| 1773 | penv->line_number, |
| 1774 | penv->function_name); |
| 1775 | |
| 1776 | penv->stats.rejuvenate_ind++; |
| 1777 | out: |
| 1778 | return ret; |
| 1779 | } |
| 1780 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1781 | static int wlfw_rejuvenate_ack_send_sync_msg(struct icnss_priv *priv) |
| 1782 | { |
| 1783 | int ret; |
| 1784 | struct wlfw_rejuvenate_ack_req_msg_v01 req; |
| 1785 | struct wlfw_rejuvenate_ack_resp_msg_v01 resp; |
| 1786 | struct msg_desc req_desc, resp_desc; |
| 1787 | |
| 1788 | icnss_pr_dbg("Sending rejuvenate ack request, state: 0x%lx\n", |
| 1789 | priv->state); |
| 1790 | |
| 1791 | memset(&req, 0, sizeof(req)); |
| 1792 | memset(&resp, 0, sizeof(resp)); |
| 1793 | |
| 1794 | req_desc.max_msg_len = WLFW_REJUVENATE_ACK_REQ_MSG_V01_MAX_MSG_LEN; |
| 1795 | req_desc.msg_id = QMI_WLFW_REJUVENATE_ACK_REQ_V01; |
| 1796 | req_desc.ei_array = wlfw_rejuvenate_ack_req_msg_v01_ei; |
| 1797 | |
| 1798 | resp_desc.max_msg_len = WLFW_REJUVENATE_ACK_RESP_MSG_V01_MAX_MSG_LEN; |
| 1799 | resp_desc.msg_id = QMI_WLFW_REJUVENATE_ACK_RESP_V01; |
| 1800 | resp_desc.ei_array = wlfw_rejuvenate_ack_resp_msg_v01_ei; |
| 1801 | |
| 1802 | priv->stats.rejuvenate_ack_req++; |
| 1803 | ret = qmi_send_req_wait(priv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1804 | &resp_desc, &resp, sizeof(resp), |
| 1805 | WLFW_TIMEOUT_MS); |
| 1806 | if (ret < 0) { |
| 1807 | icnss_pr_err("Send rejuvenate ack req failed %d\n", ret); |
| 1808 | goto out; |
| 1809 | } |
| 1810 | |
| 1811 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1812 | icnss_pr_err("QMI rejuvenate ack request rejected, result:%d error %d\n", |
| 1813 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1814 | ret = -resp.resp.result; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1815 | goto out; |
| 1816 | } |
| 1817 | priv->stats.rejuvenate_ack_resp++; |
| 1818 | return 0; |
| 1819 | |
| 1820 | out: |
| 1821 | priv->stats.rejuvenate_ack_err++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1822 | ICNSS_QMI_ASSERT(); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1823 | return ret; |
| 1824 | } |
| 1825 | |
| 1826 | static int wlfw_dynamic_feature_mask_send_sync_msg(struct icnss_priv *priv, |
| 1827 | uint64_t dynamic_feature_mask) |
| 1828 | { |
| 1829 | int ret; |
| 1830 | struct wlfw_dynamic_feature_mask_req_msg_v01 req; |
| 1831 | struct wlfw_dynamic_feature_mask_resp_msg_v01 resp; |
| 1832 | struct msg_desc req_desc, resp_desc; |
| 1833 | |
| 1834 | if (!test_bit(ICNSS_WLFW_QMI_CONNECTED, &priv->state)) { |
| 1835 | icnss_pr_err("Invalid state for dynamic feature: 0x%lx\n", |
| 1836 | priv->state); |
| 1837 | return -EINVAL; |
| 1838 | } |
| 1839 | |
| 1840 | if (!test_bit(FW_REJUVENATE_ENABLE, &quirks)) { |
| 1841 | icnss_pr_dbg("FW rejuvenate is disabled from quirks\n"); |
| 1842 | return 0; |
| 1843 | } |
| 1844 | |
| 1845 | icnss_pr_dbg("Sending dynamic feature mask request, val 0x%llx, state: 0x%lx\n", |
| 1846 | dynamic_feature_mask, priv->state); |
| 1847 | |
| 1848 | memset(&req, 0, sizeof(req)); |
| 1849 | memset(&resp, 0, sizeof(resp)); |
| 1850 | |
| 1851 | req.mask_valid = 1; |
| 1852 | req.mask = dynamic_feature_mask; |
| 1853 | |
| 1854 | req_desc.max_msg_len = |
| 1855 | WLFW_DYNAMIC_FEATURE_MASK_REQ_MSG_V01_MAX_MSG_LEN; |
| 1856 | req_desc.msg_id = QMI_WLFW_DYNAMIC_FEATURE_MASK_REQ_V01; |
| 1857 | req_desc.ei_array = wlfw_dynamic_feature_mask_req_msg_v01_ei; |
| 1858 | |
| 1859 | resp_desc.max_msg_len = |
| 1860 | WLFW_DYNAMIC_FEATURE_MASK_RESP_MSG_V01_MAX_MSG_LEN; |
| 1861 | resp_desc.msg_id = QMI_WLFW_DYNAMIC_FEATURE_MASK_RESP_V01; |
| 1862 | resp_desc.ei_array = wlfw_dynamic_feature_mask_resp_msg_v01_ei; |
| 1863 | |
| 1864 | ret = qmi_send_req_wait(priv->wlfw_clnt, &req_desc, &req, sizeof(req), |
| 1865 | &resp_desc, &resp, sizeof(resp), |
| 1866 | WLFW_TIMEOUT_MS); |
| 1867 | if (ret < 0) { |
| 1868 | icnss_pr_err("Send dynamic feature mask req failed %d\n", ret); |
| 1869 | goto out; |
| 1870 | } |
| 1871 | |
| 1872 | if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { |
| 1873 | icnss_pr_err("QMI dynamic feature mask request rejected, result:%d error %d\n", |
| 1874 | resp.resp.result, resp.resp.error); |
Anurag Chouhan | 52a48a1 | 2017-09-08 18:40:14 +0530 | [diff] [blame] | 1875 | ret = -resp.resp.result; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1876 | goto out; |
| 1877 | } |
| 1878 | |
| 1879 | icnss_pr_dbg("prev_mask_valid %u, prev_mask 0x%llx, curr_maks_valid %u, curr_mask 0x%llx\n", |
| 1880 | resp.prev_mask_valid, resp.prev_mask, |
| 1881 | resp.curr_mask_valid, resp.curr_mask); |
| 1882 | |
| 1883 | return 0; |
| 1884 | |
| 1885 | out: |
| 1886 | return ret; |
| 1887 | } |
| 1888 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1889 | static void icnss_qmi_wlfw_clnt_notify_work(struct work_struct *work) |
| 1890 | { |
| 1891 | int ret; |
| 1892 | |
| 1893 | if (!penv || !penv->wlfw_clnt) |
| 1894 | return; |
| 1895 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1896 | icnss_pr_vdbg("Receiving Event in work queue context\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1897 | |
| 1898 | do { |
| 1899 | } while ((ret = qmi_recv_msg(penv->wlfw_clnt)) == 0); |
| 1900 | |
| 1901 | if (ret != -ENOMSG) |
| 1902 | icnss_pr_err("Error receiving message: %d\n", ret); |
| 1903 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1904 | icnss_pr_vdbg("Receiving Event completed\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | static void icnss_qmi_wlfw_clnt_notify(struct qmi_handle *handle, |
| 1908 | enum qmi_event_type event, void *notify_priv) |
| 1909 | { |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1910 | icnss_pr_vdbg("QMI client notify: %d\n", event); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1911 | |
| 1912 | if (!penv || !penv->wlfw_clnt) |
| 1913 | return; |
| 1914 | |
| 1915 | switch (event) { |
| 1916 | case QMI_RECV_MSG: |
| 1917 | schedule_work(&penv->qmi_recv_msg_work); |
| 1918 | break; |
| 1919 | default: |
| 1920 | icnss_pr_dbg("Unknown Event: %d\n", event); |
| 1921 | break; |
| 1922 | } |
| 1923 | } |
| 1924 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1925 | static int icnss_call_driver_uevent(struct icnss_priv *priv, |
| 1926 | enum icnss_uevent uevent, void *data) |
| 1927 | { |
| 1928 | struct icnss_uevent_data uevent_data; |
| 1929 | |
| 1930 | if (!priv->ops || !priv->ops->uevent) |
| 1931 | return 0; |
| 1932 | |
| 1933 | icnss_pr_dbg("Calling driver uevent state: 0x%lx, uevent: %d\n", |
| 1934 | priv->state, uevent); |
| 1935 | |
| 1936 | uevent_data.uevent = uevent; |
| 1937 | uevent_data.data = data; |
| 1938 | |
| 1939 | return priv->ops->uevent(&priv->pdev->dev, &uevent_data); |
| 1940 | } |
| 1941 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1942 | static void icnss_qmi_wlfw_clnt_ind(struct qmi_handle *handle, |
| 1943 | unsigned int msg_id, void *msg, |
| 1944 | unsigned int msg_len, void *ind_cb_priv) |
| 1945 | { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1946 | struct icnss_event_pd_service_down_data *event_data; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1947 | struct icnss_uevent_fw_down_data fw_down_data; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1948 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1949 | if (!penv) |
| 1950 | return; |
| 1951 | |
| 1952 | icnss_pr_dbg("Received Ind 0x%x, msg_len: %d\n", msg_id, msg_len); |
| 1953 | |
Sameer Thalappil | 93c0073 | 2017-08-18 13:02:32 -0700 | [diff] [blame] | 1954 | if (test_bit(ICNSS_FW_DOWN, &penv->state)) { |
| 1955 | icnss_pr_dbg("FW down, ignoring 0x%x, state: 0x%lx\n", |
| 1956 | msg_id, penv->state); |
| 1957 | return; |
| 1958 | } |
| 1959 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1960 | switch (msg_id) { |
| 1961 | case QMI_WLFW_FW_READY_IND_V01: |
| 1962 | icnss_driver_event_post(ICNSS_DRIVER_EVENT_FW_READY_IND, |
| 1963 | 0, NULL); |
| 1964 | break; |
| 1965 | case QMI_WLFW_MSA_READY_IND_V01: |
| 1966 | icnss_pr_dbg("Received MSA Ready Indication msg_id 0x%x\n", |
| 1967 | msg_id); |
| 1968 | penv->stats.msa_ready_ind++; |
| 1969 | break; |
| 1970 | case QMI_WLFW_PIN_CONNECT_RESULT_IND_V01: |
| 1971 | icnss_pr_dbg("Received Pin Connect Test Result msg_id 0x%x\n", |
| 1972 | msg_id); |
| 1973 | icnss_qmi_pin_connect_result_ind(msg, msg_len); |
| 1974 | break; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1975 | case QMI_WLFW_REJUVENATE_IND_V01: |
| 1976 | icnss_pr_dbg("Received Rejuvenate Indication msg_id 0x%x, state: 0x%lx\n", |
| 1977 | msg_id, penv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1978 | |
| 1979 | icnss_ignore_qmi_timeout(true); |
Yuanyuan Liu | 4c497ff | 2016-12-16 16:36:08 -0800 | [diff] [blame] | 1980 | icnss_decode_rejuvenate_ind(msg, msg_len); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1981 | event_data = kzalloc(sizeof(*event_data), GFP_KERNEL); |
| 1982 | if (event_data == NULL) |
| 1983 | return; |
| 1984 | event_data->crashed = true; |
| 1985 | event_data->fw_rejuvenate = true; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 1986 | fw_down_data.crashed = true; |
| 1987 | icnss_call_driver_uevent(penv, ICNSS_UEVENT_FW_DOWN, |
| 1988 | &fw_down_data); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 1989 | icnss_driver_event_post(ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN, |
| 1990 | 0, event_data); |
| 1991 | break; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 1992 | default: |
| 1993 | icnss_pr_err("Invalid msg_id 0x%x\n", msg_id); |
| 1994 | break; |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | static int icnss_driver_event_server_arrive(void *data) |
| 1999 | { |
| 2000 | int ret = 0; |
| 2001 | |
| 2002 | if (!penv) |
| 2003 | return -ENODEV; |
| 2004 | |
| 2005 | set_bit(ICNSS_WLFW_EXISTS, &penv->state); |
Sameer Thalappil | 93c0073 | 2017-08-18 13:02:32 -0700 | [diff] [blame] | 2006 | clear_bit(ICNSS_FW_DOWN, &penv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2007 | |
| 2008 | penv->wlfw_clnt = qmi_handle_create(icnss_qmi_wlfw_clnt_notify, penv); |
| 2009 | if (!penv->wlfw_clnt) { |
| 2010 | icnss_pr_err("QMI client handle create failed\n"); |
| 2011 | ret = -ENOMEM; |
| 2012 | goto out; |
| 2013 | } |
| 2014 | |
| 2015 | ret = qmi_connect_to_service(penv->wlfw_clnt, WLFW_SERVICE_ID_V01, |
| 2016 | WLFW_SERVICE_VERS_V01, |
| 2017 | WLFW_SERVICE_INS_ID_V01); |
| 2018 | if (ret < 0) { |
| 2019 | icnss_pr_err("QMI WLAN Service not found : %d\n", ret); |
| 2020 | goto fail; |
| 2021 | } |
| 2022 | |
| 2023 | ret = qmi_register_ind_cb(penv->wlfw_clnt, |
| 2024 | icnss_qmi_wlfw_clnt_ind, penv); |
| 2025 | if (ret < 0) { |
| 2026 | icnss_pr_err("Failed to register indication callback: %d\n", |
| 2027 | ret); |
| 2028 | goto fail; |
| 2029 | } |
| 2030 | |
| 2031 | set_bit(ICNSS_WLFW_QMI_CONNECTED, &penv->state); |
| 2032 | |
| 2033 | icnss_pr_info("QMI Server Connected: state: 0x%lx\n", penv->state); |
| 2034 | |
| 2035 | ret = icnss_hw_power_on(penv); |
| 2036 | if (ret) |
| 2037 | goto fail; |
| 2038 | |
| 2039 | ret = wlfw_ind_register_send_sync_msg(); |
| 2040 | if (ret < 0) |
| 2041 | goto err_power_on; |
| 2042 | |
| 2043 | if (!penv->msa_va) { |
| 2044 | icnss_pr_err("Invalid MSA address\n"); |
| 2045 | ret = -EINVAL; |
| 2046 | goto err_power_on; |
| 2047 | } |
| 2048 | |
| 2049 | ret = wlfw_msa_mem_info_send_sync_msg(); |
| 2050 | if (ret < 0) |
| 2051 | goto err_power_on; |
| 2052 | |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 2053 | if (!test_bit(ICNSS_MSA0_ASSIGNED, &penv->state)) { |
| 2054 | ret = icnss_assign_msa_perm_all(penv, ICNSS_MSA_PERM_WLAN_HW_RW); |
| 2055 | if (ret < 0) |
| 2056 | goto err_power_on; |
| 2057 | set_bit(ICNSS_MSA0_ASSIGNED, &penv->state); |
| 2058 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2059 | |
| 2060 | ret = wlfw_msa_ready_send_sync_msg(); |
| 2061 | if (ret < 0) |
| 2062 | goto err_setup_msa; |
| 2063 | |
| 2064 | ret = wlfw_cap_send_sync_msg(); |
| 2065 | if (ret < 0) |
| 2066 | goto err_setup_msa; |
| 2067 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2068 | wlfw_dynamic_feature_mask_send_sync_msg(penv, |
| 2069 | dynamic_feature_mask); |
| 2070 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2071 | icnss_init_vph_monitor(penv); |
| 2072 | |
| 2073 | return ret; |
| 2074 | |
| 2075 | err_setup_msa: |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 2076 | icnss_assign_msa_perm_all(penv, ICNSS_MSA_PERM_HLOS_ALL); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2077 | err_power_on: |
| 2078 | icnss_hw_power_off(penv); |
| 2079 | fail: |
| 2080 | qmi_handle_destroy(penv->wlfw_clnt); |
| 2081 | penv->wlfw_clnt = NULL; |
| 2082 | out: |
| 2083 | ICNSS_ASSERT(0); |
| 2084 | return ret; |
| 2085 | } |
| 2086 | |
| 2087 | static int icnss_driver_event_server_exit(void *data) |
| 2088 | { |
| 2089 | if (!penv || !penv->wlfw_clnt) |
| 2090 | return -ENODEV; |
| 2091 | |
| 2092 | icnss_pr_info("QMI Service Disconnected: 0x%lx\n", penv->state); |
| 2093 | |
| 2094 | if (!test_bit(VBATT_DISABLE, &quirks) && penv->adc_tm_dev) |
| 2095 | qpnp_adc_tm_disable_chan_meas(penv->adc_tm_dev, |
| 2096 | &penv->vph_monitor_params); |
| 2097 | |
| 2098 | qmi_handle_destroy(penv->wlfw_clnt); |
| 2099 | |
| 2100 | clear_bit(ICNSS_WLFW_QMI_CONNECTED, &penv->state); |
| 2101 | penv->wlfw_clnt = NULL; |
| 2102 | |
| 2103 | return 0; |
| 2104 | } |
| 2105 | |
| 2106 | static int icnss_call_driver_probe(struct icnss_priv *priv) |
| 2107 | { |
Yuanyuan Liu | 237c0ad | 2017-10-09 17:58:17 -0700 | [diff] [blame] | 2108 | int ret = 0; |
| 2109 | int probe_cnt = 0; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2110 | |
| 2111 | if (!priv->ops || !priv->ops->probe) |
| 2112 | return 0; |
| 2113 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2114 | if (test_bit(ICNSS_DRIVER_PROBED, &priv->state)) |
| 2115 | return -EINVAL; |
| 2116 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2117 | icnss_pr_dbg("Calling driver probe state: 0x%lx\n", priv->state); |
| 2118 | |
| 2119 | icnss_hw_power_on(priv); |
| 2120 | |
Yuanyuan Liu | 237c0ad | 2017-10-09 17:58:17 -0700 | [diff] [blame] | 2121 | while (probe_cnt < ICNSS_MAX_PROBE_CNT) { |
| 2122 | ret = priv->ops->probe(&priv->pdev->dev); |
| 2123 | probe_cnt++; |
| 2124 | if (ret != -EPROBE_DEFER) |
| 2125 | break; |
| 2126 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2127 | if (ret < 0) { |
Yuanyuan Liu | 237c0ad | 2017-10-09 17:58:17 -0700 | [diff] [blame] | 2128 | icnss_pr_err("Driver probe failed: %d, state: 0x%lx, probe_cnt: %d\n", |
| 2129 | ret, priv->state, probe_cnt); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2130 | goto out; |
| 2131 | } |
| 2132 | |
| 2133 | set_bit(ICNSS_DRIVER_PROBED, &priv->state); |
| 2134 | |
| 2135 | return 0; |
| 2136 | |
| 2137 | out: |
| 2138 | icnss_hw_power_off(priv); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2139 | return ret; |
| 2140 | } |
| 2141 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2142 | static int icnss_call_driver_shutdown(struct icnss_priv *priv) |
| 2143 | { |
| 2144 | if (!test_bit(ICNSS_DRIVER_PROBED, &penv->state)) |
| 2145 | goto out; |
| 2146 | |
| 2147 | if (!priv->ops || !priv->ops->shutdown) |
| 2148 | goto out; |
| 2149 | |
Anurag Chouhan | fa0c70d | 2017-04-10 17:26:47 +0530 | [diff] [blame] | 2150 | if (test_bit(ICNSS_SHUTDOWN_DONE, &penv->state)) |
| 2151 | goto out; |
| 2152 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2153 | icnss_pr_dbg("Calling driver shutdown state: 0x%lx\n", priv->state); |
| 2154 | |
| 2155 | priv->ops->shutdown(&priv->pdev->dev); |
Anurag Chouhan | fa0c70d | 2017-04-10 17:26:47 +0530 | [diff] [blame] | 2156 | set_bit(ICNSS_SHUTDOWN_DONE, &penv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2157 | |
| 2158 | out: |
| 2159 | return 0; |
| 2160 | } |
| 2161 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2162 | static int icnss_pd_restart_complete(struct icnss_priv *priv) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2163 | { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2164 | int ret; |
| 2165 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2166 | icnss_pm_relax(priv); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2167 | |
Anurag Chouhan | 9de2119 | 2017-08-08 15:30:02 +0530 | [diff] [blame] | 2168 | icnss_call_driver_shutdown(priv); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2169 | |
| 2170 | clear_bit(ICNSS_PD_RESTART, &priv->state); |
| 2171 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2172 | if (!priv->ops || !priv->ops->reinit) |
| 2173 | goto out; |
| 2174 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2175 | if (!test_bit(ICNSS_DRIVER_PROBED, &priv->state)) |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2176 | goto call_probe; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2177 | |
| 2178 | icnss_pr_dbg("Calling driver reinit state: 0x%lx\n", priv->state); |
| 2179 | |
| 2180 | icnss_hw_power_on(priv); |
| 2181 | |
| 2182 | ret = priv->ops->reinit(&priv->pdev->dev); |
| 2183 | if (ret < 0) { |
| 2184 | icnss_pr_err("Driver reinit failed: %d, state: 0x%lx\n", |
| 2185 | ret, priv->state); |
| 2186 | ICNSS_ASSERT(false); |
| 2187 | goto out_power_off; |
| 2188 | } |
| 2189 | |
| 2190 | out: |
Anurag Chouhan | fa0c70d | 2017-04-10 17:26:47 +0530 | [diff] [blame] | 2191 | clear_bit(ICNSS_SHUTDOWN_DONE, &penv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2192 | return 0; |
| 2193 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2194 | call_probe: |
| 2195 | return icnss_call_driver_probe(priv); |
| 2196 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2197 | out_power_off: |
| 2198 | icnss_hw_power_off(priv); |
| 2199 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2200 | return ret; |
| 2201 | } |
| 2202 | |
| 2203 | |
| 2204 | static int icnss_driver_event_fw_ready_ind(void *data) |
| 2205 | { |
| 2206 | int ret = 0; |
| 2207 | |
| 2208 | if (!penv) |
| 2209 | return -ENODEV; |
| 2210 | |
| 2211 | set_bit(ICNSS_FW_READY, &penv->state); |
| 2212 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2213 | icnss_call_driver_uevent(penv, ICNSS_UEVENT_FW_READY, NULL); |
| 2214 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2215 | icnss_pr_info("WLAN FW is ready: 0x%lx\n", penv->state); |
| 2216 | |
| 2217 | icnss_hw_power_off(penv); |
| 2218 | |
| 2219 | if (!penv->pdev) { |
| 2220 | icnss_pr_err("Device is not ready\n"); |
| 2221 | ret = -ENODEV; |
| 2222 | goto out; |
| 2223 | } |
| 2224 | |
| 2225 | if (test_bit(ICNSS_PD_RESTART, &penv->state)) |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2226 | ret = icnss_pd_restart_complete(penv); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2227 | else |
| 2228 | ret = icnss_call_driver_probe(penv); |
| 2229 | |
| 2230 | out: |
| 2231 | return ret; |
| 2232 | } |
| 2233 | |
| 2234 | static int icnss_driver_event_register_driver(void *data) |
| 2235 | { |
| 2236 | int ret = 0; |
Yuanyuan Liu | 237c0ad | 2017-10-09 17:58:17 -0700 | [diff] [blame] | 2237 | int probe_cnt = 0; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2238 | |
| 2239 | if (penv->ops) |
| 2240 | return -EEXIST; |
| 2241 | |
| 2242 | penv->ops = data; |
| 2243 | |
| 2244 | if (test_bit(SKIP_QMI, &quirks)) |
| 2245 | set_bit(ICNSS_FW_READY, &penv->state); |
| 2246 | |
| 2247 | if (!test_bit(ICNSS_FW_READY, &penv->state)) { |
| 2248 | icnss_pr_dbg("FW is not ready yet, state: 0x%lx\n", |
| 2249 | penv->state); |
| 2250 | goto out; |
| 2251 | } |
| 2252 | |
| 2253 | ret = icnss_hw_power_on(penv); |
| 2254 | if (ret) |
| 2255 | goto out; |
| 2256 | |
Yuanyuan Liu | 237c0ad | 2017-10-09 17:58:17 -0700 | [diff] [blame] | 2257 | while (probe_cnt < ICNSS_MAX_PROBE_CNT) { |
| 2258 | ret = penv->ops->probe(&penv->pdev->dev); |
| 2259 | probe_cnt++; |
| 2260 | if (ret != -EPROBE_DEFER) |
| 2261 | break; |
| 2262 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2263 | if (ret) { |
Yuanyuan Liu | 237c0ad | 2017-10-09 17:58:17 -0700 | [diff] [blame] | 2264 | icnss_pr_err("Driver probe failed: %d, state: 0x%lx, probe_cnt: %d\n", |
| 2265 | ret, penv->state, probe_cnt); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2266 | goto power_off; |
| 2267 | } |
| 2268 | |
| 2269 | set_bit(ICNSS_DRIVER_PROBED, &penv->state); |
| 2270 | |
| 2271 | return 0; |
| 2272 | |
| 2273 | power_off: |
| 2274 | icnss_hw_power_off(penv); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2275 | out: |
| 2276 | return ret; |
| 2277 | } |
| 2278 | |
| 2279 | static int icnss_driver_event_unregister_driver(void *data) |
| 2280 | { |
| 2281 | if (!test_bit(ICNSS_DRIVER_PROBED, &penv->state)) { |
| 2282 | penv->ops = NULL; |
| 2283 | goto out; |
| 2284 | } |
| 2285 | |
| 2286 | if (penv->ops) |
| 2287 | penv->ops->remove(&penv->pdev->dev); |
| 2288 | |
| 2289 | clear_bit(ICNSS_DRIVER_PROBED, &penv->state); |
| 2290 | |
| 2291 | penv->ops = NULL; |
| 2292 | |
| 2293 | icnss_hw_power_off(penv); |
| 2294 | |
| 2295 | out: |
| 2296 | return 0; |
| 2297 | } |
| 2298 | |
| 2299 | static int icnss_call_driver_remove(struct icnss_priv *priv) |
| 2300 | { |
| 2301 | icnss_pr_dbg("Calling driver remove state: 0x%lx\n", priv->state); |
| 2302 | |
| 2303 | clear_bit(ICNSS_FW_READY, &priv->state); |
| 2304 | |
| 2305 | if (!test_bit(ICNSS_DRIVER_PROBED, &penv->state)) |
| 2306 | return 0; |
| 2307 | |
| 2308 | if (!priv->ops || !priv->ops->remove) |
| 2309 | return 0; |
| 2310 | |
| 2311 | penv->ops->remove(&priv->pdev->dev); |
| 2312 | |
| 2313 | clear_bit(ICNSS_DRIVER_PROBED, &priv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2314 | |
| 2315 | icnss_hw_power_off(penv); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2316 | |
| 2317 | return 0; |
| 2318 | } |
| 2319 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2320 | static int icnss_fw_crashed(struct icnss_priv *priv, |
| 2321 | struct icnss_event_pd_service_down_data *event_data) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2322 | { |
Anurag Chouhan | 9de2119 | 2017-08-08 15:30:02 +0530 | [diff] [blame] | 2323 | icnss_pr_dbg("FW crashed, state: 0x%lx\n", priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2324 | |
| 2325 | set_bit(ICNSS_PD_RESTART, &priv->state); |
| 2326 | clear_bit(ICNSS_FW_READY, &priv->state); |
| 2327 | |
| 2328 | icnss_pm_stay_awake(priv); |
| 2329 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2330 | if (test_bit(ICNSS_DRIVER_PROBED, &priv->state)) |
| 2331 | icnss_call_driver_uevent(priv, ICNSS_UEVENT_FW_CRASHED, NULL); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2332 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2333 | if (event_data->fw_rejuvenate) |
| 2334 | wlfw_rejuvenate_ack_send_sync_msg(priv); |
| 2335 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2336 | return 0; |
| 2337 | } |
| 2338 | |
| 2339 | static int icnss_driver_event_pd_service_down(struct icnss_priv *priv, |
| 2340 | void *data) |
| 2341 | { |
| 2342 | int ret = 0; |
| 2343 | struct icnss_event_pd_service_down_data *event_data = data; |
| 2344 | |
| 2345 | if (!test_bit(ICNSS_WLFW_EXISTS, &priv->state)) |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2346 | goto out; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2347 | |
| 2348 | if (test_bit(ICNSS_PD_RESTART, &priv->state)) { |
| 2349 | icnss_pr_err("PD Down while recovery inprogress, crashed: %d, state: 0x%lx\n", |
| 2350 | event_data->crashed, priv->state); |
| 2351 | ICNSS_ASSERT(0); |
| 2352 | goto out; |
| 2353 | } |
| 2354 | |
| 2355 | if (event_data->crashed) |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2356 | icnss_fw_crashed(priv, event_data); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2357 | else |
| 2358 | icnss_call_driver_remove(priv); |
| 2359 | |
| 2360 | out: |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2361 | kfree(data); |
| 2362 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2363 | icnss_ignore_qmi_timeout(false); |
| 2364 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2365 | return ret; |
| 2366 | } |
| 2367 | |
| 2368 | static void icnss_driver_event_work(struct work_struct *work) |
| 2369 | { |
| 2370 | struct icnss_driver_event *event; |
| 2371 | unsigned long flags; |
| 2372 | int ret; |
| 2373 | |
| 2374 | icnss_pm_stay_awake(penv); |
| 2375 | |
| 2376 | spin_lock_irqsave(&penv->event_lock, flags); |
| 2377 | |
| 2378 | while (!list_empty(&penv->event_list)) { |
| 2379 | event = list_first_entry(&penv->event_list, |
| 2380 | struct icnss_driver_event, list); |
| 2381 | list_del(&event->list); |
| 2382 | spin_unlock_irqrestore(&penv->event_lock, flags); |
| 2383 | |
| 2384 | icnss_pr_dbg("Processing event: %s%s(%d), state: 0x%lx\n", |
| 2385 | icnss_driver_event_to_str(event->type), |
| 2386 | event->sync ? "-sync" : "", event->type, |
| 2387 | penv->state); |
| 2388 | |
| 2389 | switch (event->type) { |
| 2390 | case ICNSS_DRIVER_EVENT_SERVER_ARRIVE: |
| 2391 | ret = icnss_driver_event_server_arrive(event->data); |
| 2392 | break; |
| 2393 | case ICNSS_DRIVER_EVENT_SERVER_EXIT: |
| 2394 | ret = icnss_driver_event_server_exit(event->data); |
| 2395 | break; |
| 2396 | case ICNSS_DRIVER_EVENT_FW_READY_IND: |
| 2397 | ret = icnss_driver_event_fw_ready_ind(event->data); |
| 2398 | break; |
| 2399 | case ICNSS_DRIVER_EVENT_REGISTER_DRIVER: |
| 2400 | ret = icnss_driver_event_register_driver(event->data); |
| 2401 | break; |
| 2402 | case ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER: |
| 2403 | ret = icnss_driver_event_unregister_driver(event->data); |
| 2404 | break; |
| 2405 | case ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN: |
| 2406 | ret = icnss_driver_event_pd_service_down(penv, |
| 2407 | event->data); |
| 2408 | break; |
| 2409 | default: |
| 2410 | icnss_pr_err("Invalid Event type: %d", event->type); |
| 2411 | kfree(event); |
| 2412 | continue; |
| 2413 | } |
| 2414 | |
| 2415 | penv->stats.events[event->type].processed++; |
| 2416 | |
| 2417 | icnss_pr_dbg("Event Processed: %s%s(%d), ret: %d, state: 0x%lx\n", |
| 2418 | icnss_driver_event_to_str(event->type), |
| 2419 | event->sync ? "-sync" : "", event->type, ret, |
| 2420 | penv->state); |
| 2421 | |
| 2422 | spin_lock_irqsave(&penv->event_lock, flags); |
| 2423 | if (event->sync) { |
| 2424 | event->ret = ret; |
| 2425 | complete(&event->complete); |
| 2426 | continue; |
| 2427 | } |
| 2428 | spin_unlock_irqrestore(&penv->event_lock, flags); |
| 2429 | |
| 2430 | kfree(event); |
| 2431 | |
| 2432 | spin_lock_irqsave(&penv->event_lock, flags); |
| 2433 | } |
| 2434 | spin_unlock_irqrestore(&penv->event_lock, flags); |
| 2435 | |
| 2436 | icnss_pm_relax(penv); |
| 2437 | } |
| 2438 | |
| 2439 | static int icnss_qmi_wlfw_clnt_svc_event_notify(struct notifier_block *this, |
| 2440 | unsigned long code, |
| 2441 | void *_cmd) |
| 2442 | { |
| 2443 | int ret = 0; |
| 2444 | |
| 2445 | if (!penv) |
| 2446 | return -ENODEV; |
| 2447 | |
| 2448 | icnss_pr_dbg("Event Notify: code: %ld", code); |
| 2449 | |
| 2450 | switch (code) { |
| 2451 | case QMI_SERVER_ARRIVE: |
| 2452 | ret = icnss_driver_event_post(ICNSS_DRIVER_EVENT_SERVER_ARRIVE, |
| 2453 | 0, NULL); |
| 2454 | break; |
| 2455 | |
| 2456 | case QMI_SERVER_EXIT: |
| 2457 | ret = icnss_driver_event_post(ICNSS_DRIVER_EVENT_SERVER_EXIT, |
| 2458 | 0, NULL); |
| 2459 | break; |
| 2460 | default: |
| 2461 | icnss_pr_dbg("Invalid code: %ld", code); |
| 2462 | break; |
| 2463 | } |
| 2464 | return ret; |
| 2465 | } |
| 2466 | |
| 2467 | static int icnss_msa0_ramdump(struct icnss_priv *priv) |
| 2468 | { |
| 2469 | struct ramdump_segment segment; |
| 2470 | |
| 2471 | memset(&segment, 0, sizeof(segment)); |
| 2472 | segment.v_address = priv->msa_va; |
| 2473 | segment.size = priv->msa_mem_size; |
| 2474 | return do_ramdump(priv->msa0_dump_dev, &segment, 1); |
| 2475 | } |
| 2476 | |
| 2477 | static struct notifier_block wlfw_clnt_nb = { |
| 2478 | .notifier_call = icnss_qmi_wlfw_clnt_svc_event_notify, |
| 2479 | }; |
| 2480 | |
| 2481 | static int icnss_modem_notifier_nb(struct notifier_block *nb, |
| 2482 | unsigned long code, |
| 2483 | void *data) |
| 2484 | { |
| 2485 | struct icnss_event_pd_service_down_data *event_data; |
| 2486 | struct notif_data *notif = data; |
| 2487 | struct icnss_priv *priv = container_of(nb, struct icnss_priv, |
| 2488 | modem_ssr_nb); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2489 | struct icnss_uevent_fw_down_data fw_down_data; |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 2490 | int ret = 0; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2491 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2492 | icnss_pr_vdbg("Modem-Notify: event %lu\n", code); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2493 | |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 2494 | if (code == SUBSYS_AFTER_SHUTDOWN) { |
| 2495 | ret = icnss_assign_msa_perm_all(priv, |
| 2496 | ICNSS_MSA_PERM_DUMP_COLLECT); |
| 2497 | if (!ret) { |
| 2498 | icnss_pr_info("Collecting msa0 segment dump\n"); |
| 2499 | icnss_msa0_ramdump(priv); |
| 2500 | icnss_assign_msa_perm_all(priv, |
| 2501 | ICNSS_MSA_PERM_WLAN_HW_RW); |
| 2502 | } else { |
| 2503 | icnss_pr_err("Not able to Collect msa0 segment dump" |
| 2504 | "Apps permissions not assigned %d\n", ret); |
| 2505 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2506 | return NOTIFY_OK; |
| 2507 | } |
| 2508 | |
| 2509 | if (code != SUBSYS_BEFORE_SHUTDOWN) |
| 2510 | return NOTIFY_OK; |
| 2511 | |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 2512 | if (test_bit(ICNSS_PDR_REGISTERED, &priv->state)) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2513 | return NOTIFY_OK; |
| 2514 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2515 | icnss_pr_info("Modem went down, state: 0x%lx, crashed: %d\n", |
| 2516 | priv->state, notif->crashed); |
| 2517 | |
Sameer Thalappil | 93c0073 | 2017-08-18 13:02:32 -0700 | [diff] [blame] | 2518 | set_bit(ICNSS_FW_DOWN, &priv->state); |
| 2519 | |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2520 | if (notif->crashed) |
| 2521 | priv->stats.recovery.root_pd_crash++; |
| 2522 | else |
| 2523 | priv->stats.recovery.root_pd_shutdown++; |
| 2524 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2525 | icnss_ignore_qmi_timeout(true); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2526 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2527 | event_data = kzalloc(sizeof(*event_data), GFP_KERNEL); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2528 | |
| 2529 | if (event_data == NULL) |
| 2530 | return notifier_from_errno(-ENOMEM); |
| 2531 | |
| 2532 | event_data->crashed = notif->crashed; |
| 2533 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2534 | fw_down_data.crashed = !!notif->crashed; |
| 2535 | icnss_call_driver_uevent(priv, ICNSS_UEVENT_FW_DOWN, &fw_down_data); |
| 2536 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2537 | icnss_driver_event_post(ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN, |
| 2538 | ICNSS_EVENT_SYNC, event_data); |
| 2539 | |
| 2540 | return NOTIFY_OK; |
| 2541 | } |
| 2542 | |
| 2543 | static int icnss_modem_ssr_register_notifier(struct icnss_priv *priv) |
| 2544 | { |
| 2545 | int ret = 0; |
| 2546 | |
| 2547 | priv->modem_ssr_nb.notifier_call = icnss_modem_notifier_nb; |
| 2548 | |
| 2549 | priv->modem_notify_handler = |
| 2550 | subsys_notif_register_notifier("modem", &priv->modem_ssr_nb); |
| 2551 | |
| 2552 | if (IS_ERR(priv->modem_notify_handler)) { |
| 2553 | ret = PTR_ERR(priv->modem_notify_handler); |
| 2554 | icnss_pr_err("Modem register notifier failed: %d\n", ret); |
| 2555 | } |
| 2556 | |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 2557 | set_bit(ICNSS_SSR_REGISTERED, &priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2558 | |
| 2559 | return ret; |
| 2560 | } |
| 2561 | |
| 2562 | static int icnss_modem_ssr_unregister_notifier(struct icnss_priv *priv) |
| 2563 | { |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 2564 | if (!test_and_clear_bit(ICNSS_SSR_REGISTERED, &priv->state)) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2565 | return 0; |
| 2566 | |
| 2567 | subsys_notif_unregister_notifier(priv->modem_notify_handler, |
| 2568 | &priv->modem_ssr_nb); |
| 2569 | priv->modem_notify_handler = NULL; |
| 2570 | |
| 2571 | return 0; |
| 2572 | } |
| 2573 | |
| 2574 | static int icnss_pdr_unregister_notifier(struct icnss_priv *priv) |
| 2575 | { |
| 2576 | int i; |
| 2577 | |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 2578 | if (!test_and_clear_bit(ICNSS_PDR_REGISTERED, &priv->state)) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2579 | return 0; |
| 2580 | |
| 2581 | for (i = 0; i < priv->total_domains; i++) |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2582 | service_notif_unregister_notifier( |
| 2583 | priv->service_notifier[i].handle, |
| 2584 | &priv->service_notifier_nb); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2585 | |
| 2586 | kfree(priv->service_notifier); |
| 2587 | |
| 2588 | priv->service_notifier = NULL; |
| 2589 | |
| 2590 | return 0; |
| 2591 | } |
| 2592 | |
| 2593 | static int icnss_service_notifier_notify(struct notifier_block *nb, |
| 2594 | unsigned long notification, void *data) |
| 2595 | { |
| 2596 | struct icnss_priv *priv = container_of(nb, struct icnss_priv, |
| 2597 | service_notifier_nb); |
| 2598 | enum pd_subsys_state *state = data; |
| 2599 | struct icnss_event_pd_service_down_data *event_data; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2600 | struct icnss_uevent_fw_down_data fw_down_data; |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2601 | enum icnss_pdr_cause_index cause = ICNSS_ROOT_PD_CRASH; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2602 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2603 | icnss_pr_dbg("PD service notification: 0x%lx state: 0x%lx\n", |
| 2604 | notification, priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2605 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2606 | if (notification != SERVREG_NOTIF_SERVICE_STATE_DOWN_V01) |
| 2607 | goto done; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2608 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2609 | event_data = kzalloc(sizeof(*event_data), GFP_KERNEL); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2610 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2611 | if (event_data == NULL) |
| 2612 | return notifier_from_errno(-ENOMEM); |
| 2613 | |
Sameer Thalappil | 3bbb431 | 2017-07-25 13:24:48 -0700 | [diff] [blame] | 2614 | event_data->crashed = true; |
| 2615 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2616 | if (state == NULL) { |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2617 | priv->stats.recovery.root_pd_crash++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2618 | goto event_post; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2619 | } |
| 2620 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2621 | switch (*state) { |
| 2622 | case ROOT_PD_WDOG_BITE: |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2623 | priv->stats.recovery.root_pd_crash++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2624 | break; |
| 2625 | case ROOT_PD_SHUTDOWN: |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2626 | cause = ICNSS_ROOT_PD_SHUTDOWN; |
| 2627 | priv->stats.recovery.root_pd_shutdown++; |
Sameer Thalappil | 3bbb431 | 2017-07-25 13:24:48 -0700 | [diff] [blame] | 2628 | event_data->crashed = false; |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2629 | break; |
| 2630 | case USER_PD_STATE_CHANGE: |
| 2631 | if (test_bit(ICNSS_HOST_TRIGGERED_PDR, &priv->state)) { |
| 2632 | cause = ICNSS_HOST_ERROR; |
| 2633 | priv->stats.recovery.pdr_host_error++; |
| 2634 | } else { |
| 2635 | cause = ICNSS_FW_CRASH; |
| 2636 | priv->stats.recovery.pdr_fw_crash++; |
| 2637 | } |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2638 | break; |
| 2639 | default: |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2640 | priv->stats.recovery.root_pd_crash++; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2641 | break; |
| 2642 | } |
| 2643 | |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2644 | icnss_pr_info("PD service down, pd_state: %d, state: 0x%lx: cause: %s\n", |
| 2645 | *state, priv->state, icnss_pdr_cause[cause]); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2646 | event_post: |
Sameer Thalappil | 93c0073 | 2017-08-18 13:02:32 -0700 | [diff] [blame] | 2647 | set_bit(ICNSS_FW_DOWN, &priv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2648 | icnss_ignore_qmi_timeout(true); |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 2649 | clear_bit(ICNSS_HOST_TRIGGERED_PDR, &priv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2650 | |
| 2651 | fw_down_data.crashed = event_data->crashed; |
Yuanyuan Liu | 946f661 | 2017-10-06 15:11:54 -0700 | [diff] [blame] | 2652 | if (test_bit(ICNSS_FW_READY, &priv->state)) |
Yuanyuan Liu | 95d6eb7 | 2017-10-05 16:23:39 -0700 | [diff] [blame] | 2653 | icnss_call_driver_uevent(priv, ICNSS_UEVENT_FW_DOWN, |
| 2654 | &fw_down_data); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2655 | icnss_driver_event_post(ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN, |
| 2656 | ICNSS_EVENT_SYNC, event_data); |
| 2657 | done: |
Sameer Thalappil | 93c0073 | 2017-08-18 13:02:32 -0700 | [diff] [blame] | 2658 | if (notification == SERVREG_NOTIF_SERVICE_STATE_UP_V01) |
| 2659 | clear_bit(ICNSS_FW_DOWN, &priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2660 | return NOTIFY_OK; |
| 2661 | } |
| 2662 | |
| 2663 | static int icnss_get_service_location_notify(struct notifier_block *nb, |
| 2664 | unsigned long opcode, void *data) |
| 2665 | { |
| 2666 | struct icnss_priv *priv = container_of(nb, struct icnss_priv, |
| 2667 | get_service_nb); |
| 2668 | struct pd_qmi_client_data *pd = data; |
| 2669 | int curr_state; |
| 2670 | int ret; |
| 2671 | int i; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2672 | struct service_notifier_context *notifier; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2673 | |
| 2674 | icnss_pr_dbg("Get service notify opcode: %lu, state: 0x%lx\n", opcode, |
| 2675 | priv->state); |
| 2676 | |
| 2677 | if (opcode != LOCATOR_UP) |
| 2678 | return NOTIFY_DONE; |
| 2679 | |
| 2680 | if (pd->total_domains == 0) { |
| 2681 | icnss_pr_err("Did not find any domains\n"); |
| 2682 | ret = -ENOENT; |
| 2683 | goto out; |
| 2684 | } |
| 2685 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2686 | notifier = kcalloc(pd->total_domains, |
| 2687 | sizeof(struct service_notifier_context), |
| 2688 | GFP_KERNEL); |
| 2689 | if (!notifier) { |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2690 | ret = -ENOMEM; |
| 2691 | goto out; |
| 2692 | } |
| 2693 | |
| 2694 | priv->service_notifier_nb.notifier_call = icnss_service_notifier_notify; |
| 2695 | |
| 2696 | for (i = 0; i < pd->total_domains; i++) { |
| 2697 | icnss_pr_dbg("%d: domain_name: %s, instance_id: %d\n", i, |
| 2698 | pd->domain_list[i].name, |
| 2699 | pd->domain_list[i].instance_id); |
| 2700 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2701 | notifier[i].handle = |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2702 | service_notif_register_notifier(pd->domain_list[i].name, |
| 2703 | pd->domain_list[i].instance_id, |
| 2704 | &priv->service_notifier_nb, &curr_state); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2705 | notifier[i].instance_id = pd->domain_list[i].instance_id; |
| 2706 | strlcpy(notifier[i].name, pd->domain_list[i].name, |
| 2707 | QMI_SERVREG_LOC_NAME_LENGTH_V01 + 1); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2708 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2709 | if (IS_ERR(notifier[i].handle)) { |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2710 | icnss_pr_err("%d: Unable to register notifier for %s(0x%x)\n", |
| 2711 | i, pd->domain_list->name, |
| 2712 | pd->domain_list->instance_id); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2713 | ret = PTR_ERR(notifier[i].handle); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2714 | goto free_handle; |
| 2715 | } |
| 2716 | } |
| 2717 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2718 | priv->service_notifier = notifier; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2719 | priv->total_domains = pd->total_domains; |
| 2720 | |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 2721 | set_bit(ICNSS_PDR_REGISTERED, &priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2722 | |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 2723 | icnss_pr_dbg("PD notification registration happened, state: 0x%lx\n", |
| 2724 | priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2725 | |
| 2726 | return NOTIFY_OK; |
| 2727 | |
| 2728 | free_handle: |
| 2729 | for (i = 0; i < pd->total_domains; i++) { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2730 | if (notifier[i].handle) |
| 2731 | service_notif_unregister_notifier(notifier[i].handle, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2732 | &priv->service_notifier_nb); |
| 2733 | } |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 2734 | kfree(notifier); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2735 | |
| 2736 | out: |
| 2737 | icnss_pr_err("PD restart not enabled: %d, state: 0x%lx\n", ret, |
| 2738 | priv->state); |
| 2739 | |
| 2740 | return NOTIFY_OK; |
| 2741 | } |
| 2742 | |
| 2743 | |
| 2744 | static int icnss_pd_restart_enable(struct icnss_priv *priv) |
| 2745 | { |
| 2746 | int ret; |
| 2747 | |
| 2748 | if (test_bit(SSR_ONLY, &quirks)) { |
| 2749 | icnss_pr_dbg("PDR disabled through module parameter\n"); |
| 2750 | return 0; |
| 2751 | } |
| 2752 | |
| 2753 | icnss_pr_dbg("Get service location, state: 0x%lx\n", priv->state); |
| 2754 | |
| 2755 | priv->get_service_nb.notifier_call = icnss_get_service_location_notify; |
| 2756 | ret = get_service_location(ICNSS_SERVICE_LOCATION_CLIENT_NAME, |
| 2757 | ICNSS_WLAN_SERVICE_NAME, |
| 2758 | &priv->get_service_nb); |
| 2759 | if (ret) { |
| 2760 | icnss_pr_err("Get service location failed: %d\n", ret); |
| 2761 | goto out; |
| 2762 | } |
| 2763 | |
| 2764 | return 0; |
| 2765 | out: |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2766 | icnss_pr_err("Failed to enable PD restart: %d\n", ret); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2767 | return ret; |
| 2768 | |
| 2769 | } |
| 2770 | |
| 2771 | |
| 2772 | static int icnss_enable_recovery(struct icnss_priv *priv) |
| 2773 | { |
| 2774 | int ret; |
| 2775 | |
| 2776 | if (test_bit(RECOVERY_DISABLE, &quirks)) { |
| 2777 | icnss_pr_dbg("Recovery disabled through module parameter\n"); |
| 2778 | return 0; |
| 2779 | } |
| 2780 | |
| 2781 | if (test_bit(PDR_ONLY, &quirks)) { |
| 2782 | icnss_pr_dbg("SSR disabled through module parameter\n"); |
| 2783 | goto enable_pdr; |
| 2784 | } |
| 2785 | |
| 2786 | priv->msa0_dump_dev = create_ramdump_device("wcss_msa0", |
| 2787 | &priv->pdev->dev); |
| 2788 | if (!priv->msa0_dump_dev) |
| 2789 | return -ENOMEM; |
| 2790 | |
| 2791 | icnss_modem_ssr_register_notifier(priv); |
| 2792 | if (test_bit(SSR_ONLY, &quirks)) { |
| 2793 | icnss_pr_dbg("PDR disabled through module parameter\n"); |
| 2794 | return 0; |
| 2795 | } |
| 2796 | |
| 2797 | enable_pdr: |
| 2798 | ret = icnss_pd_restart_enable(priv); |
| 2799 | |
| 2800 | if (ret) |
| 2801 | return ret; |
| 2802 | |
| 2803 | return 0; |
| 2804 | } |
| 2805 | |
| 2806 | int icnss_register_driver(struct icnss_driver_ops *ops) |
| 2807 | { |
| 2808 | int ret = 0; |
| 2809 | |
| 2810 | if (!penv || !penv->pdev) { |
| 2811 | ret = -ENODEV; |
| 2812 | goto out; |
| 2813 | } |
| 2814 | |
| 2815 | icnss_pr_dbg("Registering driver, state: 0x%lx\n", penv->state); |
| 2816 | |
| 2817 | if (penv->ops) { |
| 2818 | icnss_pr_err("Driver already registered\n"); |
| 2819 | ret = -EEXIST; |
| 2820 | goto out; |
| 2821 | } |
| 2822 | |
| 2823 | if (!ops->probe || !ops->remove) { |
| 2824 | ret = -EINVAL; |
| 2825 | goto out; |
| 2826 | } |
| 2827 | |
| 2828 | ret = icnss_driver_event_post(ICNSS_DRIVER_EVENT_REGISTER_DRIVER, |
Anurag Chouhan | 3dd77c1 | 2017-03-24 16:07:45 +0530 | [diff] [blame] | 2829 | 0, ops); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2830 | |
| 2831 | if (ret == -EINTR) |
| 2832 | ret = 0; |
| 2833 | |
| 2834 | out: |
| 2835 | return ret; |
| 2836 | } |
| 2837 | EXPORT_SYMBOL(icnss_register_driver); |
| 2838 | |
| 2839 | int icnss_unregister_driver(struct icnss_driver_ops *ops) |
| 2840 | { |
| 2841 | int ret; |
| 2842 | |
| 2843 | if (!penv || !penv->pdev) { |
| 2844 | ret = -ENODEV; |
| 2845 | goto out; |
| 2846 | } |
| 2847 | |
| 2848 | icnss_pr_dbg("Unregistering driver, state: 0x%lx\n", penv->state); |
| 2849 | |
| 2850 | if (!penv->ops) { |
| 2851 | icnss_pr_err("Driver not registered\n"); |
| 2852 | ret = -ENOENT; |
| 2853 | goto out; |
| 2854 | } |
| 2855 | |
| 2856 | ret = icnss_driver_event_post(ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER, |
| 2857 | ICNSS_EVENT_SYNC_UNINTERRUPTIBLE, NULL); |
| 2858 | out: |
| 2859 | return ret; |
| 2860 | } |
| 2861 | EXPORT_SYMBOL(icnss_unregister_driver); |
| 2862 | |
| 2863 | int icnss_ce_request_irq(unsigned int ce_id, |
| 2864 | irqreturn_t (*handler)(int, void *), |
| 2865 | unsigned long flags, const char *name, void *ctx) |
| 2866 | { |
| 2867 | int ret = 0; |
| 2868 | unsigned int irq; |
| 2869 | struct ce_irq_list *irq_entry; |
| 2870 | |
| 2871 | if (!penv || !penv->pdev) { |
| 2872 | ret = -ENODEV; |
| 2873 | goto out; |
| 2874 | } |
| 2875 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2876 | icnss_pr_vdbg("CE request IRQ: %d, state: 0x%lx\n", ce_id, penv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2877 | |
| 2878 | if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) { |
| 2879 | icnss_pr_err("Invalid CE ID, ce_id: %d\n", ce_id); |
| 2880 | ret = -EINVAL; |
| 2881 | goto out; |
| 2882 | } |
| 2883 | irq = penv->ce_irqs[ce_id]; |
| 2884 | irq_entry = &penv->ce_irq_list[ce_id]; |
| 2885 | |
| 2886 | if (irq_entry->handler || irq_entry->irq) { |
| 2887 | icnss_pr_err("IRQ already requested: %d, ce_id: %d\n", |
| 2888 | irq, ce_id); |
| 2889 | ret = -EEXIST; |
| 2890 | goto out; |
| 2891 | } |
| 2892 | |
| 2893 | ret = request_irq(irq, handler, flags, name, ctx); |
| 2894 | if (ret) { |
| 2895 | icnss_pr_err("IRQ request failed: %d, ce_id: %d, ret: %d\n", |
| 2896 | irq, ce_id, ret); |
| 2897 | goto out; |
| 2898 | } |
| 2899 | irq_entry->irq = irq; |
| 2900 | irq_entry->handler = handler; |
| 2901 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2902 | icnss_pr_vdbg("IRQ requested: %d, ce_id: %d\n", irq, ce_id); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2903 | |
| 2904 | penv->stats.ce_irqs[ce_id].request++; |
| 2905 | out: |
| 2906 | return ret; |
| 2907 | } |
| 2908 | EXPORT_SYMBOL(icnss_ce_request_irq); |
| 2909 | |
| 2910 | int icnss_ce_free_irq(unsigned int ce_id, void *ctx) |
| 2911 | { |
| 2912 | int ret = 0; |
| 2913 | unsigned int irq; |
| 2914 | struct ce_irq_list *irq_entry; |
| 2915 | |
| 2916 | if (!penv || !penv->pdev) { |
| 2917 | ret = -ENODEV; |
| 2918 | goto out; |
| 2919 | } |
| 2920 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2921 | icnss_pr_vdbg("CE free IRQ: %d, state: 0x%lx\n", ce_id, penv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2922 | |
| 2923 | if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) { |
| 2924 | icnss_pr_err("Invalid CE ID to free, ce_id: %d\n", ce_id); |
| 2925 | ret = -EINVAL; |
| 2926 | goto out; |
| 2927 | } |
| 2928 | |
| 2929 | irq = penv->ce_irqs[ce_id]; |
| 2930 | irq_entry = &penv->ce_irq_list[ce_id]; |
| 2931 | if (!irq_entry->handler || !irq_entry->irq) { |
| 2932 | icnss_pr_err("IRQ not requested: %d, ce_id: %d\n", irq, ce_id); |
| 2933 | ret = -EEXIST; |
| 2934 | goto out; |
| 2935 | } |
| 2936 | free_irq(irq, ctx); |
| 2937 | irq_entry->irq = 0; |
| 2938 | irq_entry->handler = NULL; |
| 2939 | |
| 2940 | penv->stats.ce_irqs[ce_id].free++; |
| 2941 | out: |
| 2942 | return ret; |
| 2943 | } |
| 2944 | EXPORT_SYMBOL(icnss_ce_free_irq); |
| 2945 | |
| 2946 | void icnss_enable_irq(unsigned int ce_id) |
| 2947 | { |
| 2948 | unsigned int irq; |
| 2949 | |
| 2950 | if (!penv || !penv->pdev) { |
| 2951 | icnss_pr_err("Platform driver not initialized\n"); |
| 2952 | return; |
| 2953 | } |
| 2954 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2955 | icnss_pr_vdbg("Enable IRQ: ce_id: %d, state: 0x%lx\n", ce_id, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2956 | penv->state); |
| 2957 | |
| 2958 | if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) { |
| 2959 | icnss_pr_err("Invalid CE ID to enable IRQ, ce_id: %d\n", ce_id); |
| 2960 | return; |
| 2961 | } |
| 2962 | |
| 2963 | penv->stats.ce_irqs[ce_id].enable++; |
| 2964 | |
| 2965 | irq = penv->ce_irqs[ce_id]; |
| 2966 | enable_irq(irq); |
| 2967 | } |
| 2968 | EXPORT_SYMBOL(icnss_enable_irq); |
| 2969 | |
| 2970 | void icnss_disable_irq(unsigned int ce_id) |
| 2971 | { |
| 2972 | unsigned int irq; |
| 2973 | |
| 2974 | if (!penv || !penv->pdev) { |
| 2975 | icnss_pr_err("Platform driver not initialized\n"); |
| 2976 | return; |
| 2977 | } |
| 2978 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 2979 | icnss_pr_vdbg("Disable IRQ: ce_id: %d, state: 0x%lx\n", ce_id, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 2980 | penv->state); |
| 2981 | |
| 2982 | if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) { |
| 2983 | icnss_pr_err("Invalid CE ID to disable IRQ, ce_id: %d\n", |
| 2984 | ce_id); |
| 2985 | return; |
| 2986 | } |
| 2987 | |
| 2988 | irq = penv->ce_irqs[ce_id]; |
| 2989 | disable_irq(irq); |
| 2990 | |
| 2991 | penv->stats.ce_irqs[ce_id].disable++; |
| 2992 | } |
| 2993 | EXPORT_SYMBOL(icnss_disable_irq); |
| 2994 | |
| 2995 | int icnss_get_soc_info(struct icnss_soc_info *info) |
| 2996 | { |
| 2997 | if (!penv) { |
| 2998 | icnss_pr_err("Platform driver not initialized\n"); |
| 2999 | return -EINVAL; |
| 3000 | } |
| 3001 | |
| 3002 | info->v_addr = penv->mem_base_va; |
| 3003 | info->p_addr = penv->mem_base_pa; |
| 3004 | info->chip_id = penv->chip_info.chip_id; |
| 3005 | info->chip_family = penv->chip_info.chip_family; |
| 3006 | info->board_id = penv->board_info.board_id; |
| 3007 | info->soc_id = penv->soc_info.soc_id; |
| 3008 | info->fw_version = penv->fw_version_info.fw_version; |
| 3009 | strlcpy(info->fw_build_timestamp, |
| 3010 | penv->fw_version_info.fw_build_timestamp, |
| 3011 | QMI_WLFW_MAX_TIMESTAMP_LEN_V01 + 1); |
| 3012 | |
| 3013 | return 0; |
| 3014 | } |
| 3015 | EXPORT_SYMBOL(icnss_get_soc_info); |
| 3016 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3017 | int icnss_set_fw_log_mode(uint8_t fw_log_mode) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3018 | { |
| 3019 | int ret; |
| 3020 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3021 | icnss_pr_dbg("FW log mode: %u\n", fw_log_mode); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3022 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3023 | ret = wlfw_ini_send_sync_msg(fw_log_mode); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3024 | if (ret) |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3025 | icnss_pr_err("Fail to send ini, ret = %d, fw_log_mode: %u\n", |
| 3026 | ret, fw_log_mode); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3027 | return ret; |
| 3028 | } |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3029 | EXPORT_SYMBOL(icnss_set_fw_log_mode); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3030 | |
| 3031 | int icnss_athdiag_read(struct device *dev, uint32_t offset, |
| 3032 | uint32_t mem_type, uint32_t data_len, |
| 3033 | uint8_t *output) |
| 3034 | { |
| 3035 | int ret = 0; |
| 3036 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 3037 | |
| 3038 | if (priv->magic != ICNSS_MAGIC) { |
| 3039 | icnss_pr_err("Invalid drvdata for diag read: dev %p, data %p, magic 0x%x\n", |
| 3040 | dev, priv, priv->magic); |
| 3041 | return -EINVAL; |
| 3042 | } |
| 3043 | |
| 3044 | if (!output || data_len == 0 |
| 3045 | || data_len > QMI_WLFW_MAX_DATA_SIZE_V01) { |
| 3046 | icnss_pr_err("Invalid parameters for diag read: output %p, data_len %u\n", |
| 3047 | output, data_len); |
| 3048 | ret = -EINVAL; |
| 3049 | goto out; |
| 3050 | } |
| 3051 | |
| 3052 | if (!test_bit(ICNSS_FW_READY, &priv->state) || |
| 3053 | !test_bit(ICNSS_POWER_ON, &priv->state)) { |
| 3054 | icnss_pr_err("Invalid state for diag read: 0x%lx\n", |
| 3055 | priv->state); |
| 3056 | ret = -EINVAL; |
| 3057 | goto out; |
| 3058 | } |
| 3059 | |
| 3060 | ret = wlfw_athdiag_read_send_sync_msg(priv, offset, mem_type, |
| 3061 | data_len, output); |
| 3062 | out: |
| 3063 | return ret; |
| 3064 | } |
| 3065 | EXPORT_SYMBOL(icnss_athdiag_read); |
| 3066 | |
| 3067 | int icnss_athdiag_write(struct device *dev, uint32_t offset, |
| 3068 | uint32_t mem_type, uint32_t data_len, |
| 3069 | uint8_t *input) |
| 3070 | { |
| 3071 | int ret = 0; |
| 3072 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 3073 | |
| 3074 | if (priv->magic != ICNSS_MAGIC) { |
| 3075 | icnss_pr_err("Invalid drvdata for diag write: dev %p, data %p, magic 0x%x\n", |
| 3076 | dev, priv, priv->magic); |
| 3077 | return -EINVAL; |
| 3078 | } |
| 3079 | |
| 3080 | if (!input || data_len == 0 |
| 3081 | || data_len > QMI_WLFW_MAX_DATA_SIZE_V01) { |
| 3082 | icnss_pr_err("Invalid parameters for diag write: input %p, data_len %u\n", |
| 3083 | input, data_len); |
| 3084 | ret = -EINVAL; |
| 3085 | goto out; |
| 3086 | } |
| 3087 | |
| 3088 | if (!test_bit(ICNSS_FW_READY, &priv->state) || |
| 3089 | !test_bit(ICNSS_POWER_ON, &priv->state)) { |
| 3090 | icnss_pr_err("Invalid state for diag write: 0x%lx\n", |
| 3091 | priv->state); |
| 3092 | ret = -EINVAL; |
| 3093 | goto out; |
| 3094 | } |
| 3095 | |
| 3096 | ret = wlfw_athdiag_write_send_sync_msg(priv, offset, mem_type, |
| 3097 | data_len, input); |
| 3098 | out: |
| 3099 | return ret; |
| 3100 | } |
| 3101 | EXPORT_SYMBOL(icnss_athdiag_write); |
| 3102 | |
| 3103 | int icnss_wlan_enable(struct icnss_wlan_enable_cfg *config, |
| 3104 | enum icnss_driver_mode mode, |
| 3105 | const char *host_version) |
| 3106 | { |
| 3107 | struct wlfw_wlan_cfg_req_msg_v01 req; |
| 3108 | u32 i; |
| 3109 | int ret; |
| 3110 | |
| 3111 | icnss_pr_dbg("Mode: %d, config: %p, host_version: %s\n", |
| 3112 | mode, config, host_version); |
| 3113 | |
| 3114 | memset(&req, 0, sizeof(req)); |
| 3115 | |
| 3116 | if (mode == ICNSS_WALTEST || mode == ICNSS_CCPM) |
| 3117 | goto skip; |
| 3118 | |
| 3119 | if (!config || !host_version) { |
| 3120 | icnss_pr_err("Invalid cfg pointer, config: %p, host_version: %p\n", |
| 3121 | config, host_version); |
| 3122 | ret = -EINVAL; |
| 3123 | goto out; |
| 3124 | } |
| 3125 | |
| 3126 | req.host_version_valid = 1; |
| 3127 | strlcpy(req.host_version, host_version, |
| 3128 | QMI_WLFW_MAX_STR_LEN_V01 + 1); |
| 3129 | |
| 3130 | req.tgt_cfg_valid = 1; |
| 3131 | if (config->num_ce_tgt_cfg > QMI_WLFW_MAX_NUM_CE_V01) |
| 3132 | req.tgt_cfg_len = QMI_WLFW_MAX_NUM_CE_V01; |
| 3133 | else |
| 3134 | req.tgt_cfg_len = config->num_ce_tgt_cfg; |
| 3135 | for (i = 0; i < req.tgt_cfg_len; i++) { |
| 3136 | req.tgt_cfg[i].pipe_num = config->ce_tgt_cfg[i].pipe_num; |
| 3137 | req.tgt_cfg[i].pipe_dir = config->ce_tgt_cfg[i].pipe_dir; |
| 3138 | req.tgt_cfg[i].nentries = config->ce_tgt_cfg[i].nentries; |
| 3139 | req.tgt_cfg[i].nbytes_max = config->ce_tgt_cfg[i].nbytes_max; |
| 3140 | req.tgt_cfg[i].flags = config->ce_tgt_cfg[i].flags; |
| 3141 | } |
| 3142 | |
| 3143 | req.svc_cfg_valid = 1; |
| 3144 | if (config->num_ce_svc_pipe_cfg > QMI_WLFW_MAX_NUM_SVC_V01) |
| 3145 | req.svc_cfg_len = QMI_WLFW_MAX_NUM_SVC_V01; |
| 3146 | else |
| 3147 | req.svc_cfg_len = config->num_ce_svc_pipe_cfg; |
| 3148 | for (i = 0; i < req.svc_cfg_len; i++) { |
| 3149 | req.svc_cfg[i].service_id = config->ce_svc_cfg[i].service_id; |
| 3150 | req.svc_cfg[i].pipe_dir = config->ce_svc_cfg[i].pipe_dir; |
| 3151 | req.svc_cfg[i].pipe_num = config->ce_svc_cfg[i].pipe_num; |
| 3152 | } |
| 3153 | |
| 3154 | req.shadow_reg_valid = 1; |
| 3155 | if (config->num_shadow_reg_cfg > |
| 3156 | QMI_WLFW_MAX_NUM_SHADOW_REG_V01) |
| 3157 | req.shadow_reg_len = QMI_WLFW_MAX_NUM_SHADOW_REG_V01; |
| 3158 | else |
| 3159 | req.shadow_reg_len = config->num_shadow_reg_cfg; |
| 3160 | |
| 3161 | memcpy(req.shadow_reg, config->shadow_reg_cfg, |
| 3162 | sizeof(struct wlfw_shadow_reg_cfg_s_v01) * req.shadow_reg_len); |
| 3163 | |
| 3164 | ret = wlfw_wlan_cfg_send_sync_msg(&req); |
| 3165 | if (ret) |
| 3166 | goto out; |
| 3167 | skip: |
| 3168 | ret = wlfw_wlan_mode_send_sync_msg(mode); |
| 3169 | out: |
| 3170 | if (test_bit(SKIP_QMI, &quirks)) |
| 3171 | ret = 0; |
| 3172 | |
| 3173 | return ret; |
| 3174 | } |
| 3175 | EXPORT_SYMBOL(icnss_wlan_enable); |
| 3176 | |
| 3177 | int icnss_wlan_disable(enum icnss_driver_mode mode) |
| 3178 | { |
| 3179 | return wlfw_wlan_mode_send_sync_msg(QMI_WLFW_OFF_V01); |
| 3180 | } |
| 3181 | EXPORT_SYMBOL(icnss_wlan_disable); |
| 3182 | |
| 3183 | bool icnss_is_qmi_disable(void) |
| 3184 | { |
| 3185 | return test_bit(SKIP_QMI, &quirks) ? true : false; |
| 3186 | } |
| 3187 | EXPORT_SYMBOL(icnss_is_qmi_disable); |
| 3188 | |
| 3189 | int icnss_get_ce_id(int irq) |
| 3190 | { |
| 3191 | int i; |
| 3192 | |
| 3193 | if (!penv || !penv->pdev) |
| 3194 | return -ENODEV; |
| 3195 | |
| 3196 | for (i = 0; i < ICNSS_MAX_IRQ_REGISTRATIONS; i++) { |
| 3197 | if (penv->ce_irqs[i] == irq) |
| 3198 | return i; |
| 3199 | } |
| 3200 | |
| 3201 | icnss_pr_err("No matching CE id for irq %d\n", irq); |
| 3202 | |
| 3203 | return -EINVAL; |
| 3204 | } |
| 3205 | EXPORT_SYMBOL(icnss_get_ce_id); |
| 3206 | |
| 3207 | int icnss_get_irq(int ce_id) |
| 3208 | { |
| 3209 | int irq; |
| 3210 | |
| 3211 | if (!penv || !penv->pdev) |
| 3212 | return -ENODEV; |
| 3213 | |
| 3214 | if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) |
| 3215 | return -EINVAL; |
| 3216 | |
| 3217 | irq = penv->ce_irqs[ce_id]; |
| 3218 | |
| 3219 | return irq; |
| 3220 | } |
| 3221 | EXPORT_SYMBOL(icnss_get_irq); |
| 3222 | |
| 3223 | struct dma_iommu_mapping *icnss_smmu_get_mapping(struct device *dev) |
| 3224 | { |
| 3225 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 3226 | |
| 3227 | if (!priv) { |
| 3228 | icnss_pr_err("Invalid drvdata: dev %p, data %p\n", |
| 3229 | dev, priv); |
| 3230 | return NULL; |
| 3231 | } |
| 3232 | |
| 3233 | return priv->smmu_mapping; |
| 3234 | } |
| 3235 | EXPORT_SYMBOL(icnss_smmu_get_mapping); |
| 3236 | |
| 3237 | int icnss_smmu_map(struct device *dev, |
| 3238 | phys_addr_t paddr, uint32_t *iova_addr, size_t size) |
| 3239 | { |
| 3240 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 3241 | unsigned long iova; |
| 3242 | size_t len; |
| 3243 | int ret = 0; |
| 3244 | |
| 3245 | if (!priv) { |
| 3246 | icnss_pr_err("Invalid drvdata: dev %p, data %p\n", |
| 3247 | dev, priv); |
| 3248 | return -EINVAL; |
| 3249 | } |
| 3250 | |
| 3251 | if (!iova_addr) { |
| 3252 | icnss_pr_err("iova_addr is NULL, paddr %pa, size %zu\n", |
| 3253 | &paddr, size); |
| 3254 | return -EINVAL; |
| 3255 | } |
| 3256 | |
| 3257 | len = roundup(size + paddr - rounddown(paddr, PAGE_SIZE), PAGE_SIZE); |
| 3258 | iova = roundup(penv->smmu_iova_ipa_start, PAGE_SIZE); |
| 3259 | |
| 3260 | if (iova >= priv->smmu_iova_ipa_start + priv->smmu_iova_ipa_len) { |
| 3261 | icnss_pr_err("No IOVA space to map, iova %lx, smmu_iova_ipa_start %pad, smmu_iova_ipa_len %zu\n", |
| 3262 | iova, |
| 3263 | &priv->smmu_iova_ipa_start, |
| 3264 | priv->smmu_iova_ipa_len); |
| 3265 | return -ENOMEM; |
| 3266 | } |
| 3267 | |
| 3268 | ret = iommu_map(priv->smmu_mapping->domain, iova, |
| 3269 | rounddown(paddr, PAGE_SIZE), len, |
| 3270 | IOMMU_READ | IOMMU_WRITE); |
| 3271 | if (ret) { |
| 3272 | icnss_pr_err("PA to IOVA mapping failed, ret %d\n", ret); |
| 3273 | return ret; |
| 3274 | } |
| 3275 | |
| 3276 | priv->smmu_iova_ipa_start = iova + len; |
| 3277 | *iova_addr = (uint32_t)(iova + paddr - rounddown(paddr, PAGE_SIZE)); |
| 3278 | |
| 3279 | return 0; |
| 3280 | } |
| 3281 | EXPORT_SYMBOL(icnss_smmu_map); |
| 3282 | |
| 3283 | unsigned int icnss_socinfo_get_serial_number(struct device *dev) |
| 3284 | { |
| 3285 | return socinfo_get_serial_number(); |
| 3286 | } |
| 3287 | EXPORT_SYMBOL(icnss_socinfo_get_serial_number); |
| 3288 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3289 | int icnss_trigger_recovery(struct device *dev) |
| 3290 | { |
| 3291 | int ret = 0; |
| 3292 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 3293 | |
| 3294 | if (priv->magic != ICNSS_MAGIC) { |
| 3295 | icnss_pr_err("Invalid drvdata: magic 0x%x\n", priv->magic); |
| 3296 | ret = -EINVAL; |
| 3297 | goto out; |
| 3298 | } |
| 3299 | |
| 3300 | if (test_bit(ICNSS_PD_RESTART, &priv->state)) { |
| 3301 | icnss_pr_err("PD recovery already in progress: state: 0x%lx\n", |
| 3302 | priv->state); |
| 3303 | ret = -EPERM; |
| 3304 | goto out; |
| 3305 | } |
| 3306 | |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 3307 | if (!test_bit(ICNSS_PDR_REGISTERED, &priv->state)) { |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 3308 | icnss_pr_err("PD restart not enabled to trigger recovery: state: 0x%lx\n", |
| 3309 | priv->state); |
| 3310 | ret = -EOPNOTSUPP; |
| 3311 | goto out; |
| 3312 | } |
| 3313 | |
| 3314 | if (!priv->service_notifier || !priv->service_notifier[0].handle) { |
| 3315 | icnss_pr_err("Invalid handle during recovery, state: 0x%lx\n", |
| 3316 | priv->state); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3317 | ret = -EINVAL; |
| 3318 | goto out; |
| 3319 | } |
| 3320 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 3321 | WARN_ON(1); |
| 3322 | icnss_pr_warn("Initiate PD restart at WLAN FW, state: 0x%lx\n", |
| 3323 | priv->state); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 3324 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3325 | /* |
| 3326 | * Initiate PDR, required only for the first instance |
| 3327 | */ |
| 3328 | ret = service_notif_pd_restart(priv->service_notifier[0].name, |
| 3329 | priv->service_notifier[0].instance_id); |
| 3330 | |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 3331 | if (!ret) |
| 3332 | set_bit(ICNSS_HOST_TRIGGERED_PDR, &priv->state); |
| 3333 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3334 | out: |
| 3335 | return ret; |
| 3336 | } |
| 3337 | EXPORT_SYMBOL(icnss_trigger_recovery); |
| 3338 | |
| 3339 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3340 | static int icnss_smmu_init(struct icnss_priv *priv) |
| 3341 | { |
| 3342 | struct dma_iommu_mapping *mapping; |
| 3343 | int atomic_ctx = 1; |
| 3344 | int s1_bypass = 1; |
Hardik Kantilal Patel | e92672b | 2017-07-11 15:47:21 +0530 | [diff] [blame] | 3345 | int fast = 1; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3346 | int ret = 0; |
| 3347 | |
| 3348 | icnss_pr_dbg("Initializing SMMU\n"); |
| 3349 | |
| 3350 | mapping = arm_iommu_create_mapping(&platform_bus_type, |
| 3351 | priv->smmu_iova_start, |
| 3352 | priv->smmu_iova_len); |
| 3353 | if (IS_ERR(mapping)) { |
| 3354 | icnss_pr_err("Create mapping failed, err = %d\n", ret); |
| 3355 | ret = PTR_ERR(mapping); |
| 3356 | goto map_fail; |
| 3357 | } |
| 3358 | |
Hardik Kantilal Patel | e92672b | 2017-07-11 15:47:21 +0530 | [diff] [blame] | 3359 | if (priv->bypass_s1_smmu) { |
| 3360 | ret = iommu_domain_set_attr(mapping->domain, |
| 3361 | DOMAIN_ATTR_S1_BYPASS, |
| 3362 | &s1_bypass); |
| 3363 | if (ret < 0) { |
| 3364 | icnss_pr_err("Set s1_bypass attribute failed, err = %d\n", |
| 3365 | ret); |
| 3366 | goto set_attr_fail; |
| 3367 | } |
| 3368 | icnss_pr_dbg("SMMU S1 BYPASS\n"); |
| 3369 | } else { |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 3370 | ret = iommu_domain_set_attr(mapping->domain, |
| 3371 | DOMAIN_ATTR_ATOMIC, |
| 3372 | &atomic_ctx); |
| 3373 | if (ret < 0) { |
| 3374 | icnss_pr_err("Set atomic_ctx attribute failed, err = %d\n", |
| 3375 | ret); |
| 3376 | goto set_attr_fail; |
| 3377 | } |
Hardik Kantilal Patel | e92672b | 2017-07-11 15:47:21 +0530 | [diff] [blame] | 3378 | icnss_pr_dbg("SMMU ATTR ATOMIC\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3379 | |
Hardik Kantilal Patel | e92672b | 2017-07-11 15:47:21 +0530 | [diff] [blame] | 3380 | ret = iommu_domain_set_attr(mapping->domain, |
| 3381 | DOMAIN_ATTR_FAST, |
| 3382 | &fast); |
| 3383 | if (ret < 0) { |
| 3384 | icnss_pr_err("Set fast map attribute failed, err = %d\n", |
| 3385 | ret); |
| 3386 | goto set_attr_fail; |
| 3387 | } |
| 3388 | icnss_pr_dbg("SMMU FAST map set\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | ret = arm_iommu_attach_device(&priv->pdev->dev, mapping); |
| 3392 | if (ret < 0) { |
| 3393 | icnss_pr_err("Attach device failed, err = %d\n", ret); |
| 3394 | goto attach_fail; |
| 3395 | } |
| 3396 | |
| 3397 | priv->smmu_mapping = mapping; |
| 3398 | |
| 3399 | return ret; |
| 3400 | |
| 3401 | attach_fail: |
| 3402 | set_attr_fail: |
| 3403 | arm_iommu_release_mapping(mapping); |
| 3404 | map_fail: |
| 3405 | return ret; |
| 3406 | } |
| 3407 | |
| 3408 | static void icnss_smmu_deinit(struct icnss_priv *priv) |
| 3409 | { |
| 3410 | if (!priv->smmu_mapping) |
| 3411 | return; |
| 3412 | |
| 3413 | arm_iommu_detach_device(&priv->pdev->dev); |
| 3414 | arm_iommu_release_mapping(priv->smmu_mapping); |
| 3415 | |
| 3416 | priv->smmu_mapping = NULL; |
| 3417 | } |
| 3418 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 3419 | static int icnss_get_vreg_info(struct device *dev, |
| 3420 | struct icnss_vreg_info *vreg_info) |
| 3421 | { |
| 3422 | int ret = 0; |
| 3423 | char prop_name[MAX_PROP_SIZE]; |
| 3424 | struct regulator *reg; |
| 3425 | const __be32 *prop; |
| 3426 | int len = 0; |
| 3427 | int i; |
| 3428 | |
| 3429 | reg = devm_regulator_get_optional(dev, vreg_info->name); |
| 3430 | if (PTR_ERR(reg) == -EPROBE_DEFER) { |
| 3431 | icnss_pr_err("EPROBE_DEFER for regulator: %s\n", |
| 3432 | vreg_info->name); |
| 3433 | ret = PTR_ERR(reg); |
| 3434 | goto out; |
| 3435 | } |
| 3436 | |
| 3437 | if (IS_ERR(reg)) { |
| 3438 | ret = PTR_ERR(reg); |
| 3439 | |
| 3440 | if (vreg_info->required) { |
| 3441 | icnss_pr_err("Regulator %s doesn't exist: %d\n", |
| 3442 | vreg_info->name, ret); |
| 3443 | goto out; |
| 3444 | } else { |
| 3445 | icnss_pr_dbg("Optional regulator %s doesn't exist: %d\n", |
| 3446 | vreg_info->name, ret); |
| 3447 | goto done; |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | vreg_info->reg = reg; |
| 3452 | |
| 3453 | snprintf(prop_name, MAX_PROP_SIZE, |
| 3454 | "qcom,%s-config", vreg_info->name); |
| 3455 | |
| 3456 | prop = of_get_property(dev->of_node, prop_name, &len); |
| 3457 | |
| 3458 | icnss_pr_dbg("Got regulator config, prop: %s, len: %d\n", |
| 3459 | prop_name, len); |
| 3460 | |
| 3461 | if (!prop || len < (2 * sizeof(__be32))) { |
| 3462 | icnss_pr_dbg("Property %s %s\n", prop_name, |
| 3463 | prop ? "invalid format" : "doesn't exist"); |
| 3464 | goto done; |
| 3465 | } |
| 3466 | |
| 3467 | for (i = 0; (i * sizeof(__be32)) < len; i++) { |
| 3468 | switch (i) { |
| 3469 | case 0: |
| 3470 | vreg_info->min_v = be32_to_cpup(&prop[0]); |
| 3471 | break; |
| 3472 | case 1: |
| 3473 | vreg_info->max_v = be32_to_cpup(&prop[1]); |
| 3474 | break; |
| 3475 | case 2: |
| 3476 | vreg_info->load_ua = be32_to_cpup(&prop[2]); |
| 3477 | break; |
| 3478 | case 3: |
| 3479 | vreg_info->settle_delay = be32_to_cpup(&prop[3]); |
| 3480 | break; |
| 3481 | default: |
| 3482 | icnss_pr_dbg("Property %s, ignoring value at %d\n", |
| 3483 | prop_name, i); |
| 3484 | break; |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | done: |
| 3489 | icnss_pr_dbg("Regulator: %s, min_v: %u, max_v: %u, load: %u, delay: %lu\n", |
| 3490 | vreg_info->name, vreg_info->min_v, vreg_info->max_v, |
| 3491 | vreg_info->load_ua, vreg_info->settle_delay); |
| 3492 | |
| 3493 | return 0; |
| 3494 | |
| 3495 | out: |
| 3496 | return ret; |
| 3497 | } |
| 3498 | |
| 3499 | static int icnss_get_clk_info(struct device *dev, |
| 3500 | struct icnss_clk_info *clk_info) |
| 3501 | { |
| 3502 | struct clk *handle; |
| 3503 | int ret = 0; |
| 3504 | |
| 3505 | handle = devm_clk_get(dev, clk_info->name); |
| 3506 | if (IS_ERR(handle)) { |
| 3507 | ret = PTR_ERR(handle); |
| 3508 | if (clk_info->required) { |
| 3509 | icnss_pr_err("Clock %s isn't available: %d\n", |
| 3510 | clk_info->name, ret); |
| 3511 | goto out; |
| 3512 | } else { |
| 3513 | icnss_pr_dbg("Ignoring clock %s: %d\n", clk_info->name, |
| 3514 | ret); |
| 3515 | ret = 0; |
| 3516 | goto out; |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | icnss_pr_dbg("Clock: %s, freq: %u\n", clk_info->name, clk_info->freq); |
| 3521 | |
| 3522 | clk_info->handle = handle; |
| 3523 | out: |
| 3524 | return ret; |
| 3525 | } |
| 3526 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3527 | static int icnss_fw_debug_show(struct seq_file *s, void *data) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3528 | { |
| 3529 | struct icnss_priv *priv = s->private; |
| 3530 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3531 | seq_puts(s, "\nUsage: echo <CMD> <VAL> > <DEBUGFS>/icnss/fw_debug\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3532 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3533 | seq_puts(s, "\nCMD: test_mode\n"); |
| 3534 | seq_puts(s, " VAL: 0 (Test mode disable)\n"); |
| 3535 | seq_puts(s, " VAL: 1 (WLAN FW test)\n"); |
| 3536 | seq_puts(s, " VAL: 2 (CCPM test)\n"); |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 3537 | seq_puts(s, " VAL: 3 (Trigger Recovery)\n"); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3538 | |
| 3539 | seq_puts(s, "\nCMD: dynamic_feature_mask\n"); |
| 3540 | seq_puts(s, " VAL: (64 bit feature mask)\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3541 | |
| 3542 | if (!test_bit(ICNSS_FW_READY, &priv->state)) { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3543 | seq_puts(s, "Firmware is not ready yet, can't run test_mode!\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3544 | goto out; |
| 3545 | } |
| 3546 | |
| 3547 | if (test_bit(ICNSS_DRIVER_PROBED, &priv->state)) { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3548 | seq_puts(s, "Machine mode is running, can't run test_mode!\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3549 | goto out; |
| 3550 | } |
| 3551 | |
| 3552 | if (test_bit(ICNSS_FW_TEST_MODE, &priv->state)) { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3553 | seq_puts(s, "test_mode is running, can't run test_mode!\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3554 | goto out; |
| 3555 | } |
| 3556 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3557 | out: |
| 3558 | seq_puts(s, "\n"); |
| 3559 | return 0; |
| 3560 | } |
| 3561 | |
| 3562 | static int icnss_test_mode_fw_test_off(struct icnss_priv *priv) |
| 3563 | { |
| 3564 | int ret; |
| 3565 | |
| 3566 | if (!test_bit(ICNSS_FW_READY, &priv->state)) { |
| 3567 | icnss_pr_err("Firmware is not ready yet!, wait for FW READY: state: 0x%lx\n", |
| 3568 | priv->state); |
| 3569 | ret = -ENODEV; |
| 3570 | goto out; |
| 3571 | } |
| 3572 | |
| 3573 | if (test_bit(ICNSS_DRIVER_PROBED, &priv->state)) { |
| 3574 | icnss_pr_err("Machine mode is running, can't run test mode: state: 0x%lx\n", |
| 3575 | priv->state); |
| 3576 | ret = -EINVAL; |
| 3577 | goto out; |
| 3578 | } |
| 3579 | |
| 3580 | if (!test_bit(ICNSS_FW_TEST_MODE, &priv->state)) { |
| 3581 | icnss_pr_err("Test mode not started, state: 0x%lx\n", |
| 3582 | priv->state); |
| 3583 | ret = -EINVAL; |
| 3584 | goto out; |
| 3585 | } |
| 3586 | |
| 3587 | icnss_wlan_disable(ICNSS_OFF); |
| 3588 | |
| 3589 | ret = icnss_hw_power_off(priv); |
| 3590 | |
| 3591 | clear_bit(ICNSS_FW_TEST_MODE, &priv->state); |
| 3592 | |
| 3593 | out: |
| 3594 | return ret; |
| 3595 | } |
| 3596 | static int icnss_test_mode_fw_test(struct icnss_priv *priv, |
| 3597 | enum icnss_driver_mode mode) |
| 3598 | { |
| 3599 | int ret; |
| 3600 | |
| 3601 | if (!test_bit(ICNSS_FW_READY, &priv->state)) { |
| 3602 | icnss_pr_err("Firmware is not ready yet!, wait for FW READY, state: 0x%lx\n", |
| 3603 | priv->state); |
| 3604 | ret = -ENODEV; |
| 3605 | goto out; |
| 3606 | } |
| 3607 | |
| 3608 | if (test_bit(ICNSS_DRIVER_PROBED, &priv->state)) { |
| 3609 | icnss_pr_err("Machine mode is running, can't run test mode, state: 0x%lx\n", |
| 3610 | priv->state); |
| 3611 | ret = -EINVAL; |
| 3612 | goto out; |
| 3613 | } |
| 3614 | |
| 3615 | if (test_bit(ICNSS_FW_TEST_MODE, &priv->state)) { |
| 3616 | icnss_pr_err("Test mode already started, state: 0x%lx\n", |
| 3617 | priv->state); |
| 3618 | ret = -EBUSY; |
| 3619 | goto out; |
| 3620 | } |
| 3621 | |
| 3622 | ret = icnss_hw_power_on(priv); |
| 3623 | if (ret) |
| 3624 | goto out; |
| 3625 | |
| 3626 | set_bit(ICNSS_FW_TEST_MODE, &priv->state); |
| 3627 | |
| 3628 | ret = icnss_wlan_enable(NULL, mode, NULL); |
| 3629 | if (ret) |
| 3630 | goto power_off; |
| 3631 | |
| 3632 | return 0; |
| 3633 | |
| 3634 | power_off: |
| 3635 | icnss_hw_power_off(priv); |
| 3636 | clear_bit(ICNSS_FW_TEST_MODE, &priv->state); |
| 3637 | |
| 3638 | out: |
| 3639 | return ret; |
| 3640 | } |
| 3641 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3642 | static ssize_t icnss_fw_debug_write(struct file *fp, |
| 3643 | const char __user *user_buf, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3644 | size_t count, loff_t *off) |
| 3645 | { |
| 3646 | struct icnss_priv *priv = |
| 3647 | ((struct seq_file *)fp->private_data)->private; |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3648 | char buf[64]; |
| 3649 | char *sptr, *token; |
| 3650 | unsigned int len = 0; |
| 3651 | char *cmd; |
| 3652 | uint64_t val; |
| 3653 | const char *delim = " "; |
| 3654 | int ret = 0; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3655 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3656 | len = min(count, sizeof(buf) - 1); |
| 3657 | if (copy_from_user(buf, user_buf, len)) |
| 3658 | return -EINVAL; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3659 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3660 | buf[len] = '\0'; |
| 3661 | sptr = buf; |
| 3662 | |
| 3663 | token = strsep(&sptr, delim); |
| 3664 | if (!token) |
| 3665 | return -EINVAL; |
| 3666 | if (!sptr) |
| 3667 | return -EINVAL; |
| 3668 | cmd = token; |
| 3669 | |
| 3670 | token = strsep(&sptr, delim); |
| 3671 | if (!token) |
| 3672 | return -EINVAL; |
| 3673 | if (kstrtou64(token, 0, &val)) |
| 3674 | return -EINVAL; |
| 3675 | |
| 3676 | if (strcmp(cmd, "test_mode") == 0) { |
| 3677 | switch (val) { |
| 3678 | case 0: |
| 3679 | ret = icnss_test_mode_fw_test_off(priv); |
| 3680 | break; |
| 3681 | case 1: |
| 3682 | ret = icnss_test_mode_fw_test(priv, ICNSS_WALTEST); |
| 3683 | break; |
| 3684 | case 2: |
| 3685 | ret = icnss_test_mode_fw_test(priv, ICNSS_CCPM); |
| 3686 | break; |
| 3687 | case 3: |
| 3688 | ret = icnss_trigger_recovery(&priv->pdev->dev); |
| 3689 | break; |
| 3690 | default: |
| 3691 | return -EINVAL; |
| 3692 | } |
| 3693 | } else if (strcmp(cmd, "dynamic_feature_mask") == 0) { |
| 3694 | ret = wlfw_dynamic_feature_mask_send_sync_msg(priv, val); |
| 3695 | } else { |
| 3696 | return -EINVAL; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | if (ret) |
| 3700 | return ret; |
| 3701 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3702 | return count; |
| 3703 | } |
| 3704 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3705 | static int icnss_fw_debug_open(struct inode *inode, struct file *file) |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3706 | { |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3707 | return single_open(file, icnss_fw_debug_show, inode->i_private); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3708 | } |
| 3709 | |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3710 | static const struct file_operations icnss_fw_debug_fops = { |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3711 | .read = seq_read, |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3712 | .write = icnss_fw_debug_write, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3713 | .release = single_release, |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3714 | .open = icnss_fw_debug_open, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3715 | .owner = THIS_MODULE, |
| 3716 | .llseek = seq_lseek, |
| 3717 | }; |
| 3718 | |
| 3719 | static ssize_t icnss_stats_write(struct file *fp, const char __user *buf, |
| 3720 | size_t count, loff_t *off) |
| 3721 | { |
| 3722 | struct icnss_priv *priv = |
| 3723 | ((struct seq_file *)fp->private_data)->private; |
| 3724 | int ret; |
| 3725 | u32 val; |
| 3726 | |
| 3727 | ret = kstrtou32_from_user(buf, count, 0, &val); |
| 3728 | if (ret) |
| 3729 | return ret; |
| 3730 | |
| 3731 | if (ret == 0) |
| 3732 | memset(&priv->stats, 0, sizeof(priv->stats)); |
| 3733 | |
| 3734 | return count; |
| 3735 | } |
| 3736 | |
| 3737 | static int icnss_stats_show_state(struct seq_file *s, struct icnss_priv *priv) |
| 3738 | { |
| 3739 | enum icnss_driver_state i; |
| 3740 | int skip = 0; |
| 3741 | unsigned long state; |
| 3742 | |
| 3743 | seq_printf(s, "\nState: 0x%lx(", priv->state); |
| 3744 | for (i = 0, state = priv->state; state != 0; state >>= 1, i++) { |
| 3745 | |
| 3746 | if (!(state & 0x1)) |
| 3747 | continue; |
| 3748 | |
| 3749 | if (skip++) |
| 3750 | seq_puts(s, " | "); |
| 3751 | |
| 3752 | switch (i) { |
| 3753 | case ICNSS_WLFW_QMI_CONNECTED: |
| 3754 | seq_puts(s, "QMI CONN"); |
| 3755 | continue; |
| 3756 | case ICNSS_POWER_ON: |
| 3757 | seq_puts(s, "POWER ON"); |
| 3758 | continue; |
| 3759 | case ICNSS_FW_READY: |
| 3760 | seq_puts(s, "FW READY"); |
| 3761 | continue; |
| 3762 | case ICNSS_DRIVER_PROBED: |
| 3763 | seq_puts(s, "DRIVER PROBED"); |
| 3764 | continue; |
| 3765 | case ICNSS_FW_TEST_MODE: |
| 3766 | seq_puts(s, "FW TEST MODE"); |
| 3767 | continue; |
| 3768 | case ICNSS_PM_SUSPEND: |
| 3769 | seq_puts(s, "PM SUSPEND"); |
| 3770 | continue; |
| 3771 | case ICNSS_PM_SUSPEND_NOIRQ: |
| 3772 | seq_puts(s, "PM SUSPEND NOIRQ"); |
| 3773 | continue; |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 3774 | case ICNSS_SSR_REGISTERED: |
| 3775 | seq_puts(s, "SSR REGISTERED"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3776 | continue; |
Yuanyuan Liu | a0fd3f5 | 2017-06-07 11:19:22 -0700 | [diff] [blame] | 3777 | case ICNSS_PDR_REGISTERED: |
| 3778 | seq_puts(s, "PDR REGISTERED"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3779 | continue; |
| 3780 | case ICNSS_PD_RESTART: |
| 3781 | seq_puts(s, "PD RESTART"); |
| 3782 | continue; |
| 3783 | case ICNSS_MSA0_ASSIGNED: |
| 3784 | seq_puts(s, "MSA0 ASSIGNED"); |
| 3785 | continue; |
| 3786 | case ICNSS_WLFW_EXISTS: |
| 3787 | seq_puts(s, "WLAN FW EXISTS"); |
| 3788 | continue; |
Anurag Chouhan | fa0c70d | 2017-04-10 17:26:47 +0530 | [diff] [blame] | 3789 | case ICNSS_SHUTDOWN_DONE: |
| 3790 | seq_puts(s, "SHUTDOWN DONE"); |
| 3791 | continue; |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 3792 | case ICNSS_HOST_TRIGGERED_PDR: |
| 3793 | seq_puts(s, "HOST TRIGGERED PDR"); |
| 3794 | continue; |
Sameer Thalappil | 93c0073 | 2017-08-18 13:02:32 -0700 | [diff] [blame] | 3795 | case ICNSS_FW_DOWN: |
| 3796 | seq_puts(s, "FW DOWN"); |
| 3797 | continue; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | seq_printf(s, "UNKNOWN-%d", i); |
| 3801 | } |
| 3802 | seq_puts(s, ")\n"); |
| 3803 | |
| 3804 | return 0; |
| 3805 | } |
| 3806 | |
| 3807 | static int icnss_stats_show_capability(struct seq_file *s, |
| 3808 | struct icnss_priv *priv) |
| 3809 | { |
| 3810 | if (test_bit(ICNSS_FW_READY, &priv->state)) { |
| 3811 | seq_puts(s, "\n<---------------- FW Capability ----------------->\n"); |
| 3812 | seq_printf(s, "Chip ID: 0x%x\n", priv->chip_info.chip_id); |
| 3813 | seq_printf(s, "Chip family: 0x%x\n", |
| 3814 | priv->chip_info.chip_family); |
| 3815 | seq_printf(s, "Board ID: 0x%x\n", priv->board_info.board_id); |
| 3816 | seq_printf(s, "SOC Info: 0x%x\n", priv->soc_info.soc_id); |
| 3817 | seq_printf(s, "Firmware Version: 0x%x\n", |
| 3818 | priv->fw_version_info.fw_version); |
| 3819 | seq_printf(s, "Firmware Build Timestamp: %s\n", |
| 3820 | priv->fw_version_info.fw_build_timestamp); |
| 3821 | seq_printf(s, "Firmware Build ID: %s\n", |
| 3822 | priv->fw_build_id); |
| 3823 | } |
| 3824 | |
| 3825 | return 0; |
| 3826 | } |
| 3827 | |
Yuanyuan Liu | 4c497ff | 2016-12-16 16:36:08 -0800 | [diff] [blame] | 3828 | static int icnss_stats_show_rejuvenate_info(struct seq_file *s, |
| 3829 | struct icnss_priv *priv) |
| 3830 | { |
| 3831 | if (priv->stats.rejuvenate_ind) { |
| 3832 | seq_puts(s, "\n<---------------- Rejuvenate Info ----------------->\n"); |
| 3833 | seq_printf(s, "Number of Rejuvenations: %u\n", |
| 3834 | priv->stats.rejuvenate_ind); |
| 3835 | seq_printf(s, "Cause for Rejuvenation: 0x%x\n", |
| 3836 | priv->cause_for_rejuvenation); |
| 3837 | seq_printf(s, "Requesting Sub-System: 0x%x\n", |
| 3838 | priv->requesting_sub_system); |
| 3839 | seq_printf(s, "Line Number: %u\n", |
| 3840 | priv->line_number); |
| 3841 | seq_printf(s, "Function Name: %s\n", |
| 3842 | priv->function_name); |
| 3843 | } |
| 3844 | |
| 3845 | return 0; |
| 3846 | } |
| 3847 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3848 | static int icnss_stats_show_events(struct seq_file *s, struct icnss_priv *priv) |
| 3849 | { |
| 3850 | int i; |
| 3851 | |
| 3852 | seq_puts(s, "\n<----------------- Events stats ------------------->\n"); |
| 3853 | seq_printf(s, "%24s %16s %16s\n", "Events", "Posted", "Processed"); |
| 3854 | for (i = 0; i < ICNSS_DRIVER_EVENT_MAX; i++) |
| 3855 | seq_printf(s, "%24s %16u %16u\n", |
| 3856 | icnss_driver_event_to_str(i), |
| 3857 | priv->stats.events[i].posted, |
| 3858 | priv->stats.events[i].processed); |
| 3859 | |
| 3860 | return 0; |
| 3861 | } |
| 3862 | |
| 3863 | static int icnss_stats_show_irqs(struct seq_file *s, struct icnss_priv *priv) |
| 3864 | { |
| 3865 | int i; |
| 3866 | |
| 3867 | seq_puts(s, "\n<------------------ IRQ stats ------------------->\n"); |
| 3868 | seq_printf(s, "%4s %4s %8s %8s %8s %8s\n", "CE_ID", "IRQ", "Request", |
| 3869 | "Free", "Enable", "Disable"); |
| 3870 | for (i = 0; i < ICNSS_MAX_IRQ_REGISTRATIONS; i++) |
| 3871 | seq_printf(s, "%4d: %4u %8u %8u %8u %8u\n", i, |
| 3872 | priv->ce_irqs[i], priv->stats.ce_irqs[i].request, |
| 3873 | priv->stats.ce_irqs[i].free, |
| 3874 | priv->stats.ce_irqs[i].enable, |
| 3875 | priv->stats.ce_irqs[i].disable); |
| 3876 | |
| 3877 | return 0; |
| 3878 | } |
| 3879 | |
| 3880 | static int icnss_stats_show(struct seq_file *s, void *data) |
| 3881 | { |
| 3882 | #define ICNSS_STATS_DUMP(_s, _priv, _x) \ |
| 3883 | seq_printf(_s, "%24s: %u\n", #_x, _priv->stats._x) |
| 3884 | |
| 3885 | struct icnss_priv *priv = s->private; |
| 3886 | |
| 3887 | ICNSS_STATS_DUMP(s, priv, ind_register_req); |
| 3888 | ICNSS_STATS_DUMP(s, priv, ind_register_resp); |
| 3889 | ICNSS_STATS_DUMP(s, priv, ind_register_err); |
| 3890 | ICNSS_STATS_DUMP(s, priv, msa_info_req); |
| 3891 | ICNSS_STATS_DUMP(s, priv, msa_info_resp); |
| 3892 | ICNSS_STATS_DUMP(s, priv, msa_info_err); |
| 3893 | ICNSS_STATS_DUMP(s, priv, msa_ready_req); |
| 3894 | ICNSS_STATS_DUMP(s, priv, msa_ready_resp); |
| 3895 | ICNSS_STATS_DUMP(s, priv, msa_ready_err); |
| 3896 | ICNSS_STATS_DUMP(s, priv, msa_ready_ind); |
| 3897 | ICNSS_STATS_DUMP(s, priv, cap_req); |
| 3898 | ICNSS_STATS_DUMP(s, priv, cap_resp); |
| 3899 | ICNSS_STATS_DUMP(s, priv, cap_err); |
| 3900 | ICNSS_STATS_DUMP(s, priv, pin_connect_result); |
| 3901 | ICNSS_STATS_DUMP(s, priv, cfg_req); |
| 3902 | ICNSS_STATS_DUMP(s, priv, cfg_resp); |
| 3903 | ICNSS_STATS_DUMP(s, priv, cfg_req_err); |
| 3904 | ICNSS_STATS_DUMP(s, priv, mode_req); |
| 3905 | ICNSS_STATS_DUMP(s, priv, mode_resp); |
| 3906 | ICNSS_STATS_DUMP(s, priv, mode_req_err); |
| 3907 | ICNSS_STATS_DUMP(s, priv, ini_req); |
| 3908 | ICNSS_STATS_DUMP(s, priv, ini_resp); |
| 3909 | ICNSS_STATS_DUMP(s, priv, ini_req_err); |
| 3910 | ICNSS_STATS_DUMP(s, priv, vbatt_req); |
| 3911 | ICNSS_STATS_DUMP(s, priv, vbatt_resp); |
| 3912 | ICNSS_STATS_DUMP(s, priv, vbatt_req_err); |
Yuanyuan Liu | 4c497ff | 2016-12-16 16:36:08 -0800 | [diff] [blame] | 3913 | ICNSS_STATS_DUMP(s, priv, rejuvenate_ind); |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 3914 | ICNSS_STATS_DUMP(s, priv, rejuvenate_ack_req); |
| 3915 | ICNSS_STATS_DUMP(s, priv, rejuvenate_ack_resp); |
| 3916 | ICNSS_STATS_DUMP(s, priv, rejuvenate_ack_err); |
Sameer Thalappil | 0aaa758 | 2017-06-23 15:43:43 -0700 | [diff] [blame] | 3917 | ICNSS_STATS_DUMP(s, priv, recovery.pdr_fw_crash); |
| 3918 | ICNSS_STATS_DUMP(s, priv, recovery.pdr_host_error); |
| 3919 | ICNSS_STATS_DUMP(s, priv, recovery.root_pd_crash); |
| 3920 | ICNSS_STATS_DUMP(s, priv, recovery.root_pd_shutdown); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3921 | |
| 3922 | seq_puts(s, "\n<------------------ PM stats ------------------->\n"); |
| 3923 | ICNSS_STATS_DUMP(s, priv, pm_suspend); |
| 3924 | ICNSS_STATS_DUMP(s, priv, pm_suspend_err); |
| 3925 | ICNSS_STATS_DUMP(s, priv, pm_resume); |
| 3926 | ICNSS_STATS_DUMP(s, priv, pm_resume_err); |
| 3927 | ICNSS_STATS_DUMP(s, priv, pm_suspend_noirq); |
| 3928 | ICNSS_STATS_DUMP(s, priv, pm_suspend_noirq_err); |
| 3929 | ICNSS_STATS_DUMP(s, priv, pm_resume_noirq); |
| 3930 | ICNSS_STATS_DUMP(s, priv, pm_resume_noirq_err); |
| 3931 | ICNSS_STATS_DUMP(s, priv, pm_stay_awake); |
| 3932 | ICNSS_STATS_DUMP(s, priv, pm_relax); |
| 3933 | |
| 3934 | icnss_stats_show_irqs(s, priv); |
| 3935 | |
| 3936 | icnss_stats_show_capability(s, priv); |
| 3937 | |
Yuanyuan Liu | 4c497ff | 2016-12-16 16:36:08 -0800 | [diff] [blame] | 3938 | icnss_stats_show_rejuvenate_info(s, priv); |
| 3939 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 3940 | icnss_stats_show_events(s, priv); |
| 3941 | |
| 3942 | icnss_stats_show_state(s, priv); |
| 3943 | |
| 3944 | return 0; |
| 3945 | #undef ICNSS_STATS_DUMP |
| 3946 | } |
| 3947 | |
| 3948 | static int icnss_stats_open(struct inode *inode, struct file *file) |
| 3949 | { |
| 3950 | return single_open(file, icnss_stats_show, inode->i_private); |
| 3951 | } |
| 3952 | |
| 3953 | static const struct file_operations icnss_stats_fops = { |
| 3954 | .read = seq_read, |
| 3955 | .write = icnss_stats_write, |
| 3956 | .release = single_release, |
| 3957 | .open = icnss_stats_open, |
| 3958 | .owner = THIS_MODULE, |
| 3959 | .llseek = seq_lseek, |
| 3960 | }; |
| 3961 | |
| 3962 | static int icnss_regwrite_show(struct seq_file *s, void *data) |
| 3963 | { |
| 3964 | struct icnss_priv *priv = s->private; |
| 3965 | |
| 3966 | seq_puts(s, "\nUsage: echo <mem_type> <offset> <reg_val> > <debugfs>/icnss/reg_write\n"); |
| 3967 | |
| 3968 | if (!test_bit(ICNSS_FW_READY, &priv->state)) |
| 3969 | seq_puts(s, "Firmware is not ready yet!, wait for FW READY\n"); |
| 3970 | |
| 3971 | return 0; |
| 3972 | } |
| 3973 | |
| 3974 | static ssize_t icnss_regwrite_write(struct file *fp, |
| 3975 | const char __user *user_buf, |
| 3976 | size_t count, loff_t *off) |
| 3977 | { |
| 3978 | struct icnss_priv *priv = |
| 3979 | ((struct seq_file *)fp->private_data)->private; |
| 3980 | char buf[64]; |
| 3981 | char *sptr, *token; |
| 3982 | unsigned int len = 0; |
| 3983 | uint32_t reg_offset, mem_type, reg_val; |
| 3984 | const char *delim = " "; |
| 3985 | int ret = 0; |
| 3986 | |
| 3987 | if (!test_bit(ICNSS_FW_READY, &priv->state) || |
| 3988 | !test_bit(ICNSS_POWER_ON, &priv->state)) |
| 3989 | return -EINVAL; |
| 3990 | |
| 3991 | len = min(count, sizeof(buf) - 1); |
| 3992 | if (copy_from_user(buf, user_buf, len)) |
| 3993 | return -EFAULT; |
| 3994 | |
| 3995 | buf[len] = '\0'; |
| 3996 | sptr = buf; |
| 3997 | |
| 3998 | token = strsep(&sptr, delim); |
| 3999 | if (!token) |
| 4000 | return -EINVAL; |
| 4001 | |
| 4002 | if (!sptr) |
| 4003 | return -EINVAL; |
| 4004 | |
| 4005 | if (kstrtou32(token, 0, &mem_type)) |
| 4006 | return -EINVAL; |
| 4007 | |
| 4008 | token = strsep(&sptr, delim); |
| 4009 | if (!token) |
| 4010 | return -EINVAL; |
| 4011 | |
| 4012 | if (!sptr) |
| 4013 | return -EINVAL; |
| 4014 | |
| 4015 | if (kstrtou32(token, 0, ®_offset)) |
| 4016 | return -EINVAL; |
| 4017 | |
| 4018 | token = strsep(&sptr, delim); |
| 4019 | if (!token) |
| 4020 | return -EINVAL; |
| 4021 | |
| 4022 | if (kstrtou32(token, 0, ®_val)) |
| 4023 | return -EINVAL; |
| 4024 | |
| 4025 | ret = wlfw_athdiag_write_send_sync_msg(priv, reg_offset, mem_type, |
| 4026 | sizeof(uint32_t), |
| 4027 | (uint8_t *)®_val); |
| 4028 | if (ret) |
| 4029 | return ret; |
| 4030 | |
| 4031 | return count; |
| 4032 | } |
| 4033 | |
| 4034 | static int icnss_regwrite_open(struct inode *inode, struct file *file) |
| 4035 | { |
| 4036 | return single_open(file, icnss_regwrite_show, inode->i_private); |
| 4037 | } |
| 4038 | |
| 4039 | static const struct file_operations icnss_regwrite_fops = { |
| 4040 | .read = seq_read, |
| 4041 | .write = icnss_regwrite_write, |
| 4042 | .open = icnss_regwrite_open, |
| 4043 | .owner = THIS_MODULE, |
| 4044 | .llseek = seq_lseek, |
| 4045 | }; |
| 4046 | |
| 4047 | static int icnss_regread_show(struct seq_file *s, void *data) |
| 4048 | { |
| 4049 | struct icnss_priv *priv = s->private; |
| 4050 | |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4051 | mutex_lock(&priv->dev_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4052 | if (!priv->diag_reg_read_buf) { |
| 4053 | seq_puts(s, "Usage: echo <mem_type> <offset> <data_len> > <debugfs>/icnss/reg_read\n"); |
| 4054 | |
| 4055 | if (!test_bit(ICNSS_FW_READY, &priv->state)) |
| 4056 | seq_puts(s, "Firmware is not ready yet!, wait for FW READY\n"); |
| 4057 | |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4058 | mutex_unlock(&priv->dev_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4059 | return 0; |
| 4060 | } |
| 4061 | |
| 4062 | seq_printf(s, "REGREAD: Addr 0x%x Type 0x%x Length 0x%x\n", |
| 4063 | priv->diag_reg_read_addr, priv->diag_reg_read_mem_type, |
| 4064 | priv->diag_reg_read_len); |
| 4065 | |
| 4066 | seq_hex_dump(s, "", DUMP_PREFIX_OFFSET, 32, 4, priv->diag_reg_read_buf, |
| 4067 | priv->diag_reg_read_len, false); |
| 4068 | |
| 4069 | priv->diag_reg_read_len = 0; |
| 4070 | kfree(priv->diag_reg_read_buf); |
| 4071 | priv->diag_reg_read_buf = NULL; |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4072 | mutex_unlock(&priv->dev_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4073 | |
| 4074 | return 0; |
| 4075 | } |
| 4076 | |
| 4077 | static ssize_t icnss_regread_write(struct file *fp, const char __user *user_buf, |
| 4078 | size_t count, loff_t *off) |
| 4079 | { |
| 4080 | struct icnss_priv *priv = |
| 4081 | ((struct seq_file *)fp->private_data)->private; |
| 4082 | char buf[64]; |
| 4083 | char *sptr, *token; |
| 4084 | unsigned int len = 0; |
| 4085 | uint32_t reg_offset, mem_type; |
| 4086 | uint32_t data_len = 0; |
| 4087 | uint8_t *reg_buf = NULL; |
| 4088 | const char *delim = " "; |
| 4089 | int ret = 0; |
| 4090 | |
| 4091 | if (!test_bit(ICNSS_FW_READY, &priv->state) || |
| 4092 | !test_bit(ICNSS_POWER_ON, &priv->state)) |
| 4093 | return -EINVAL; |
| 4094 | |
| 4095 | len = min(count, sizeof(buf) - 1); |
| 4096 | if (copy_from_user(buf, user_buf, len)) |
| 4097 | return -EFAULT; |
| 4098 | |
| 4099 | buf[len] = '\0'; |
| 4100 | sptr = buf; |
| 4101 | |
| 4102 | token = strsep(&sptr, delim); |
| 4103 | if (!token) |
| 4104 | return -EINVAL; |
| 4105 | |
| 4106 | if (!sptr) |
| 4107 | return -EINVAL; |
| 4108 | |
| 4109 | if (kstrtou32(token, 0, &mem_type)) |
| 4110 | return -EINVAL; |
| 4111 | |
| 4112 | token = strsep(&sptr, delim); |
| 4113 | if (!token) |
| 4114 | return -EINVAL; |
| 4115 | |
| 4116 | if (!sptr) |
| 4117 | return -EINVAL; |
| 4118 | |
| 4119 | if (kstrtou32(token, 0, ®_offset)) |
| 4120 | return -EINVAL; |
| 4121 | |
| 4122 | token = strsep(&sptr, delim); |
| 4123 | if (!token) |
| 4124 | return -EINVAL; |
| 4125 | |
| 4126 | if (kstrtou32(token, 0, &data_len)) |
| 4127 | return -EINVAL; |
| 4128 | |
| 4129 | if (data_len == 0 || |
| 4130 | data_len > QMI_WLFW_MAX_DATA_SIZE_V01) |
| 4131 | return -EINVAL; |
| 4132 | |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4133 | mutex_lock(&priv->dev_lock); |
Yuanyuan Liu | 5347b0c | 2017-05-24 11:57:37 -0700 | [diff] [blame] | 4134 | kfree(priv->diag_reg_read_buf); |
| 4135 | priv->diag_reg_read_buf = NULL; |
| 4136 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4137 | reg_buf = kzalloc(data_len, GFP_KERNEL); |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4138 | if (!reg_buf) { |
| 4139 | mutex_unlock(&priv->dev_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4140 | return -ENOMEM; |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4141 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4142 | |
| 4143 | ret = wlfw_athdiag_read_send_sync_msg(priv, reg_offset, |
| 4144 | mem_type, data_len, |
| 4145 | reg_buf); |
| 4146 | if (ret) { |
| 4147 | kfree(reg_buf); |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4148 | mutex_unlock(&priv->dev_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4149 | return ret; |
| 4150 | } |
| 4151 | |
| 4152 | priv->diag_reg_read_addr = reg_offset; |
| 4153 | priv->diag_reg_read_mem_type = mem_type; |
| 4154 | priv->diag_reg_read_len = data_len; |
| 4155 | priv->diag_reg_read_buf = reg_buf; |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4156 | mutex_unlock(&priv->dev_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4157 | |
| 4158 | return count; |
| 4159 | } |
| 4160 | |
| 4161 | static int icnss_regread_open(struct inode *inode, struct file *file) |
| 4162 | { |
| 4163 | return single_open(file, icnss_regread_show, inode->i_private); |
| 4164 | } |
| 4165 | |
| 4166 | static const struct file_operations icnss_regread_fops = { |
| 4167 | .read = seq_read, |
| 4168 | .write = icnss_regread_write, |
| 4169 | .open = icnss_regread_open, |
| 4170 | .owner = THIS_MODULE, |
| 4171 | .llseek = seq_lseek, |
| 4172 | }; |
| 4173 | |
Yuanyuan Liu | c74489f | 2017-05-24 12:13:49 -0700 | [diff] [blame] | 4174 | #ifdef CONFIG_ICNSS_DEBUG |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4175 | static int icnss_debugfs_create(struct icnss_priv *priv) |
| 4176 | { |
| 4177 | int ret = 0; |
| 4178 | struct dentry *root_dentry; |
| 4179 | |
Yuanyuan Liu | c74489f | 2017-05-24 12:13:49 -0700 | [diff] [blame] | 4180 | root_dentry = debugfs_create_dir("icnss", NULL); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4181 | |
| 4182 | if (IS_ERR(root_dentry)) { |
| 4183 | ret = PTR_ERR(root_dentry); |
| 4184 | icnss_pr_err("Unable to create debugfs %d\n", ret); |
| 4185 | goto out; |
| 4186 | } |
| 4187 | |
| 4188 | priv->root_dentry = root_dentry; |
| 4189 | |
Yuanyuan Liu | 8413275 | 2017-05-24 12:07:12 -0700 | [diff] [blame] | 4190 | debugfs_create_file("fw_debug", 0600, root_dentry, priv, |
Yuanyuan Liu | 5cd732a | 2017-02-09 10:42:01 -0800 | [diff] [blame] | 4191 | &icnss_fw_debug_fops); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4192 | |
Yuanyuan Liu | 8413275 | 2017-05-24 12:07:12 -0700 | [diff] [blame] | 4193 | debugfs_create_file("stats", 0600, root_dentry, priv, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4194 | &icnss_stats_fops); |
| 4195 | debugfs_create_file("reg_read", 0600, root_dentry, priv, |
| 4196 | &icnss_regread_fops); |
Yuanyuan Liu | 8413275 | 2017-05-24 12:07:12 -0700 | [diff] [blame] | 4197 | debugfs_create_file("reg_write", 0600, root_dentry, priv, |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4198 | &icnss_regwrite_fops); |
| 4199 | |
| 4200 | out: |
| 4201 | return ret; |
| 4202 | } |
Yuanyuan Liu | c74489f | 2017-05-24 12:13:49 -0700 | [diff] [blame] | 4203 | #else |
| 4204 | static int icnss_debugfs_create(struct icnss_priv *priv) |
| 4205 | { |
| 4206 | int ret = 0; |
| 4207 | struct dentry *root_dentry; |
| 4208 | |
| 4209 | root_dentry = debugfs_create_dir("icnss", NULL); |
| 4210 | |
| 4211 | if (IS_ERR(root_dentry)) { |
| 4212 | ret = PTR_ERR(root_dentry); |
| 4213 | icnss_pr_err("Unable to create debugfs %d\n", ret); |
| 4214 | return ret; |
| 4215 | } |
| 4216 | |
| 4217 | priv->root_dentry = root_dentry; |
| 4218 | |
| 4219 | debugfs_create_file("stats", 0600, root_dentry, priv, |
| 4220 | &icnss_stats_fops); |
| 4221 | return 0; |
| 4222 | } |
| 4223 | #endif |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4224 | |
| 4225 | static void icnss_debugfs_destroy(struct icnss_priv *priv) |
| 4226 | { |
| 4227 | debugfs_remove_recursive(priv->root_dentry); |
| 4228 | } |
| 4229 | |
| 4230 | static int icnss_get_vbatt_info(struct icnss_priv *priv) |
| 4231 | { |
| 4232 | struct qpnp_adc_tm_chip *adc_tm_dev = NULL; |
| 4233 | struct qpnp_vadc_chip *vadc_dev = NULL; |
| 4234 | int ret = 0; |
| 4235 | |
| 4236 | if (test_bit(VBATT_DISABLE, &quirks)) { |
| 4237 | icnss_pr_dbg("VBATT feature is disabled\n"); |
| 4238 | return ret; |
| 4239 | } |
| 4240 | |
| 4241 | adc_tm_dev = qpnp_get_adc_tm(&priv->pdev->dev, "icnss"); |
| 4242 | if (PTR_ERR(adc_tm_dev) == -EPROBE_DEFER) { |
| 4243 | icnss_pr_err("adc_tm_dev probe defer\n"); |
| 4244 | return -EPROBE_DEFER; |
| 4245 | } |
| 4246 | |
| 4247 | if (IS_ERR(adc_tm_dev)) { |
| 4248 | ret = PTR_ERR(adc_tm_dev); |
| 4249 | icnss_pr_err("Not able to get ADC dev, VBATT monitoring is disabled: %d\n", |
| 4250 | ret); |
| 4251 | return ret; |
| 4252 | } |
| 4253 | |
| 4254 | vadc_dev = qpnp_get_vadc(&priv->pdev->dev, "icnss"); |
| 4255 | if (PTR_ERR(vadc_dev) == -EPROBE_DEFER) { |
| 4256 | icnss_pr_err("vadc_dev probe defer\n"); |
| 4257 | return -EPROBE_DEFER; |
| 4258 | } |
| 4259 | |
| 4260 | if (IS_ERR(vadc_dev)) { |
| 4261 | ret = PTR_ERR(vadc_dev); |
| 4262 | icnss_pr_err("Not able to get VADC dev, VBATT monitoring is disabled: %d\n", |
| 4263 | ret); |
| 4264 | return ret; |
| 4265 | } |
| 4266 | |
| 4267 | priv->adc_tm_dev = adc_tm_dev; |
| 4268 | priv->vadc_dev = vadc_dev; |
| 4269 | |
| 4270 | return 0; |
| 4271 | } |
| 4272 | |
| 4273 | static int icnss_probe(struct platform_device *pdev) |
| 4274 | { |
| 4275 | int ret = 0; |
| 4276 | struct resource *res; |
| 4277 | int i; |
| 4278 | struct device *dev = &pdev->dev; |
| 4279 | struct icnss_priv *priv; |
Hardik Kantilal Patel | 420482e | 2017-05-05 16:57:48 +0530 | [diff] [blame] | 4280 | const __be32 *addrp; |
| 4281 | u64 prop_size = 0; |
| 4282 | struct device_node *np; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4283 | |
| 4284 | if (penv) { |
| 4285 | icnss_pr_err("Driver is already initialized\n"); |
| 4286 | return -EEXIST; |
| 4287 | } |
| 4288 | |
| 4289 | icnss_pr_dbg("Platform driver probe\n"); |
| 4290 | |
| 4291 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 4292 | if (!priv) |
| 4293 | return -ENOMEM; |
| 4294 | |
| 4295 | priv->magic = ICNSS_MAGIC; |
| 4296 | dev_set_drvdata(dev, priv); |
| 4297 | |
| 4298 | priv->pdev = pdev; |
| 4299 | |
| 4300 | ret = icnss_get_vbatt_info(priv); |
| 4301 | if (ret == -EPROBE_DEFER) |
| 4302 | goto out; |
| 4303 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 4304 | memcpy(priv->vreg_info, icnss_vreg_info, sizeof(icnss_vreg_info)); |
| 4305 | for (i = 0; i < ICNSS_VREG_INFO_SIZE; i++) { |
| 4306 | ret = icnss_get_vreg_info(dev, &priv->vreg_info[i]); |
| 4307 | |
| 4308 | if (ret) |
| 4309 | goto out; |
| 4310 | } |
| 4311 | |
| 4312 | memcpy(priv->clk_info, icnss_clk_info, sizeof(icnss_clk_info)); |
| 4313 | for (i = 0; i < ICNSS_CLK_INFO_SIZE; i++) { |
| 4314 | ret = icnss_get_clk_info(dev, &priv->clk_info[i]); |
| 4315 | if (ret) |
| 4316 | goto out; |
| 4317 | } |
| 4318 | |
| 4319 | if (of_property_read_bool(pdev->dev.of_node, "qcom,smmu-s1-bypass")) |
| 4320 | priv->bypass_s1_smmu = true; |
| 4321 | |
| 4322 | icnss_pr_dbg("SMMU S1 BYPASS = %d\n", priv->bypass_s1_smmu); |
| 4323 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4324 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "membase"); |
| 4325 | if (!res) { |
| 4326 | icnss_pr_err("Memory base not found in DT\n"); |
| 4327 | ret = -EINVAL; |
| 4328 | goto out; |
| 4329 | } |
| 4330 | |
| 4331 | priv->mem_base_pa = res->start; |
| 4332 | priv->mem_base_va = devm_ioremap(dev, priv->mem_base_pa, |
| 4333 | resource_size(res)); |
| 4334 | if (!priv->mem_base_va) { |
| 4335 | icnss_pr_err("Memory base ioremap failed: phy addr: %pa\n", |
| 4336 | &priv->mem_base_pa); |
| 4337 | ret = -EINVAL; |
| 4338 | goto out; |
| 4339 | } |
| 4340 | icnss_pr_dbg("MEM_BASE pa: %pa, va: 0x%p\n", &priv->mem_base_pa, |
| 4341 | priv->mem_base_va); |
| 4342 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4343 | for (i = 0; i < ICNSS_MAX_IRQ_REGISTRATIONS; i++) { |
| 4344 | res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, i); |
| 4345 | if (!res) { |
| 4346 | icnss_pr_err("Fail to get IRQ-%d\n", i); |
| 4347 | ret = -ENODEV; |
| 4348 | goto out; |
| 4349 | } else { |
| 4350 | priv->ce_irqs[i] = res->start; |
| 4351 | } |
| 4352 | } |
| 4353 | |
Hardik Kantilal Patel | 420482e | 2017-05-05 16:57:48 +0530 | [diff] [blame] | 4354 | np = of_parse_phandle(dev->of_node, |
| 4355 | "qcom,wlan-msa-fixed-region", 0); |
| 4356 | if (np) { |
| 4357 | addrp = of_get_address(np, 0, &prop_size, NULL); |
| 4358 | if (!addrp) { |
| 4359 | icnss_pr_err("Failed to get assigned-addresses or property\n"); |
| 4360 | ret = -EINVAL; |
| 4361 | goto out; |
| 4362 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4363 | |
Hardik Kantilal Patel | 420482e | 2017-05-05 16:57:48 +0530 | [diff] [blame] | 4364 | priv->msa_pa = of_translate_address(np, addrp); |
| 4365 | if (priv->msa_pa == OF_BAD_ADDR) { |
| 4366 | icnss_pr_err("Failed to translate MSA PA from device-tree\n"); |
| 4367 | ret = -EINVAL; |
| 4368 | goto out; |
| 4369 | } |
| 4370 | |
| 4371 | priv->msa_va = memremap(priv->msa_pa, |
| 4372 | (unsigned long)prop_size, MEMREMAP_WT); |
| 4373 | if (!priv->msa_va) { |
| 4374 | icnss_pr_err("MSA PA ioremap failed: phy addr: %pa\n", |
| 4375 | &priv->msa_pa); |
| 4376 | ret = -EINVAL; |
| 4377 | goto out; |
| 4378 | } |
| 4379 | priv->msa_mem_size = prop_size; |
| 4380 | } else { |
| 4381 | ret = of_property_read_u32(dev->of_node, "qcom,wlan-msa-memory", |
| 4382 | &priv->msa_mem_size); |
| 4383 | if (ret || priv->msa_mem_size == 0) { |
| 4384 | icnss_pr_err("Fail to get MSA Memory Size: %u ret: %d\n", |
| 4385 | priv->msa_mem_size, ret); |
| 4386 | goto out; |
| 4387 | } |
| 4388 | |
| 4389 | priv->msa_va = dmam_alloc_coherent(&pdev->dev, |
| 4390 | priv->msa_mem_size, &priv->msa_pa, GFP_KERNEL); |
| 4391 | |
| 4392 | if (!priv->msa_va) { |
| 4393 | icnss_pr_err("DMA alloc failed for MSA\n"); |
| 4394 | ret = -ENOMEM; |
| 4395 | goto out; |
| 4396 | } |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4397 | } |
| 4398 | |
Hardik Kantilal Patel | 420482e | 2017-05-05 16:57:48 +0530 | [diff] [blame] | 4399 | icnss_pr_dbg("MSA pa: %pa, MSA va: 0x%p MSA Memory Size: 0x%x\n", |
| 4400 | &priv->msa_pa, (void *)priv->msa_va, priv->msa_mem_size); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4401 | |
| 4402 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 4403 | "smmu_iova_base"); |
| 4404 | if (!res) { |
| 4405 | icnss_pr_err("SMMU IOVA base not found\n"); |
| 4406 | } else { |
| 4407 | priv->smmu_iova_start = res->start; |
| 4408 | priv->smmu_iova_len = resource_size(res); |
| 4409 | icnss_pr_dbg("SMMU IOVA start: %pa, len: %zu\n", |
| 4410 | &priv->smmu_iova_start, priv->smmu_iova_len); |
| 4411 | |
| 4412 | res = platform_get_resource_byname(pdev, |
| 4413 | IORESOURCE_MEM, |
| 4414 | "smmu_iova_ipa"); |
| 4415 | if (!res) { |
| 4416 | icnss_pr_err("SMMU IOVA IPA not found\n"); |
| 4417 | } else { |
| 4418 | priv->smmu_iova_ipa_start = res->start; |
| 4419 | priv->smmu_iova_ipa_len = resource_size(res); |
| 4420 | icnss_pr_dbg("SMMU IOVA IPA start: %pa, len: %zu\n", |
| 4421 | &priv->smmu_iova_ipa_start, |
| 4422 | priv->smmu_iova_ipa_len); |
| 4423 | } |
| 4424 | |
| 4425 | ret = icnss_smmu_init(priv); |
| 4426 | if (ret < 0) { |
| 4427 | icnss_pr_err("SMMU init failed, err = %d, start: %pad, len: %zx\n", |
| 4428 | ret, &priv->smmu_iova_start, |
| 4429 | priv->smmu_iova_len); |
| 4430 | goto out; |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | spin_lock_init(&priv->event_lock); |
| 4435 | spin_lock_init(&priv->on_off_lock); |
Sarada Prasanna Garnayak | b728ff0 | 2017-06-08 15:34:13 +0530 | [diff] [blame] | 4436 | mutex_init(&priv->dev_lock); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4437 | |
| 4438 | priv->event_wq = alloc_workqueue("icnss_driver_event", WQ_UNBOUND, 1); |
| 4439 | if (!priv->event_wq) { |
| 4440 | icnss_pr_err("Workqueue creation failed\n"); |
| 4441 | ret = -EFAULT; |
| 4442 | goto out_smmu_deinit; |
| 4443 | } |
| 4444 | |
| 4445 | INIT_WORK(&priv->event_work, icnss_driver_event_work); |
| 4446 | INIT_WORK(&priv->qmi_recv_msg_work, icnss_qmi_wlfw_clnt_notify_work); |
| 4447 | INIT_LIST_HEAD(&priv->event_list); |
| 4448 | |
| 4449 | ret = qmi_svc_event_notifier_register(WLFW_SERVICE_ID_V01, |
| 4450 | WLFW_SERVICE_VERS_V01, |
| 4451 | WLFW_SERVICE_INS_ID_V01, |
| 4452 | &wlfw_clnt_nb); |
| 4453 | if (ret < 0) { |
| 4454 | icnss_pr_err("Notifier register failed: %d\n", ret); |
| 4455 | goto out_destroy_wq; |
| 4456 | } |
| 4457 | |
| 4458 | icnss_enable_recovery(priv); |
| 4459 | |
| 4460 | icnss_debugfs_create(priv); |
| 4461 | |
Yuanyuan Liu | c1ad928 | 2017-06-07 17:39:54 -0700 | [diff] [blame] | 4462 | ret = device_init_wakeup(&priv->pdev->dev, true); |
| 4463 | if (ret) |
| 4464 | icnss_pr_err("Failed to init platform device wakeup source, err = %d\n", |
| 4465 | ret); |
| 4466 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4467 | penv = priv; |
| 4468 | |
| 4469 | icnss_pr_info("Platform driver probed successfully\n"); |
| 4470 | |
| 4471 | return 0; |
| 4472 | |
| 4473 | out_destroy_wq: |
| 4474 | destroy_workqueue(priv->event_wq); |
| 4475 | out_smmu_deinit: |
| 4476 | icnss_smmu_deinit(priv); |
| 4477 | out: |
| 4478 | dev_set_drvdata(dev, NULL); |
| 4479 | |
| 4480 | return ret; |
| 4481 | } |
| 4482 | |
| 4483 | static int icnss_remove(struct platform_device *pdev) |
| 4484 | { |
| 4485 | icnss_pr_info("Removing driver: state: 0x%lx\n", penv->state); |
| 4486 | |
Yuanyuan Liu | c1ad928 | 2017-06-07 17:39:54 -0700 | [diff] [blame] | 4487 | device_init_wakeup(&penv->pdev->dev, false); |
| 4488 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4489 | icnss_debugfs_destroy(penv); |
| 4490 | |
| 4491 | icnss_modem_ssr_unregister_notifier(penv); |
| 4492 | |
| 4493 | destroy_ramdump_device(penv->msa0_dump_dev); |
| 4494 | |
| 4495 | icnss_pdr_unregister_notifier(penv); |
| 4496 | |
| 4497 | qmi_svc_event_notifier_unregister(WLFW_SERVICE_ID_V01, |
| 4498 | WLFW_SERVICE_VERS_V01, |
| 4499 | WLFW_SERVICE_INS_ID_V01, |
| 4500 | &wlfw_clnt_nb); |
| 4501 | if (penv->event_wq) |
| 4502 | destroy_workqueue(penv->event_wq); |
| 4503 | |
| 4504 | icnss_hw_power_off(penv); |
| 4505 | |
Anurag Chouhan | facf392 | 2017-06-08 18:26:56 +0530 | [diff] [blame] | 4506 | icnss_assign_msa_perm_all(penv, ICNSS_MSA_PERM_HLOS_ALL); |
| 4507 | clear_bit(ICNSS_MSA0_ASSIGNED, &penv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4508 | |
| 4509 | dev_set_drvdata(&pdev->dev, NULL); |
| 4510 | |
| 4511 | return 0; |
| 4512 | } |
| 4513 | |
| 4514 | #ifdef CONFIG_PM_SLEEP |
| 4515 | static int icnss_pm_suspend(struct device *dev) |
| 4516 | { |
| 4517 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 4518 | int ret = 0; |
| 4519 | |
| 4520 | if (priv->magic != ICNSS_MAGIC) { |
| 4521 | icnss_pr_err("Invalid drvdata for pm suspend: dev %p, data %p, magic 0x%x\n", |
| 4522 | dev, priv, priv->magic); |
| 4523 | return -EINVAL; |
| 4524 | } |
| 4525 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 4526 | icnss_pr_vdbg("PM Suspend, state: 0x%lx\n", priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4527 | |
| 4528 | if (!priv->ops || !priv->ops->pm_suspend || |
| 4529 | !test_bit(ICNSS_DRIVER_PROBED, &priv->state)) |
| 4530 | goto out; |
| 4531 | |
| 4532 | ret = priv->ops->pm_suspend(dev); |
| 4533 | |
| 4534 | out: |
| 4535 | if (ret == 0) { |
| 4536 | priv->stats.pm_suspend++; |
| 4537 | set_bit(ICNSS_PM_SUSPEND, &priv->state); |
| 4538 | } else { |
| 4539 | priv->stats.pm_suspend_err++; |
| 4540 | } |
| 4541 | return ret; |
| 4542 | } |
| 4543 | |
| 4544 | static int icnss_pm_resume(struct device *dev) |
| 4545 | { |
| 4546 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 4547 | int ret = 0; |
| 4548 | |
| 4549 | if (priv->magic != ICNSS_MAGIC) { |
| 4550 | icnss_pr_err("Invalid drvdata for pm resume: dev %p, data %p, magic 0x%x\n", |
| 4551 | dev, priv, priv->magic); |
| 4552 | return -EINVAL; |
| 4553 | } |
| 4554 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 4555 | icnss_pr_vdbg("PM resume, state: 0x%lx\n", priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4556 | |
| 4557 | if (!priv->ops || !priv->ops->pm_resume || |
| 4558 | !test_bit(ICNSS_DRIVER_PROBED, &priv->state)) |
| 4559 | goto out; |
| 4560 | |
| 4561 | ret = priv->ops->pm_resume(dev); |
| 4562 | |
| 4563 | out: |
| 4564 | if (ret == 0) { |
| 4565 | priv->stats.pm_resume++; |
| 4566 | clear_bit(ICNSS_PM_SUSPEND, &priv->state); |
| 4567 | } else { |
| 4568 | priv->stats.pm_resume_err++; |
| 4569 | } |
| 4570 | return ret; |
| 4571 | } |
| 4572 | |
| 4573 | static int icnss_pm_suspend_noirq(struct device *dev) |
| 4574 | { |
| 4575 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 4576 | int ret = 0; |
| 4577 | |
| 4578 | if (priv->magic != ICNSS_MAGIC) { |
| 4579 | icnss_pr_err("Invalid drvdata for pm suspend_noirq: dev %p, data %p, magic 0x%x\n", |
| 4580 | dev, priv, priv->magic); |
| 4581 | return -EINVAL; |
| 4582 | } |
| 4583 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 4584 | icnss_pr_vdbg("PM suspend_noirq, state: 0x%lx\n", priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4585 | |
| 4586 | if (!priv->ops || !priv->ops->suspend_noirq || |
| 4587 | !test_bit(ICNSS_DRIVER_PROBED, &priv->state)) |
| 4588 | goto out; |
| 4589 | |
| 4590 | ret = priv->ops->suspend_noirq(dev); |
| 4591 | |
| 4592 | out: |
| 4593 | if (ret == 0) { |
| 4594 | priv->stats.pm_suspend_noirq++; |
| 4595 | set_bit(ICNSS_PM_SUSPEND_NOIRQ, &priv->state); |
| 4596 | } else { |
| 4597 | priv->stats.pm_suspend_noirq_err++; |
| 4598 | } |
| 4599 | return ret; |
| 4600 | } |
| 4601 | |
| 4602 | static int icnss_pm_resume_noirq(struct device *dev) |
| 4603 | { |
| 4604 | struct icnss_priv *priv = dev_get_drvdata(dev); |
| 4605 | int ret = 0; |
| 4606 | |
| 4607 | if (priv->magic != ICNSS_MAGIC) { |
| 4608 | icnss_pr_err("Invalid drvdata for pm resume_noirq: dev %p, data %p, magic 0x%x\n", |
| 4609 | dev, priv, priv->magic); |
| 4610 | return -EINVAL; |
| 4611 | } |
| 4612 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 4613 | icnss_pr_vdbg("PM resume_noirq, state: 0x%lx\n", priv->state); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4614 | |
| 4615 | if (!priv->ops || !priv->ops->resume_noirq || |
| 4616 | !test_bit(ICNSS_DRIVER_PROBED, &priv->state)) |
| 4617 | goto out; |
| 4618 | |
| 4619 | ret = priv->ops->resume_noirq(dev); |
| 4620 | |
| 4621 | out: |
| 4622 | if (ret == 0) { |
| 4623 | priv->stats.pm_resume_noirq++; |
| 4624 | clear_bit(ICNSS_PM_SUSPEND_NOIRQ, &priv->state); |
| 4625 | } else { |
| 4626 | priv->stats.pm_resume_noirq_err++; |
| 4627 | } |
| 4628 | return ret; |
| 4629 | } |
| 4630 | #endif |
| 4631 | |
| 4632 | static const struct dev_pm_ops icnss_pm_ops = { |
| 4633 | SET_SYSTEM_SLEEP_PM_OPS(icnss_pm_suspend, |
| 4634 | icnss_pm_resume) |
| 4635 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(icnss_pm_suspend_noirq, |
| 4636 | icnss_pm_resume_noirq) |
| 4637 | }; |
| 4638 | |
| 4639 | static const struct of_device_id icnss_dt_match[] = { |
| 4640 | {.compatible = "qcom,icnss"}, |
| 4641 | {} |
| 4642 | }; |
| 4643 | |
| 4644 | MODULE_DEVICE_TABLE(of, icnss_dt_match); |
| 4645 | |
| 4646 | static struct platform_driver icnss_driver = { |
| 4647 | .probe = icnss_probe, |
| 4648 | .remove = icnss_remove, |
| 4649 | .driver = { |
| 4650 | .name = "icnss", |
| 4651 | .pm = &icnss_pm_ops, |
| 4652 | .owner = THIS_MODULE, |
| 4653 | .of_match_table = icnss_dt_match, |
| 4654 | }, |
| 4655 | }; |
| 4656 | |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4657 | static int __init icnss_initialize(void) |
| 4658 | { |
| 4659 | icnss_ipc_log_context = ipc_log_context_create(NUM_LOG_PAGES, |
| 4660 | "icnss", 0); |
| 4661 | if (!icnss_ipc_log_context) |
| 4662 | icnss_pr_err("Unable to create log context\n"); |
| 4663 | |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 4664 | icnss_ipc_log_long_context = ipc_log_context_create(NUM_LOG_LONG_PAGES, |
| 4665 | "icnss_long", 0); |
| 4666 | if (!icnss_ipc_log_long_context) |
| 4667 | icnss_pr_err("Unable to create log long context\n"); |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4668 | |
| 4669 | return platform_driver_register(&icnss_driver); |
| 4670 | } |
| 4671 | |
| 4672 | static void __exit icnss_exit(void) |
| 4673 | { |
| 4674 | platform_driver_unregister(&icnss_driver); |
| 4675 | ipc_log_context_destroy(icnss_ipc_log_context); |
| 4676 | icnss_ipc_log_context = NULL; |
Yuanyuan Liu | 6893976 | 2017-04-04 16:43:03 -0700 | [diff] [blame] | 4677 | ipc_log_context_destroy(icnss_ipc_log_long_context); |
| 4678 | icnss_ipc_log_long_context = NULL; |
Yuanyuan Liu | 607051c | 2016-11-28 17:04:13 -0800 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | |
| 4682 | module_init(icnss_initialize); |
| 4683 | module_exit(icnss_exit); |
| 4684 | |
| 4685 | MODULE_LICENSE("GPL v2"); |
| 4686 | MODULE_DESCRIPTION(DEVICE "iCNSS CORE platform driver"); |