Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1 | /* |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 2 | * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved. |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Host WMI unified implementation |
| 30 | */ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 31 | #include "htc_api.h" |
| 32 | #include "htc_api.h" |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 33 | #include "wmi_unified_priv.h" |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 34 | |
Kiran Venkatappa | 23e6e08 | 2016-11-11 16:49:40 +0530 | [diff] [blame] | 35 | #ifndef WMI_NON_TLV_SUPPORT |
| 36 | #include "wmi_tlv_helper.h" |
| 37 | #endif |
| 38 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 39 | #include <linux/debugfs.h> |
| 40 | |
Himanshu Agarwal | 7c83dcd | 2016-07-19 15:41:51 +0530 | [diff] [blame] | 41 | /* This check for CONFIG_WIN temporary added due to redeclaration compilation |
| 42 | error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h |
| 43 | which gets included here through ol_if_athvar.h. Eventually it is expected that |
| 44 | wmi.h will be removed from wmi_unified_api.h after cleanup, which will need |
| 45 | WMI_CMD_HDR to be defined here. */ |
| 46 | #ifdef CONFIG_WIN |
| 47 | /* Copied from wmi.h */ |
| 48 | #undef MS |
| 49 | #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB) |
| 50 | #undef SM |
| 51 | #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK) |
| 52 | #undef WO |
| 53 | #define WO(_f) ((_f##_OFFSET) >> 2) |
| 54 | |
| 55 | #undef GET_FIELD |
| 56 | #define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f) |
| 57 | #undef SET_FIELD |
| 58 | #define SET_FIELD(_addr, _f, _val) \ |
| 59 | (*((A_UINT32 *)(_addr) + WO(_f)) = \ |
| 60 | (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f)) |
| 61 | |
| 62 | #define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \ |
| 63 | GET_FIELD(_msg_buf, _msg_type ## _ ## _f) |
| 64 | |
| 65 | #define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \ |
| 66 | SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val) |
| 67 | |
| 68 | #define WMI_EP_APASS 0x0 |
| 69 | #define WMI_EP_LPASS 0x1 |
| 70 | #define WMI_EP_SENSOR 0x2 |
| 71 | |
| 72 | /* |
| 73 | * * Control Path |
| 74 | * */ |
| 75 | typedef PREPACK struct { |
| 76 | A_UINT32 commandId:24, |
| 77 | reserved:2, /* used for WMI endpoint ID */ |
| 78 | plt_priv:6; /* platform private */ |
| 79 | } POSTPACK WMI_CMD_HDR; /* used for commands and events */ |
| 80 | |
| 81 | #define WMI_CMD_HDR_COMMANDID_LSB 0 |
| 82 | #define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff |
| 83 | #define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000 |
| 84 | #define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000 |
| 85 | #define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24 |
| 86 | #define WMI_CMD_HDR_PLT_PRIV_LSB 24 |
| 87 | #define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000 |
| 88 | #define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000 |
| 89 | /* end of copy wmi.h */ |
| 90 | #endif /* CONFIG_WIN */ |
| 91 | |
Manikandan Mohan | 5826ae9 | 2016-06-08 16:29:39 -0700 | [diff] [blame] | 92 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)) |
| 93 | /* TODO Cleanup this backported function */ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 94 | static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...) |
Manikandan Mohan | 5826ae9 | 2016-06-08 16:29:39 -0700 | [diff] [blame] | 95 | { |
| 96 | va_list args; |
| 97 | |
| 98 | va_start(args, f); |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 99 | seq_vprintf(m, f, args); |
Manikandan Mohan | 5826ae9 | 2016-06-08 16:29:39 -0700 | [diff] [blame] | 100 | va_end(args); |
| 101 | |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 102 | return 0; |
Manikandan Mohan | 5826ae9 | 2016-06-08 16:29:39 -0700 | [diff] [blame] | 103 | } |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 104 | #else |
| 105 | #define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__) |
Manikandan Mohan | 5826ae9 | 2016-06-08 16:29:39 -0700 | [diff] [blame] | 106 | #endif |
| 107 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 108 | #define WMI_MIN_HEAD_ROOM 64 |
| 109 | |
| 110 | #ifdef WMI_INTERFACE_EVENT_LOGGING |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 111 | #ifndef MAX_WMI_INSTANCES |
| 112 | #ifdef CONFIG_MCL |
| 113 | #define MAX_WMI_INSTANCES 1 |
| 114 | #else |
| 115 | #define MAX_WMI_INSTANCES 3 |
| 116 | #endif |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 117 | #define CUSTOM_MGMT_CMD_DATA_SIZE 4 |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 118 | #endif |
| 119 | |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 120 | #ifdef CONFIG_MCL |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 121 | /* WMI commands */ |
| 122 | uint32_t g_wmi_command_buf_idx = 0; |
| 123 | struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY]; |
| 124 | |
| 125 | /* WMI commands TX completed */ |
| 126 | uint32_t g_wmi_command_tx_cmp_buf_idx = 0; |
| 127 | struct wmi_command_debug |
| 128 | wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY]; |
| 129 | |
| 130 | /* WMI events when processed */ |
| 131 | uint32_t g_wmi_event_buf_idx = 0; |
| 132 | struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY]; |
| 133 | |
| 134 | /* WMI events when queued */ |
| 135 | uint32_t g_wmi_rx_event_buf_idx = 0; |
| 136 | struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY]; |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 137 | #endif |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 138 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 139 | #define WMI_COMMAND_RECORD(h, a, b) { \ |
| 140 | if (wmi_log_max_entry <= \ |
| 141 | *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \ |
| 142 | *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\ |
| 143 | ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\ |
| 144 | [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\ |
| 145 | .command = a; \ |
| 146 | qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \ |
| 147 | wmi_command_log_buf_info.buf) \ |
| 148 | [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\ |
| 149 | b, wmi_record_max_length); \ |
| 150 | ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\ |
| 151 | [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\ |
| 152 | time = qdf_get_log_timestamp(); \ |
| 153 | (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \ |
| 154 | h->log_info.wmi_command_log_buf_info.length++; \ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 155 | } |
| 156 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 157 | #define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \ |
| 158 | if (wmi_log_max_entry <= \ |
| 159 | *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\ |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 160 | *(h->log_info.wmi_command_tx_cmp_log_buf_info. \ |
| 161 | p_buf_tail_idx) = 0; \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 162 | ((struct wmi_command_debug *)h->log_info. \ |
| 163 | wmi_command_tx_cmp_log_buf_info.buf) \ |
| 164 | [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \ |
| 165 | p_buf_tail_idx)]. \ |
| 166 | command = a; \ |
| 167 | qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \ |
| 168 | wmi_command_tx_cmp_log_buf_info.buf) \ |
| 169 | [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \ |
| 170 | p_buf_tail_idx)]. \ |
| 171 | data, b, wmi_record_max_length); \ |
| 172 | ((struct wmi_command_debug *)h->log_info. \ |
| 173 | wmi_command_tx_cmp_log_buf_info.buf) \ |
| 174 | [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \ |
| 175 | p_buf_tail_idx)]. \ |
| 176 | time = qdf_get_log_timestamp(); \ |
| 177 | (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\ |
| 178 | h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 179 | } |
| 180 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 181 | #define WMI_EVENT_RECORD(h, a, b) { \ |
| 182 | if (wmi_log_max_entry <= \ |
| 183 | *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \ |
| 184 | *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\ |
| 185 | ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\ |
| 186 | [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \ |
| 187 | event = a; \ |
| 188 | qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \ |
| 189 | wmi_event_log_buf_info.buf) \ |
| 190 | [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\ |
| 191 | wmi_record_max_length); \ |
| 192 | ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\ |
| 193 | [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\ |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 194 | qdf_get_log_timestamp(); \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 195 | (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \ |
| 196 | h->log_info.wmi_event_log_buf_info.length++; \ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 197 | } |
| 198 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 199 | #define WMI_RX_EVENT_RECORD(h, a, b) { \ |
| 200 | if (wmi_log_max_entry <= \ |
| 201 | *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\ |
| 202 | *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\ |
| 203 | ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\ |
| 204 | [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\ |
| 205 | event = a; \ |
| 206 | qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \ |
| 207 | wmi_rx_event_log_buf_info.buf) \ |
| 208 | [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\ |
| 209 | data, b, wmi_record_max_length); \ |
| 210 | ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\ |
| 211 | [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\ |
| 212 | time = qdf_get_log_timestamp(); \ |
| 213 | (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \ |
| 214 | h->log_info.wmi_rx_event_log_buf_info.length++; \ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 215 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 216 | |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 217 | #ifdef CONFIG_MCL |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 218 | uint32_t g_wmi_mgmt_command_buf_idx = 0; |
| 219 | struct |
| 220 | wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY]; |
| 221 | |
| 222 | /* wmi_mgmt commands TX completed */ |
| 223 | uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0; |
| 224 | struct wmi_command_debug |
| 225 | wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY]; |
| 226 | |
| 227 | /* wmi_mgmt events when processed */ |
| 228 | uint32_t g_wmi_mgmt_event_buf_idx = 0; |
| 229 | struct wmi_event_debug |
| 230 | wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY]; |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 231 | #endif |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 232 | |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 233 | #define WMI_MGMT_COMMAND_RECORD(h, a, b) { \ |
| 234 | if (wmi_mgmt_log_max_entry <= \ |
| 235 | *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \ |
| 236 | *(h->log_info.wmi_mgmt_command_log_buf_info. \ |
| 237 | p_buf_tail_idx) = 0; \ |
| 238 | ((struct wmi_command_debug *)h->log_info. \ |
| 239 | wmi_mgmt_command_log_buf_info.buf) \ |
| 240 | [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\ |
| 241 | command = a; \ |
| 242 | qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \ |
| 243 | wmi_mgmt_command_log_buf_info.buf) \ |
| 244 | [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\ |
| 245 | data, b, \ |
| 246 | wmi_record_max_length); \ |
| 247 | ((struct wmi_command_debug *)h->log_info. \ |
| 248 | wmi_mgmt_command_log_buf_info.buf) \ |
| 249 | [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\ |
| 250 | time = qdf_get_log_timestamp(); \ |
| 251 | (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\ |
| 252 | h->log_info.wmi_mgmt_command_log_buf_info.length++; \ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 253 | } |
| 254 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 255 | #define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \ |
| 256 | if (wmi_mgmt_log_max_entry <= \ |
| 257 | *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \ |
| 258 | p_buf_tail_idx)) \ |
| 259 | *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \ |
| 260 | p_buf_tail_idx) = 0; \ |
| 261 | ((struct wmi_command_debug *)h->log_info. \ |
| 262 | wmi_mgmt_command_tx_cmp_log_buf_info.buf) \ |
| 263 | [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \ |
| 264 | p_buf_tail_idx)].command = a; \ |
| 265 | qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \ |
| 266 | wmi_mgmt_command_tx_cmp_log_buf_info.buf)\ |
| 267 | [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \ |
| 268 | p_buf_tail_idx)].data, b, \ |
| 269 | wmi_record_max_length); \ |
| 270 | ((struct wmi_command_debug *)h->log_info. \ |
| 271 | wmi_mgmt_command_tx_cmp_log_buf_info.buf) \ |
| 272 | [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \ |
| 273 | p_buf_tail_idx)].time = \ |
| 274 | qdf_get_log_timestamp(); \ |
| 275 | (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \ |
| 276 | p_buf_tail_idx))++; \ |
| 277 | h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 278 | } |
| 279 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 280 | #define WMI_MGMT_EVENT_RECORD(h, a, b) { \ |
| 281 | if (wmi_mgmt_log_max_entry <= \ |
| 282 | *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\ |
| 283 | *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\ |
| 284 | ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\ |
| 285 | [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\ |
| 286 | .event = a; \ |
| 287 | qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \ |
| 288 | wmi_mgmt_event_log_buf_info.buf) \ |
| 289 | [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\ |
| 290 | data, b, wmi_record_max_length); \ |
| 291 | ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\ |
| 292 | [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\ |
| 293 | time = qdf_get_log_timestamp(); \ |
| 294 | (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \ |
| 295 | h->log_info.wmi_mgmt_event_log_buf_info.length++; \ |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 296 | } |
| 297 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 298 | /* These are defined to made it as module param, which can be configured */ |
| 299 | uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY; |
| 300 | uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY; |
| 301 | uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH; |
| 302 | uint32_t wmi_display_size = 100; |
| 303 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 304 | /** |
| 305 | * wmi_log_init() - Initialize WMI event logging |
| 306 | * @wmi_handle: WMI handle. |
| 307 | * |
| 308 | * Return: Initialization status |
| 309 | */ |
| 310 | #ifdef CONFIG_MCL |
| 311 | static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle) |
| 312 | { |
| 313 | struct wmi_log_buf_t *cmd_log_buf = |
| 314 | &wmi_handle->log_info.wmi_command_log_buf_info; |
| 315 | struct wmi_log_buf_t *cmd_tx_cmpl_log_buf = |
| 316 | &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info; |
| 317 | |
| 318 | struct wmi_log_buf_t *event_log_buf = |
| 319 | &wmi_handle->log_info.wmi_event_log_buf_info; |
| 320 | struct wmi_log_buf_t *rx_event_log_buf = |
| 321 | &wmi_handle->log_info.wmi_rx_event_log_buf_info; |
| 322 | |
| 323 | struct wmi_log_buf_t *mgmt_cmd_log_buf = |
| 324 | &wmi_handle->log_info.wmi_mgmt_command_log_buf_info; |
| 325 | struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf = |
| 326 | &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info; |
| 327 | struct wmi_log_buf_t *mgmt_event_log_buf = |
| 328 | &wmi_handle->log_info.wmi_mgmt_event_log_buf_info; |
| 329 | |
| 330 | /* WMI commands */ |
| 331 | cmd_log_buf->length = 0; |
| 332 | cmd_log_buf->buf_tail_idx = 0; |
| 333 | cmd_log_buf->buf = wmi_command_log_buffer; |
| 334 | cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 335 | cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 336 | |
| 337 | /* WMI commands TX completed */ |
| 338 | cmd_tx_cmpl_log_buf->length = 0; |
| 339 | cmd_tx_cmpl_log_buf->buf_tail_idx = 0; |
| 340 | cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer; |
| 341 | cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 342 | cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 343 | |
| 344 | /* WMI events when processed */ |
| 345 | event_log_buf->length = 0; |
| 346 | event_log_buf->buf_tail_idx = 0; |
| 347 | event_log_buf->buf = wmi_event_log_buffer; |
| 348 | event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 349 | event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 350 | |
| 351 | /* WMI events when queued */ |
| 352 | rx_event_log_buf->length = 0; |
| 353 | rx_event_log_buf->buf_tail_idx = 0; |
| 354 | rx_event_log_buf->buf = wmi_rx_event_log_buffer; |
| 355 | rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 356 | rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 357 | |
| 358 | /* WMI Management commands */ |
| 359 | mgmt_cmd_log_buf->length = 0; |
| 360 | mgmt_cmd_log_buf->buf_tail_idx = 0; |
| 361 | mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer; |
| 362 | mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 363 | mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 364 | |
| 365 | /* WMI Management commands Tx completed*/ |
| 366 | mgmt_cmd_tx_cmp_log_buf->length = 0; |
| 367 | mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0; |
| 368 | mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer; |
| 369 | mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx = |
| 370 | &g_wmi_mgmt_command_tx_cmp_buf_idx; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 371 | mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 372 | |
| 373 | /* WMI Management events when processed*/ |
| 374 | mgmt_event_log_buf->length = 0; |
| 375 | mgmt_event_log_buf->buf_tail_idx = 0; |
| 376 | mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer; |
| 377 | mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 378 | mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 379 | |
| 380 | qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock); |
| 381 | wmi_handle->log_info.wmi_logging_enable = 1; |
| 382 | |
| 383 | return QDF_STATUS_SUCCESS; |
| 384 | } |
| 385 | #else |
| 386 | static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle) |
| 387 | { |
| 388 | struct wmi_log_buf_t *cmd_log_buf = |
| 389 | &wmi_handle->log_info.wmi_command_log_buf_info; |
| 390 | struct wmi_log_buf_t *cmd_tx_cmpl_log_buf = |
| 391 | &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info; |
| 392 | |
| 393 | struct wmi_log_buf_t *event_log_buf = |
| 394 | &wmi_handle->log_info.wmi_event_log_buf_info; |
| 395 | struct wmi_log_buf_t *rx_event_log_buf = |
| 396 | &wmi_handle->log_info.wmi_rx_event_log_buf_info; |
| 397 | |
| 398 | struct wmi_log_buf_t *mgmt_cmd_log_buf = |
| 399 | &wmi_handle->log_info.wmi_mgmt_command_log_buf_info; |
| 400 | struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf = |
| 401 | &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info; |
| 402 | struct wmi_log_buf_t *mgmt_event_log_buf = |
| 403 | &wmi_handle->log_info.wmi_mgmt_event_log_buf_info; |
| 404 | |
| 405 | wmi_handle->log_info.wmi_logging_enable = 0; |
| 406 | |
| 407 | /* WMI commands */ |
| 408 | cmd_log_buf->length = 0; |
| 409 | cmd_log_buf->buf_tail_idx = 0; |
| 410 | cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc( |
| 411 | wmi_log_max_entry * sizeof(struct wmi_command_debug)); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 412 | cmd_log_buf->size = wmi_log_max_entry; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 413 | |
| 414 | if (!cmd_log_buf->buf) { |
| 415 | qdf_print("no memory for WMI command log buffer..\n"); |
| 416 | return QDF_STATUS_E_NOMEM; |
| 417 | } |
| 418 | cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx; |
| 419 | |
| 420 | /* WMI commands TX completed */ |
| 421 | cmd_tx_cmpl_log_buf->length = 0; |
| 422 | cmd_tx_cmpl_log_buf->buf_tail_idx = 0; |
| 423 | cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc( |
| 424 | wmi_log_max_entry * sizeof(struct wmi_command_debug)); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 425 | cmd_tx_cmpl_log_buf->size = wmi_log_max_entry; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 426 | |
| 427 | if (!cmd_tx_cmpl_log_buf->buf) { |
| 428 | qdf_print("no memory for WMI Command Tx Complete log buffer..\n"); |
| 429 | return QDF_STATUS_E_NOMEM; |
| 430 | } |
| 431 | cmd_tx_cmpl_log_buf->p_buf_tail_idx = |
| 432 | &cmd_tx_cmpl_log_buf->buf_tail_idx; |
| 433 | |
| 434 | /* WMI events when processed */ |
| 435 | event_log_buf->length = 0; |
| 436 | event_log_buf->buf_tail_idx = 0; |
| 437 | event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc( |
| 438 | wmi_log_max_entry * sizeof(struct wmi_event_debug)); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 439 | event_log_buf->size = wmi_log_max_entry; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 440 | |
| 441 | if (!event_log_buf->buf) { |
| 442 | qdf_print("no memory for WMI Event log buffer..\n"); |
| 443 | return QDF_STATUS_E_NOMEM; |
| 444 | } |
| 445 | event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx; |
| 446 | |
| 447 | /* WMI events when queued */ |
| 448 | rx_event_log_buf->length = 0; |
| 449 | rx_event_log_buf->buf_tail_idx = 0; |
| 450 | rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc( |
| 451 | wmi_log_max_entry * sizeof(struct wmi_event_debug)); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 452 | rx_event_log_buf->size = wmi_log_max_entry; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 453 | |
| 454 | if (!rx_event_log_buf->buf) { |
| 455 | qdf_print("no memory for WMI Event Rx log buffer..\n"); |
| 456 | return QDF_STATUS_E_NOMEM; |
| 457 | } |
| 458 | rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx; |
| 459 | |
| 460 | /* WMI Management commands */ |
| 461 | mgmt_cmd_log_buf->length = 0; |
| 462 | mgmt_cmd_log_buf->buf_tail_idx = 0; |
| 463 | mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc( |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 464 | wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug)); |
| 465 | mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 466 | |
| 467 | if (!mgmt_cmd_log_buf->buf) { |
| 468 | qdf_print("no memory for WMI Management Command log buffer..\n"); |
| 469 | return QDF_STATUS_E_NOMEM; |
| 470 | } |
| 471 | mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx; |
| 472 | |
| 473 | /* WMI Management commands Tx completed*/ |
| 474 | mgmt_cmd_tx_cmp_log_buf->length = 0; |
| 475 | mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0; |
| 476 | mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *) |
| 477 | qdf_mem_malloc( |
| 478 | wmi_mgmt_log_max_entry * |
| 479 | sizeof(struct wmi_command_debug)); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 480 | mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 481 | |
| 482 | if (!mgmt_cmd_tx_cmp_log_buf->buf) { |
| 483 | qdf_print("no memory for WMI Management Command Tx complete log buffer..\n"); |
| 484 | return QDF_STATUS_E_NOMEM; |
| 485 | } |
| 486 | mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx = |
| 487 | &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx; |
| 488 | |
| 489 | /* WMI Management events when processed*/ |
| 490 | mgmt_event_log_buf->length = 0; |
| 491 | mgmt_event_log_buf->buf_tail_idx = 0; |
| 492 | |
| 493 | mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc( |
| 494 | wmi_mgmt_log_max_entry * |
| 495 | sizeof(struct wmi_event_debug)); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 496 | mgmt_event_log_buf->size = wmi_mgmt_log_max_entry; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 497 | |
| 498 | if (!mgmt_event_log_buf->buf) { |
| 499 | qdf_print("no memory for WMI Management Event log buffer..\n"); |
| 500 | return QDF_STATUS_E_NOMEM; |
| 501 | } |
| 502 | mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx; |
| 503 | |
| 504 | qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock); |
| 505 | wmi_handle->log_info.wmi_logging_enable = 1; |
| 506 | |
| 507 | return QDF_STATUS_SUCCESS; |
| 508 | } |
| 509 | #endif |
| 510 | |
| 511 | /** |
| 512 | * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for |
| 513 | * event logging |
| 514 | * @wmi_handle: WMI handle. |
| 515 | * |
| 516 | * Return: None |
| 517 | */ |
| 518 | #ifndef CONFIG_MCL |
| 519 | static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) |
| 520 | { |
| 521 | if (wmi_handle->log_info.wmi_command_log_buf_info.buf) |
| 522 | qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf); |
| 523 | if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf) |
| 524 | qdf_mem_free( |
| 525 | wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf); |
| 526 | if (wmi_handle->log_info.wmi_event_log_buf_info.buf) |
| 527 | qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf); |
| 528 | if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf) |
| 529 | qdf_mem_free( |
| 530 | wmi_handle->log_info.wmi_rx_event_log_buf_info.buf); |
| 531 | if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf) |
| 532 | qdf_mem_free( |
| 533 | wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf); |
| 534 | if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf) |
| 535 | qdf_mem_free( |
| 536 | wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf); |
| 537 | if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf) |
| 538 | qdf_mem_free( |
| 539 | wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf); |
| 540 | wmi_handle->log_info.wmi_logging_enable = 0; |
| 541 | qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock); |
| 542 | } |
| 543 | #else |
| 544 | static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) |
| 545 | { |
| 546 | /* Do Nothing */ |
| 547 | } |
| 548 | #endif |
| 549 | |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 550 | /** |
| 551 | * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer |
| 552 | * @log_buffer: the command log buffer metadata of the buffer to print |
| 553 | * @count: the maximum number of entries to print |
| 554 | * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper |
| 555 | * @print_priv: any data required by the print method, e.g. a file handle |
| 556 | * |
| 557 | * Return: None |
| 558 | */ |
| 559 | static void |
| 560 | wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count, |
| 561 | qdf_abstract_print *print, void *print_priv) |
| 562 | { |
| 563 | static const int data_len = |
| 564 | WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t); |
| 565 | char str[128]; |
| 566 | uint32_t idx; |
| 567 | |
| 568 | if (count > log_buffer->size) |
| 569 | count = log_buffer->size; |
| 570 | if (count > log_buffer->length) |
| 571 | count = log_buffer->length; |
| 572 | |
| 573 | /* subtract count from index, and wrap if necessary */ |
| 574 | idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count; |
| 575 | idx %= log_buffer->size; |
| 576 | |
| 577 | print(print_priv, "Time (seconds) Cmd Id Payload"); |
| 578 | while (count) { |
| 579 | struct wmi_command_debug *cmd_log = (struct wmi_command_debug *) |
| 580 | &((struct wmi_command_debug *)log_buffer->buf)[idx]; |
Dustin Brown | 8ea3912 | 2017-04-10 13:26:56 -0700 | [diff] [blame] | 581 | uint64_t secs, usecs; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 582 | int len = 0; |
| 583 | int i; |
| 584 | |
Dustin Brown | 8ea3912 | 2017-04-10 13:26:56 -0700 | [diff] [blame] | 585 | qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 586 | len += scnprintf(str + len, sizeof(str) - len, |
| 587 | "% 8lld.%06lld %6u (0x%06x) ", |
Dustin Brown | 8ea3912 | 2017-04-10 13:26:56 -0700 | [diff] [blame] | 588 | secs, usecs, |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 589 | cmd_log->command, cmd_log->command); |
| 590 | for (i = 0; i < data_len; ++i) { |
| 591 | len += scnprintf(str + len, sizeof(str) - len, |
| 592 | "0x%08x ", cmd_log->data[i]); |
| 593 | } |
| 594 | |
| 595 | print(print_priv, str); |
| 596 | |
| 597 | --count; |
| 598 | ++idx; |
| 599 | if (idx >= log_buffer->size) |
| 600 | idx = 0; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * wmi_print_event_log_buffer() - an output agnostic wmi event log printer |
| 606 | * @log_buffer: the event log buffer metadata of the buffer to print |
| 607 | * @count: the maximum number of entries to print |
| 608 | * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper |
| 609 | * @print_priv: any data required by the print method, e.g. a file handle |
| 610 | * |
| 611 | * Return: None |
| 612 | */ |
| 613 | static void |
| 614 | wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count, |
| 615 | qdf_abstract_print *print, void *print_priv) |
| 616 | { |
| 617 | static const int data_len = |
| 618 | WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t); |
| 619 | char str[128]; |
| 620 | uint32_t idx; |
| 621 | |
| 622 | if (count > log_buffer->size) |
| 623 | count = log_buffer->size; |
| 624 | if (count > log_buffer->length) |
| 625 | count = log_buffer->length; |
| 626 | |
| 627 | /* subtract count from index, and wrap if necessary */ |
| 628 | idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count; |
| 629 | idx %= log_buffer->size; |
| 630 | |
| 631 | print(print_priv, "Time (seconds) Event Id Payload"); |
| 632 | while (count) { |
| 633 | struct wmi_event_debug *event_log = (struct wmi_event_debug *) |
| 634 | &((struct wmi_event_debug *)log_buffer->buf)[idx]; |
Dustin Brown | 8ea3912 | 2017-04-10 13:26:56 -0700 | [diff] [blame] | 635 | uint64_t secs, usecs; |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 636 | int len = 0; |
| 637 | int i; |
| 638 | |
Dustin Brown | 8ea3912 | 2017-04-10 13:26:56 -0700 | [diff] [blame] | 639 | qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs); |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 640 | len += scnprintf(str + len, sizeof(str) - len, |
| 641 | "% 8lld.%06lld %6u (0x%06x) ", |
Dustin Brown | 8ea3912 | 2017-04-10 13:26:56 -0700 | [diff] [blame] | 642 | secs, usecs, |
Dustin Brown | f24bf9b | 2017-04-03 17:00:07 -0700 | [diff] [blame] | 643 | event_log->event, event_log->event); |
| 644 | for (i = 0; i < data_len; ++i) { |
| 645 | len += scnprintf(str + len, sizeof(str) - len, |
| 646 | "0x%08x ", event_log->data[i]); |
| 647 | } |
| 648 | |
| 649 | print(print_priv, str); |
| 650 | |
| 651 | --count; |
| 652 | ++idx; |
| 653 | if (idx >= log_buffer->size) |
| 654 | idx = 0; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | inline void |
| 659 | wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count, |
| 660 | qdf_abstract_print *print, void *print_priv) |
| 661 | { |
| 662 | wmi_print_cmd_log_buffer( |
| 663 | &wmi->log_info.wmi_command_log_buf_info, |
| 664 | count, print, print_priv); |
| 665 | } |
| 666 | |
| 667 | inline void |
| 668 | wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count, |
| 669 | qdf_abstract_print *print, void *print_priv) |
| 670 | { |
| 671 | wmi_print_cmd_log_buffer( |
| 672 | &wmi->log_info.wmi_command_tx_cmp_log_buf_info, |
| 673 | count, print, print_priv); |
| 674 | } |
| 675 | |
| 676 | inline void |
| 677 | wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count, |
| 678 | qdf_abstract_print *print, void *print_priv) |
| 679 | { |
| 680 | wmi_print_cmd_log_buffer( |
| 681 | &wmi->log_info.wmi_mgmt_command_log_buf_info, |
| 682 | count, print, print_priv); |
| 683 | } |
| 684 | |
| 685 | inline void |
| 686 | wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count, |
| 687 | qdf_abstract_print *print, void *print_priv) |
| 688 | { |
| 689 | wmi_print_cmd_log_buffer( |
| 690 | &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info, |
| 691 | count, print, print_priv); |
| 692 | } |
| 693 | |
| 694 | inline void |
| 695 | wmi_print_event_log(wmi_unified_t wmi, uint32_t count, |
| 696 | qdf_abstract_print *print, void *print_priv) |
| 697 | { |
| 698 | wmi_print_event_log_buffer( |
| 699 | &wmi->log_info.wmi_event_log_buf_info, |
| 700 | count, print, print_priv); |
| 701 | } |
| 702 | |
| 703 | inline void |
| 704 | wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count, |
| 705 | qdf_abstract_print *print, void *print_priv) |
| 706 | { |
| 707 | wmi_print_event_log_buffer( |
| 708 | &wmi->log_info.wmi_rx_event_log_buf_info, |
| 709 | count, print, print_priv); |
| 710 | } |
| 711 | |
| 712 | inline void |
| 713 | wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count, |
| 714 | qdf_abstract_print *print, void *print_priv) |
| 715 | { |
| 716 | wmi_print_event_log_buffer( |
| 717 | &wmi->log_info.wmi_mgmt_event_log_buf_info, |
| 718 | count, print, print_priv); |
| 719 | } |
| 720 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 721 | #ifdef CONFIG_MCL |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 722 | const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"}; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 723 | #else |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 724 | const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"}; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 725 | #endif |
| 726 | |
| 727 | /* debugfs routines*/ |
| 728 | |
| 729 | /** |
| 730 | * debug_wmi_##func_base##_show() - debugfs functions to display content of |
| 731 | * command and event buffers. Macro uses max buffer length to display |
| 732 | * buffer when it is wraparound. |
| 733 | * |
| 734 | * @m: debugfs handler to access wmi_handle |
| 735 | * @v: Variable arguments (not used) |
| 736 | * |
| 737 | * Return: Length of characters printed |
| 738 | */ |
| 739 | #define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \ |
| 740 | static int debug_wmi_##func_base##_show(struct seq_file *m, \ |
| 741 | void *v) \ |
| 742 | { \ |
| 743 | wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \ |
| 744 | struct wmi_log_buf_t *wmi_log = \ |
| 745 | &wmi_handle->log_info.wmi_##func_base##_buf_info;\ |
| 746 | int pos, nread, outlen; \ |
| 747 | int i; \ |
nobelj | 2a6da6f | 2017-12-11 23:18:27 -0800 | [diff] [blame] | 748 | uint64_t secs, usecs; \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 749 | \ |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 750 | qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \ |
| 751 | if (!wmi_log->length) { \ |
| 752 | qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 753 | return wmi_bp_seq_printf(m, \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 754 | "no elements to read from ring buffer!\n"); \ |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 755 | } \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 756 | \ |
| 757 | if (wmi_log->length <= wmi_ring_size) \ |
| 758 | nread = wmi_log->length; \ |
| 759 | else \ |
| 760 | nread = wmi_ring_size; \ |
| 761 | \ |
| 762 | if (*(wmi_log->p_buf_tail_idx) == 0) \ |
| 763 | /* tail can be 0 after wrap-around */ \ |
| 764 | pos = wmi_ring_size - 1; \ |
| 765 | else \ |
| 766 | pos = *(wmi_log->p_buf_tail_idx) - 1; \ |
| 767 | \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 768 | outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\ |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 769 | qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 770 | while (nread--) { \ |
| 771 | struct wmi_command_debug *wmi_record; \ |
| 772 | \ |
| 773 | wmi_record = (struct wmi_command_debug *) \ |
| 774 | &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 775 | outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 776 | (wmi_record->command)); \ |
nobelj | 2a6da6f | 2017-12-11 23:18:27 -0800 | [diff] [blame] | 777 | qdf_log_timestamp_to_secs(wmi_record->time, &secs,\ |
| 778 | &usecs); \ |
| 779 | outlen += \ |
| 780 | wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\ |
| 781 | secs, usecs); \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 782 | outlen += wmi_bp_seq_printf(m, "CMD = "); \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 783 | for (i = 0; i < (wmi_record_max_length/ \ |
| 784 | sizeof(uint32_t)); i++) \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 785 | outlen += wmi_bp_seq_printf(m, "%x ", \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 786 | wmi_record->data[i]); \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 787 | outlen += wmi_bp_seq_printf(m, "\n"); \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 788 | \ |
| 789 | if (pos == 0) \ |
| 790 | pos = wmi_ring_size - 1; \ |
| 791 | else \ |
| 792 | pos--; \ |
| 793 | } \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 794 | return outlen; \ |
| 795 | } \ |
| 796 | |
| 797 | #define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \ |
| 798 | static int debug_wmi_##func_base##_show(struct seq_file *m, \ |
| 799 | void *v) \ |
| 800 | { \ |
| 801 | wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \ |
| 802 | struct wmi_log_buf_t *wmi_log = \ |
| 803 | &wmi_handle->log_info.wmi_##func_base##_buf_info;\ |
| 804 | int pos, nread, outlen; \ |
| 805 | int i; \ |
nobelj | 2a6da6f | 2017-12-11 23:18:27 -0800 | [diff] [blame] | 806 | uint64_t secs, usecs; \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 807 | \ |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 808 | qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \ |
| 809 | if (!wmi_log->length) { \ |
| 810 | qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 811 | return wmi_bp_seq_printf(m, \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 812 | "no elements to read from ring buffer!\n"); \ |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 813 | } \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 814 | \ |
| 815 | if (wmi_log->length <= wmi_ring_size) \ |
| 816 | nread = wmi_log->length; \ |
| 817 | else \ |
| 818 | nread = wmi_ring_size; \ |
| 819 | \ |
| 820 | if (*(wmi_log->p_buf_tail_idx) == 0) \ |
| 821 | /* tail can be 0 after wrap-around */ \ |
| 822 | pos = wmi_ring_size - 1; \ |
| 823 | else \ |
| 824 | pos = *(wmi_log->p_buf_tail_idx) - 1; \ |
| 825 | \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 826 | outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\ |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 827 | qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 828 | while (nread--) { \ |
| 829 | struct wmi_event_debug *wmi_record; \ |
| 830 | \ |
| 831 | wmi_record = (struct wmi_event_debug *) \ |
| 832 | &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\ |
nobelj | 2a6da6f | 2017-12-11 23:18:27 -0800 | [diff] [blame] | 833 | qdf_log_timestamp_to_secs(wmi_record->time, &secs,\ |
| 834 | &usecs); \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 835 | outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 836 | (wmi_record->event)); \ |
nobelj | 2a6da6f | 2017-12-11 23:18:27 -0800 | [diff] [blame] | 837 | outlen += \ |
| 838 | wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\ |
| 839 | secs, usecs); \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 840 | outlen += wmi_bp_seq_printf(m, "CMD = "); \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 841 | for (i = 0; i < (wmi_record_max_length/ \ |
| 842 | sizeof(uint32_t)); i++) \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 843 | outlen += wmi_bp_seq_printf(m, "%x ", \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 844 | wmi_record->data[i]); \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 845 | outlen += wmi_bp_seq_printf(m, "\n"); \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 846 | \ |
| 847 | if (pos == 0) \ |
| 848 | pos = wmi_ring_size - 1; \ |
| 849 | else \ |
| 850 | pos--; \ |
| 851 | } \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 852 | return outlen; \ |
| 853 | } |
| 854 | |
| 855 | GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size); |
| 856 | GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size); |
| 857 | GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size); |
| 858 | GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size); |
| 859 | GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size); |
| 860 | GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log, |
| 861 | wmi_display_size); |
| 862 | GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size); |
| 863 | |
| 864 | /** |
| 865 | * debug_wmi_enable_show() - debugfs functions to display enable state of |
| 866 | * wmi logging feature. |
| 867 | * |
| 868 | * @m: debugfs handler to access wmi_handle |
| 869 | * @v: Variable arguments (not used) |
| 870 | * |
| 871 | * Return: always 1 |
| 872 | */ |
| 873 | static int debug_wmi_enable_show(struct seq_file *m, void *v) |
| 874 | { |
| 875 | wmi_unified_t wmi_handle = (wmi_unified_t) m->private; |
| 876 | |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 877 | return wmi_bp_seq_printf(m, "%d\n", |
| 878 | wmi_handle->log_info.wmi_logging_enable); |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /** |
| 882 | * debug_wmi_log_size_show() - debugfs functions to display configured size of |
| 883 | * wmi logging command/event buffer and management command/event buffer. |
| 884 | * |
| 885 | * @m: debugfs handler to access wmi_handle |
| 886 | * @v: Variable arguments (not used) |
| 887 | * |
| 888 | * Return: Length of characters printed |
| 889 | */ |
| 890 | static int debug_wmi_log_size_show(struct seq_file *m, void *v) |
| 891 | { |
| 892 | |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 893 | wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n", |
| 894 | wmi_log_max_entry); |
| 895 | return wmi_bp_seq_printf(m, |
| 896 | "WMI management command/events log max size:%d\n", |
| 897 | wmi_mgmt_log_max_entry); |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | /** |
| 901 | * debug_wmi_##func_base##_write() - debugfs functions to clear |
| 902 | * wmi logging command/event buffer and management command/event buffer. |
| 903 | * |
| 904 | * @file: file handler to access wmi_handle |
| 905 | * @buf: received data buffer |
| 906 | * @count: length of received buffer |
| 907 | * @ppos: Not used |
| 908 | * |
| 909 | * Return: count |
| 910 | */ |
| 911 | #define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\ |
| 912 | static ssize_t debug_wmi_##func_base##_write(struct file *file, \ |
| 913 | const char __user *buf, \ |
| 914 | size_t count, loff_t *ppos) \ |
| 915 | { \ |
| 916 | int k, ret; \ |
Pratik Gandhi | dad75ff | 2017-01-16 12:50:27 +0530 | [diff] [blame] | 917 | wmi_unified_t wmi_handle = \ |
| 918 | ((struct seq_file *)file->private_data)->private;\ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 919 | struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \ |
| 920 | wmi_##func_base##_buf_info; \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 921 | char locbuf[50]; \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 922 | \ |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 923 | if ((!buf) || (count > 50)) \ |
| 924 | return -EFAULT; \ |
| 925 | \ |
| 926 | if (copy_from_user(locbuf, buf, count)) \ |
| 927 | return -EFAULT; \ |
| 928 | \ |
| 929 | ret = sscanf(locbuf, "%d", &k); \ |
| 930 | if ((ret != 1) || (k != 0)) { \ |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 931 | qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\ |
| 932 | return -EINVAL; \ |
| 933 | } \ |
| 934 | \ |
| 935 | qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \ |
| 936 | qdf_mem_zero(wmi_log->buf, wmi_ring_size * \ |
| 937 | sizeof(struct wmi_record_type)); \ |
| 938 | wmi_log->length = 0; \ |
| 939 | *(wmi_log->p_buf_tail_idx) = 0; \ |
| 940 | qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \ |
| 941 | \ |
| 942 | return count; \ |
| 943 | } |
| 944 | |
| 945 | GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry, |
| 946 | wmi_command_debug); |
| 947 | GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry, |
| 948 | wmi_command_debug); |
| 949 | GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry, |
| 950 | wmi_event_debug); |
| 951 | GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry, |
| 952 | wmi_event_debug); |
| 953 | GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry, |
| 954 | wmi_command_debug); |
| 955 | GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log, |
| 956 | wmi_mgmt_log_max_entry, wmi_command_debug); |
| 957 | GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry, |
| 958 | wmi_event_debug); |
| 959 | |
| 960 | /** |
| 961 | * debug_wmi_enable_write() - debugfs functions to enable/disable |
| 962 | * wmi logging feature. |
| 963 | * |
| 964 | * @file: file handler to access wmi_handle |
| 965 | * @buf: received data buffer |
| 966 | * @count: length of received buffer |
| 967 | * @ppos: Not used |
| 968 | * |
| 969 | * Return: count |
| 970 | */ |
| 971 | static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf, |
| 972 | size_t count, loff_t *ppos) |
| 973 | { |
Pratik Gandhi | dad75ff | 2017-01-16 12:50:27 +0530 | [diff] [blame] | 974 | wmi_unified_t wmi_handle = |
| 975 | ((struct seq_file *)file->private_data)->private; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 976 | int k, ret; |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 977 | char locbuf[50]; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 978 | |
Pratik Gandhi | 795ab91 | 2017-05-03 20:15:50 +0530 | [diff] [blame] | 979 | if ((!buf) || (count > 50)) |
| 980 | return -EFAULT; |
| 981 | |
| 982 | if (copy_from_user(locbuf, buf, count)) |
| 983 | return -EFAULT; |
| 984 | |
| 985 | ret = sscanf(locbuf, "%d", &k); |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 986 | if ((ret != 1) || ((k != 0) && (k != 1))) |
| 987 | return -EINVAL; |
| 988 | |
| 989 | wmi_handle->log_info.wmi_logging_enable = k; |
| 990 | return count; |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * debug_wmi_log_size_write() - reserved. |
| 995 | * |
| 996 | * @file: file handler to access wmi_handle |
| 997 | * @buf: received data buffer |
| 998 | * @count: length of received buffer |
| 999 | * @ppos: Not used |
| 1000 | * |
| 1001 | * Return: count |
| 1002 | */ |
| 1003 | static ssize_t debug_wmi_log_size_write(struct file *file, |
| 1004 | const char __user *buf, size_t count, loff_t *ppos) |
| 1005 | { |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | |
| 1009 | /* Structure to maintain debug information */ |
| 1010 | struct wmi_debugfs_info { |
| 1011 | const char *name; |
| 1012 | struct dentry *de[MAX_WMI_INSTANCES]; |
| 1013 | const struct file_operations *ops; |
| 1014 | }; |
| 1015 | |
| 1016 | #define DEBUG_FOO(func_base) { .name = #func_base, \ |
| 1017 | .ops = &debug_##func_base##_ops } |
| 1018 | |
| 1019 | /** |
| 1020 | * debug_##func_base##_open() - Open debugfs entry for respective command |
| 1021 | * and event buffer. |
| 1022 | * |
| 1023 | * @inode: node for debug dir entry |
| 1024 | * @file: file handler |
| 1025 | * |
| 1026 | * Return: open status |
| 1027 | */ |
| 1028 | #define GENERATE_DEBUG_STRUCTS(func_base) \ |
| 1029 | static int debug_##func_base##_open(struct inode *inode, \ |
| 1030 | struct file *file) \ |
| 1031 | { \ |
| 1032 | return single_open(file, debug_##func_base##_show, \ |
| 1033 | inode->i_private); \ |
| 1034 | } \ |
| 1035 | \ |
| 1036 | \ |
| 1037 | static struct file_operations debug_##func_base##_ops = { \ |
| 1038 | .open = debug_##func_base##_open, \ |
| 1039 | .read = seq_read, \ |
| 1040 | .llseek = seq_lseek, \ |
| 1041 | .write = debug_##func_base##_write, \ |
| 1042 | .release = single_release, \ |
| 1043 | }; |
| 1044 | |
| 1045 | GENERATE_DEBUG_STRUCTS(wmi_command_log); |
| 1046 | GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log); |
| 1047 | GENERATE_DEBUG_STRUCTS(wmi_event_log); |
| 1048 | GENERATE_DEBUG_STRUCTS(wmi_rx_event_log); |
| 1049 | GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log); |
| 1050 | GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log); |
| 1051 | GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log); |
| 1052 | GENERATE_DEBUG_STRUCTS(wmi_enable); |
| 1053 | GENERATE_DEBUG_STRUCTS(wmi_log_size); |
| 1054 | |
| 1055 | struct wmi_debugfs_info wmi_debugfs_infos[] = { |
| 1056 | DEBUG_FOO(wmi_command_log), |
| 1057 | DEBUG_FOO(wmi_command_tx_cmp_log), |
| 1058 | DEBUG_FOO(wmi_event_log), |
| 1059 | DEBUG_FOO(wmi_rx_event_log), |
| 1060 | DEBUG_FOO(wmi_mgmt_command_log), |
| 1061 | DEBUG_FOO(wmi_mgmt_command_tx_cmp_log), |
| 1062 | DEBUG_FOO(wmi_mgmt_event_log), |
| 1063 | DEBUG_FOO(wmi_enable), |
| 1064 | DEBUG_FOO(wmi_log_size), |
| 1065 | }; |
| 1066 | |
| 1067 | #define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \ |
| 1068 | sizeof(wmi_debugfs_infos[0])) |
| 1069 | |
| 1070 | /** |
| 1071 | * wmi_debugfs_create() - Create debug_fs entry for wmi logging. |
| 1072 | * |
| 1073 | * @wmi_handle: wmi handle |
| 1074 | * @par_entry: debug directory entry |
| 1075 | * @id: Index to debug info data array |
| 1076 | * |
| 1077 | * Return: none |
| 1078 | */ |
| 1079 | static void wmi_debugfs_create(wmi_unified_t wmi_handle, |
| 1080 | struct dentry *par_entry, int id) |
| 1081 | { |
| 1082 | int i; |
| 1083 | |
| 1084 | if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES)) |
| 1085 | goto out; |
| 1086 | |
| 1087 | for (i = 0; i < NUM_DEBUG_INFOS; ++i) { |
| 1088 | |
| 1089 | wmi_debugfs_infos[i].de[id] = debugfs_create_file( |
| 1090 | wmi_debugfs_infos[i].name, 0644, par_entry, |
| 1091 | wmi_handle, wmi_debugfs_infos[i].ops); |
| 1092 | |
| 1093 | if (wmi_debugfs_infos[i].de[id] == NULL) { |
| 1094 | qdf_print("%s: debug Entry creation failed!\n", |
| 1095 | __func__); |
| 1096 | goto out; |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | return; |
| 1101 | |
| 1102 | out: |
| 1103 | qdf_print("%s: debug Entry creation failed!\n", __func__); |
| 1104 | wmi_log_buffer_free(wmi_handle); |
| 1105 | return; |
| 1106 | } |
| 1107 | |
| 1108 | /** |
| 1109 | * wmi_debugfs_remove() - Remove debugfs entry for wmi logging. |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1110 | * @wmi_handle: wmi handle |
| 1111 | * @dentry: debugfs directory entry |
| 1112 | * @id: Index to debug info data array |
| 1113 | * |
| 1114 | * Return: none |
| 1115 | */ |
Govind Singh | 06c1839 | 2016-06-10 10:33:19 +0530 | [diff] [blame] | 1116 | static void wmi_debugfs_remove(wmi_unified_t wmi_handle) |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1117 | { |
| 1118 | int i; |
Govind Singh | 06c1839 | 2016-06-10 10:33:19 +0530 | [diff] [blame] | 1119 | struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir; |
Rakesh Pillai | 24c7f8a | 2017-12-26 19:02:35 +0530 | [diff] [blame] | 1120 | int id; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1121 | |
Rakesh Pillai | 24c7f8a | 2017-12-26 19:02:35 +0530 | [diff] [blame] | 1122 | if (!wmi_handle->log_info.wmi_instance_id) |
| 1123 | return; |
| 1124 | |
| 1125 | id = wmi_handle->log_info.wmi_instance_id - 1; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1126 | if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) { |
| 1127 | for (i = 0; i < NUM_DEBUG_INFOS; ++i) { |
| 1128 | if (wmi_debugfs_infos[i].de[id]) |
| 1129 | wmi_debugfs_infos[i].de[id] = NULL; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | if (dentry) |
| 1134 | debugfs_remove_recursive(dentry); |
Rakesh Pillai | 24c7f8a | 2017-12-26 19:02:35 +0530 | [diff] [blame] | 1135 | |
| 1136 | if (wmi_handle->log_info.wmi_instance_id) |
| 1137 | wmi_handle->log_info.wmi_instance_id--; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * wmi_debugfs_init() - debugfs functions to create debugfs directory and to |
| 1142 | * create debugfs enteries. |
| 1143 | * |
| 1144 | * @h: wmi handler |
| 1145 | * |
| 1146 | * Return: init status |
| 1147 | */ |
| 1148 | static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle) |
| 1149 | { |
Rakesh Pillai | 24c7f8a | 2017-12-26 19:02:35 +0530 | [diff] [blame] | 1150 | int wmi_index = wmi_handle->log_info.wmi_instance_id; |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1151 | |
Rakesh Pillai | 24c7f8a | 2017-12-26 19:02:35 +0530 | [diff] [blame] | 1152 | if (wmi_index < MAX_WMI_INSTANCES) { |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1153 | wmi_handle->log_info.wmi_log_debugfs_dir = |
| 1154 | debugfs_create_dir(debugfs_dir[wmi_index], NULL); |
| 1155 | |
Rakesh Pillai | 24c7f8a | 2017-12-26 19:02:35 +0530 | [diff] [blame] | 1156 | if (!wmi_handle->log_info.wmi_log_debugfs_dir) { |
| 1157 | qdf_print("error while creating debugfs dir for %s\n", |
| 1158 | debugfs_dir[wmi_index]); |
| 1159 | return QDF_STATUS_E_FAILURE; |
| 1160 | } |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1161 | |
Rakesh Pillai | 24c7f8a | 2017-12-26 19:02:35 +0530 | [diff] [blame] | 1162 | wmi_debugfs_create(wmi_handle, |
| 1163 | wmi_handle->log_info.wmi_log_debugfs_dir, |
| 1164 | wmi_index); |
| 1165 | wmi_handle->log_info.wmi_instance_id++; |
| 1166 | } |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1167 | |
| 1168 | return QDF_STATUS_SUCCESS; |
| 1169 | } |
Sandeep Puligilla | b74958d | 2016-06-13 15:42:55 -0700 | [diff] [blame] | 1170 | |
| 1171 | /** |
| 1172 | * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro |
| 1173 | * |
| 1174 | * @wmi_handle: wmi handle |
| 1175 | * @cmd: mgmt command |
Sandeep Puligilla | 828a45f | 2016-07-19 13:20:57 -0700 | [diff] [blame] | 1176 | * @header: pointer to 802.11 header |
Sandeep Puligilla | b74958d | 2016-06-13 15:42:55 -0700 | [diff] [blame] | 1177 | * @vdev_id: vdev id |
| 1178 | * @chanfreq: channel frequency |
| 1179 | * |
| 1180 | * Return: none |
| 1181 | */ |
Himanshu Agarwal | 7c83dcd | 2016-07-19 15:41:51 +0530 | [diff] [blame] | 1182 | void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd, |
Sandeep Puligilla | 828a45f | 2016-07-19 13:20:57 -0700 | [diff] [blame] | 1183 | void *header, uint32_t vdev_id, uint32_t chanfreq) |
Sandeep Puligilla | b74958d | 2016-06-13 15:42:55 -0700 | [diff] [blame] | 1184 | { |
Pratik Gandhi | 29e33f0 | 2016-09-16 01:32:51 +0530 | [diff] [blame] | 1185 | |
| 1186 | uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE]; |
| 1187 | |
| 1188 | data[0] = ((struct wmi_command_header *)header)->type; |
| 1189 | data[1] = ((struct wmi_command_header *)header)->sub_type; |
| 1190 | data[2] = vdev_id; |
| 1191 | data[3] = chanfreq; |
| 1192 | |
Sandeep Puligilla | b74958d | 2016-06-13 15:42:55 -0700 | [diff] [blame] | 1193 | qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock); |
| 1194 | |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 1195 | WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data); |
Sandeep Puligilla | b74958d | 2016-06-13 15:42:55 -0700 | [diff] [blame] | 1196 | |
| 1197 | qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock); |
| 1198 | } |
Rajeev Kumar | ae91c40 | 2016-05-25 16:07:23 -0700 | [diff] [blame] | 1199 | #else |
| 1200 | /** |
| 1201 | * wmi_debugfs_remove() - Remove debugfs entry for wmi logging. |
| 1202 | * @wmi_handle: wmi handle |
| 1203 | * @dentry: debugfs directory entry |
| 1204 | * @id: Index to debug info data array |
| 1205 | * |
| 1206 | * Return: none |
| 1207 | */ |
Govind Singh | 06c1839 | 2016-06-10 10:33:19 +0530 | [diff] [blame] | 1208 | static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { } |
Himanshu Agarwal | 7c83dcd | 2016-07-19 15:41:51 +0530 | [diff] [blame] | 1209 | void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd, |
Sandeep Puligilla | 828a45f | 2016-07-19 13:20:57 -0700 | [diff] [blame] | 1210 | void *header, uint32_t vdev_id, uint32_t chanfreq) { } |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 1211 | static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1212 | #endif /*WMI_INTERFACE_EVENT_LOGGING */ |
| 1213 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1214 | int wmi_get_host_credits(wmi_unified_t wmi_handle); |
| 1215 | /* WMI buffer APIs */ |
| 1216 | |
| 1217 | #ifdef MEMORY_DEBUG |
| 1218 | wmi_buf_t |
| 1219 | wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name, |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1220 | uint32_t line_num) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1221 | { |
| 1222 | wmi_buf_t wmi_buf; |
| 1223 | |
| 1224 | if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1225 | QDF_ASSERT(0); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1226 | return NULL; |
| 1227 | } |
| 1228 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1229 | wmi_buf = qdf_nbuf_alloc_debug(NULL, |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1230 | roundup(len + WMI_MIN_HEAD_ROOM, 4), |
| 1231 | WMI_MIN_HEAD_ROOM, 4, false, file_name, |
| 1232 | line_num); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1233 | |
| 1234 | if (!wmi_buf) |
| 1235 | return NULL; |
| 1236 | |
| 1237 | /* Clear the wmi buffer */ |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1238 | OS_MEMZERO(qdf_nbuf_data(wmi_buf), len); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1239 | |
| 1240 | /* |
| 1241 | * Set the length of the buffer to match the allocation size. |
| 1242 | */ |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1243 | qdf_nbuf_set_pktlen(wmi_buf, len); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1244 | |
| 1245 | return wmi_buf; |
| 1246 | } |
| 1247 | |
| 1248 | void wmi_buf_free(wmi_buf_t net_buf) |
| 1249 | { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1250 | qdf_nbuf_free(net_buf); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1251 | } |
| 1252 | #else |
| 1253 | wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len) |
| 1254 | { |
| 1255 | wmi_buf_t wmi_buf; |
| 1256 | |
| 1257 | if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1258 | QDF_ASSERT(0); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1259 | return NULL; |
| 1260 | } |
| 1261 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1262 | wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4), |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1263 | WMI_MIN_HEAD_ROOM, 4, false); |
| 1264 | if (!wmi_buf) |
| 1265 | return NULL; |
| 1266 | |
| 1267 | /* Clear the wmi buffer */ |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1268 | OS_MEMZERO(qdf_nbuf_data(wmi_buf), len); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1269 | |
| 1270 | /* |
| 1271 | * Set the length of the buffer to match the allocation size. |
| 1272 | */ |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1273 | qdf_nbuf_set_pktlen(wmi_buf, len); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1274 | return wmi_buf; |
| 1275 | } |
| 1276 | |
| 1277 | void wmi_buf_free(wmi_buf_t net_buf) |
| 1278 | { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1279 | qdf_nbuf_free(net_buf); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1280 | } |
| 1281 | #endif |
| 1282 | |
| 1283 | /** |
| 1284 | * wmi_get_max_msg_len() - get maximum WMI message length |
| 1285 | * @wmi_handle: WMI handle. |
| 1286 | * |
| 1287 | * This function returns the maximum WMI message length |
| 1288 | * |
| 1289 | * Return: maximum WMI message length |
| 1290 | */ |
| 1291 | uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle) |
| 1292 | { |
| 1293 | return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM; |
| 1294 | } |
| 1295 | |
Ashish Kumar Dhanotiya | 4f873ff | 2017-03-16 18:03:32 +0530 | [diff] [blame] | 1296 | #ifndef WMI_CMD_STRINGS |
Himanshu Agarwal | 7c83dcd | 2016-07-19 15:41:51 +0530 | [diff] [blame] | 1297 | static uint8_t *wmi_id_to_name(uint32_t wmi_command) |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1298 | { |
| 1299 | return "Invalid WMI cmd"; |
| 1300 | } |
Ashish Kumar Dhanotiya | 4f873ff | 2017-03-16 18:03:32 +0530 | [diff] [blame] | 1301 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1302 | #endif |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1303 | |
Kiran Venkatappa | 1d5f5ab | 2016-08-09 22:52:35 +0530 | [diff] [blame] | 1304 | #ifdef CONFIG_MCL |
Govind Singh | 2d8bfc6 | 2017-03-21 13:02:00 +0530 | [diff] [blame] | 1305 | static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag) |
| 1306 | { |
| 1307 | WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n", |
| 1308 | wmi_id_to_name(cmd_id), cmd_id, tag); |
| 1309 | } |
| 1310 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1311 | /** |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1312 | * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence |
| 1313 | * @cmd_id: command to check |
| 1314 | * |
| 1315 | * Return: true if the command is part of the resume sequence. |
| 1316 | */ |
Himanshu Agarwal | 7c83dcd | 2016-07-19 15:41:51 +0530 | [diff] [blame] | 1317 | static bool wmi_is_pm_resume_cmd(uint32_t cmd_id) |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1318 | { |
| 1319 | switch (cmd_id) { |
| 1320 | case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID: |
| 1321 | case WMI_PDEV_RESUME_CMDID: |
| 1322 | return true; |
| 1323 | |
| 1324 | default: |
| 1325 | return false; |
| 1326 | } |
| 1327 | } |
| 1328 | #else |
Himanshu Agarwal | 7c83dcd | 2016-07-19 15:41:51 +0530 | [diff] [blame] | 1329 | static bool wmi_is_pm_resume_cmd(uint32_t cmd_id) |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1330 | { |
| 1331 | return false; |
| 1332 | } |
| 1333 | #endif |
| 1334 | |
| 1335 | /** |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1336 | * wmi_unified_cmd_send() - WMI command API |
| 1337 | * @wmi_handle: handle to wmi |
| 1338 | * @buf: wmi buf |
| 1339 | * @len: wmi buffer length |
| 1340 | * @cmd_id: wmi command id |
| 1341 | * |
Dustin Brown | 4103e4a | 2016-11-14 16:11:26 -0800 | [diff] [blame] | 1342 | * Note, it is NOT safe to access buf after calling this function! |
| 1343 | * |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1344 | * Return: 0 on success |
| 1345 | */ |
Houston Hoffman | cdd5eda | 2016-09-27 23:29:49 -0700 | [diff] [blame] | 1346 | QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf, |
| 1347 | uint32_t len, uint32_t cmd_id) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1348 | { |
| 1349 | HTC_PACKET *pkt; |
Rakesh Pillai | 943a6c1 | 2017-06-22 12:52:31 +0530 | [diff] [blame] | 1350 | QDF_STATUS status; |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1351 | uint16_t htc_tag = 0; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1352 | |
| 1353 | if (wmi_get_runtime_pm_inprogress(wmi_handle)) { |
Sarada Prasanna Garnayak | 17b9e9e | 2017-01-05 19:30:07 +0530 | [diff] [blame] | 1354 | htc_tag = |
| 1355 | (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag( |
| 1356 | wmi_handle, buf, cmd_id); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1357 | } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) && |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1358 | (!wmi_is_pm_resume_cmd(cmd_id))) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1359 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1360 | "%s: Target is suspended", __func__); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1361 | QDF_ASSERT(0); |
Govind Singh | 67922e8 | 2016-04-01 16:48:57 +0530 | [diff] [blame] | 1362 | return QDF_STATUS_E_BUSY; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1363 | } |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1364 | if (wmi_handle->wmi_stopinprogress) { |
| 1365 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
| 1366 | "WMI stop in progress\n"); |
Houston Hoffman | cdd5eda | 2016-09-27 23:29:49 -0700 | [diff] [blame] | 1367 | return QDF_STATUS_E_INVAL; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1368 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1369 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1370 | #ifndef WMI_NON_TLV_SUPPORT |
Kiran Venkatappa | 1d5f5ab | 2016-08-09 22:52:35 +0530 | [diff] [blame] | 1371 | /* Do sanity check on the TLV parameter structure */ |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1372 | if (wmi_handle->target_type == WMI_TLV_TARGET) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1373 | void *buf_ptr = (void *)qdf_nbuf_data(buf); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1374 | |
| 1375 | if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id) |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1376 | != 0) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1377 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1378 | "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d", |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1379 | __func__, cmd_id); |
Govind Singh | 67922e8 | 2016-04-01 16:48:57 +0530 | [diff] [blame] | 1380 | return QDF_STATUS_E_INVAL; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1381 | } |
| 1382 | } |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1383 | #endif |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1384 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1385 | if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) { |
| 1386 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1387 | "%s, Failed to send cmd %x, no memory", |
| 1388 | __func__, cmd_id); |
Govind Singh | 67922e8 | 2016-04-01 16:48:57 +0530 | [diff] [blame] | 1389 | return QDF_STATUS_E_NOMEM; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1390 | } |
| 1391 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1392 | WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1393 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1394 | qdf_atomic_inc(&wmi_handle->pending_cmds); |
| 1395 | if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) { |
| 1396 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1397 | "\n%s: hostcredits = %d", __func__, |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1398 | wmi_get_host_credits(wmi_handle)); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1399 | htc_dump_counter_info(wmi_handle->htc_handle); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1400 | qdf_atomic_dec(&wmi_handle->pending_cmds); |
| 1401 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Mukul Sharma | 7da24ca | 2016-10-12 23:50:13 +0530 | [diff] [blame] | 1402 | "%s: MAX %d WMI Pending cmds reached.", __func__, |
| 1403 | WMI_MAX_CMDS); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1404 | QDF_BUG(0); |
Govind Singh | 67922e8 | 2016-04-01 16:48:57 +0530 | [diff] [blame] | 1405 | return QDF_STATUS_E_BUSY; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1406 | } |
| 1407 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1408 | pkt = qdf_mem_malloc(sizeof(*pkt)); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1409 | if (!pkt) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1410 | qdf_atomic_dec(&wmi_handle->pending_cmds); |
| 1411 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1412 | "%s, Failed to alloc htc packet %x, no memory", |
| 1413 | __func__, cmd_id); |
Govind Singh | 67922e8 | 2016-04-01 16:48:57 +0530 | [diff] [blame] | 1414 | return QDF_STATUS_E_NOMEM; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | SET_HTC_PACKET_INFO_TX(pkt, |
| 1418 | NULL, |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1419 | qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR), |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1420 | wmi_handle->wmi_endpoint_id, htc_tag); |
| 1421 | |
| 1422 | SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf); |
Kiran Venkatappa | 1d5f5ab | 2016-08-09 22:52:35 +0530 | [diff] [blame] | 1423 | #ifdef CONFIG_MCL |
Govind Singh | 2d8bfc6 | 2017-03-21 13:02:00 +0530 | [diff] [blame] | 1424 | wmi_log_cmd_id(cmd_id, htc_tag); |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1425 | #endif |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1426 | |
| 1427 | #ifdef WMI_INTERFACE_EVENT_LOGGING |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1428 | if (wmi_handle->log_info.wmi_logging_enable) { |
| 1429 | qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock); |
jiad | 36c94d2 | 2018-01-22 15:37:03 +0800 | [diff] [blame] | 1430 | /* |
| 1431 | * Record 16 bytes of WMI cmd data - |
| 1432 | * exclude TLV and WMI headers |
| 1433 | * |
| 1434 | * WMI mgmt command already recorded in wmi_mgmt_cmd_record |
| 1435 | */ |
| 1436 | if (wmi_handle->ops->is_management_record(cmd_id) == false) { |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1437 | WMI_COMMAND_RECORD(wmi_handle, cmd_id, |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 1438 | qdf_nbuf_data(buf) + |
| 1439 | wmi_handle->log_info.buf_offset_command); |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1440 | } |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1441 | qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock); |
| 1442 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1443 | #endif |
| 1444 | |
| 1445 | status = htc_send_pkt(wmi_handle->htc_handle, pkt); |
| 1446 | |
Rakesh Pillai | 943a6c1 | 2017-06-22 12:52:31 +0530 | [diff] [blame] | 1447 | if (QDF_STATUS_SUCCESS != status) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1448 | qdf_atomic_dec(&wmi_handle->pending_cmds); |
| 1449 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1450 | "%s %d, htc_send_pkt failed", __func__, __LINE__); |
Houston Hoffman | 40805b8 | 2016-10-13 15:30:52 -0700 | [diff] [blame] | 1451 | qdf_mem_free(pkt); |
Rakesh Pillai | 943a6c1 | 2017-06-22 12:52:31 +0530 | [diff] [blame] | 1452 | return status; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1453 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1454 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1455 | return QDF_STATUS_SUCCESS; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * wmi_unified_get_event_handler_ix() - gives event handler's index |
| 1460 | * @wmi_handle: handle to wmi |
| 1461 | * @event_id: wmi event id |
| 1462 | * |
| 1463 | * Return: event handler's index |
| 1464 | */ |
Jeff Johnson | 9366d7a | 2016-10-07 13:03:02 -0700 | [diff] [blame] | 1465 | static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle, |
| 1466 | uint32_t event_id) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1467 | { |
| 1468 | uint32_t idx = 0; |
| 1469 | int32_t invalid_idx = -1; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1470 | struct wmi_soc *soc = wmi_handle->soc; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1471 | |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1472 | for (idx = 0; (idx < soc->max_event_idx && |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1473 | idx < WMI_UNIFIED_MAX_EVENT); ++idx) { |
| 1474 | if (wmi_handle->event_id[idx] == event_id && |
| 1475 | wmi_handle->event_handler[idx] != NULL) { |
| 1476 | return idx; |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | return invalid_idx; |
| 1481 | } |
| 1482 | |
| 1483 | /** |
Soumya Bhat | 488092d | 2017-03-22 14:41:01 +0530 | [diff] [blame] | 1484 | * wmi_unified_register_event() - register wmi event handler |
| 1485 | * @wmi_handle: handle to wmi |
| 1486 | * @event_id: wmi event id |
| 1487 | * @handler_func: wmi event handler function |
| 1488 | * |
| 1489 | * Return: 0 on success |
| 1490 | */ |
| 1491 | int wmi_unified_register_event(wmi_unified_t wmi_handle, |
| 1492 | uint32_t event_id, |
| 1493 | wmi_unified_event_handler handler_func) |
| 1494 | { |
| 1495 | uint32_t idx = 0; |
| 1496 | uint32_t evt_id; |
| 1497 | struct wmi_soc *soc = wmi_handle->soc; |
| 1498 | |
| 1499 | if (event_id >= wmi_events_max || |
| 1500 | wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) { |
| 1501 | qdf_print("%s: Event id %d is unavailable\n", |
| 1502 | __func__, event_id); |
| 1503 | return QDF_STATUS_E_FAILURE; |
| 1504 | } |
| 1505 | evt_id = wmi_handle->wmi_events[event_id]; |
| 1506 | if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) { |
| 1507 | qdf_print("%s : event handler already registered 0x%x\n", |
| 1508 | __func__, evt_id); |
| 1509 | return QDF_STATUS_E_FAILURE; |
| 1510 | } |
| 1511 | if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) { |
| 1512 | qdf_print("%s : no more event handlers 0x%x\n", |
| 1513 | __func__, evt_id); |
| 1514 | return QDF_STATUS_E_FAILURE; |
| 1515 | } |
| 1516 | idx = soc->max_event_idx; |
| 1517 | wmi_handle->event_handler[idx] = handler_func; |
| 1518 | wmi_handle->event_id[idx] = evt_id; |
| 1519 | qdf_spin_lock_bh(&soc->ctx_lock); |
| 1520 | wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX; |
| 1521 | qdf_spin_unlock_bh(&soc->ctx_lock); |
| 1522 | soc->max_event_idx++; |
| 1523 | |
| 1524 | return 0; |
| 1525 | } |
| 1526 | |
| 1527 | /** |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1528 | * wmi_unified_register_event_handler() - register wmi event handler |
| 1529 | * @wmi_handle: handle to wmi |
| 1530 | * @event_id: wmi event id |
| 1531 | * @handler_func: wmi event handler function |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1532 | * @rx_ctx: rx execution context for wmi rx events |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1533 | * |
Soumya Bhat | 488092d | 2017-03-22 14:41:01 +0530 | [diff] [blame] | 1534 | * This API is to support legacy requirements. Will be deprecated in future. |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1535 | * Return: 0 on success |
| 1536 | */ |
| 1537 | int wmi_unified_register_event_handler(wmi_unified_t wmi_handle, |
Mukul Sharma | 2c66f7e | 2017-11-03 19:26:54 +0530 | [diff] [blame] | 1538 | wmi_conv_event_id event_id, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1539 | wmi_unified_event_handler handler_func, |
| 1540 | uint8_t rx_ctx) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1541 | { |
| 1542 | uint32_t idx = 0; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1543 | uint32_t evt_id; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1544 | struct wmi_soc *soc = wmi_handle->soc; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1545 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1546 | if (event_id >= wmi_events_max || |
| 1547 | wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) { |
| 1548 | qdf_print("%s: Event id %d is unavailable\n", |
| 1549 | __func__, event_id); |
| 1550 | return QDF_STATUS_E_FAILURE; |
| 1551 | } |
| 1552 | evt_id = wmi_handle->wmi_events[event_id]; |
Mukul Sharma | 2c66f7e | 2017-11-03 19:26:54 +0530 | [diff] [blame] | 1553 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1554 | if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) { |
| 1555 | qdf_print("%s : event handler already registered 0x%x\n", |
| 1556 | __func__, evt_id); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1557 | return QDF_STATUS_E_FAILURE; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1558 | } |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1559 | if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) { |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1560 | qdf_print("%s : no more event handlers 0x%x\n", |
| 1561 | __func__, evt_id); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1562 | return QDF_STATUS_E_FAILURE; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1563 | } |
Adil Saeed Musthafa | 4f2c98f | 2017-07-05 14:43:51 -0700 | [diff] [blame] | 1564 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG, |
| 1565 | "Registered event handler for event 0x%8x\n", evt_id); |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1566 | idx = soc->max_event_idx; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1567 | wmi_handle->event_handler[idx] = handler_func; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1568 | wmi_handle->event_id[idx] = evt_id; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1569 | qdf_spin_lock_bh(&soc->ctx_lock); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1570 | wmi_handle->ctx[idx] = rx_ctx; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1571 | qdf_spin_unlock_bh(&soc->ctx_lock); |
| 1572 | soc->max_event_idx++; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | /** |
Soumya Bhat | 8eb0b93 | 2017-03-27 12:26:56 +0530 | [diff] [blame] | 1578 | * wmi_unified_unregister_event() - unregister wmi event handler |
| 1579 | * @wmi_handle: handle to wmi |
| 1580 | * @event_id: wmi event id |
| 1581 | * |
| 1582 | * Return: 0 on success |
| 1583 | */ |
| 1584 | int wmi_unified_unregister_event(wmi_unified_t wmi_handle, |
| 1585 | uint32_t event_id) |
| 1586 | { |
| 1587 | uint32_t idx = 0; |
| 1588 | uint32_t evt_id; |
| 1589 | struct wmi_soc *soc = wmi_handle->soc; |
| 1590 | |
| 1591 | if (event_id >= wmi_events_max || |
| 1592 | wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) { |
| 1593 | qdf_print("%s: Event id %d is unavailable\n", |
| 1594 | __func__, event_id); |
| 1595 | return QDF_STATUS_E_FAILURE; |
| 1596 | } |
| 1597 | evt_id = wmi_handle->wmi_events[event_id]; |
| 1598 | |
| 1599 | idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id); |
| 1600 | if (idx == -1) { |
| 1601 | qdf_print("%s : event handler is not registered: evt id 0x%x\n", |
| 1602 | __func__, evt_id); |
| 1603 | return QDF_STATUS_E_FAILURE; |
| 1604 | } |
| 1605 | wmi_handle->event_handler[idx] = NULL; |
| 1606 | wmi_handle->event_id[idx] = 0; |
| 1607 | --soc->max_event_idx; |
| 1608 | wmi_handle->event_handler[idx] = |
| 1609 | wmi_handle->event_handler[soc->max_event_idx]; |
| 1610 | wmi_handle->event_id[idx] = |
| 1611 | wmi_handle->event_id[soc->max_event_idx]; |
| 1612 | |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | /** |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1617 | * wmi_unified_unregister_event_handler() - unregister wmi event handler |
| 1618 | * @wmi_handle: handle to wmi |
| 1619 | * @event_id: wmi event id |
| 1620 | * |
| 1621 | * Return: 0 on success |
| 1622 | */ |
| 1623 | int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle, |
Mukul Sharma | 2c66f7e | 2017-11-03 19:26:54 +0530 | [diff] [blame] | 1624 | wmi_conv_event_id event_id) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1625 | { |
| 1626 | uint32_t idx = 0; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1627 | uint32_t evt_id; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1628 | struct wmi_soc *soc = wmi_handle->soc; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1629 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1630 | if (event_id >= wmi_events_max || |
| 1631 | wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) { |
| 1632 | qdf_print("%s: Event id %d is unavailable\n", |
| 1633 | __func__, event_id); |
| 1634 | return QDF_STATUS_E_FAILURE; |
| 1635 | } |
| 1636 | evt_id = wmi_handle->wmi_events[event_id]; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1637 | |
| 1638 | idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1639 | if (idx == -1) { |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1640 | qdf_print("%s : event handler is not registered: evt id 0x%x\n", |
| 1641 | __func__, evt_id); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1642 | return QDF_STATUS_E_FAILURE; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1643 | } |
| 1644 | wmi_handle->event_handler[idx] = NULL; |
| 1645 | wmi_handle->event_id[idx] = 0; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1646 | --soc->max_event_idx; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1647 | wmi_handle->event_handler[idx] = |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1648 | wmi_handle->event_handler[soc->max_event_idx]; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1649 | wmi_handle->event_id[idx] = |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1650 | wmi_handle->event_id[soc->max_event_idx]; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1651 | |
| 1652 | return 0; |
| 1653 | } |
| 1654 | |
| 1655 | /** |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1656 | * wmi_process_fw_event_default_ctx() - process in default caller context |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1657 | * @wmi_handle: handle to wmi |
| 1658 | * @htc_packet: pointer to htc packet |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1659 | * @exec_ctx: execution context for wmi fw event |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1660 | * |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1661 | * Event process by below function will be in default caller context. |
| 1662 | * wmi internally provides rx work thread processing context. |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1663 | * |
| 1664 | * Return: none |
| 1665 | */ |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1666 | static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle, |
| 1667 | HTC_PACKET *htc_packet, uint8_t exec_ctx) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1668 | { |
| 1669 | wmi_buf_t evt_buf; |
| 1670 | evt_buf = (wmi_buf_t) htc_packet->pPktContext; |
| 1671 | |
Kiran Venkatappa | 1d5f5ab | 2016-08-09 22:52:35 +0530 | [diff] [blame] | 1672 | #ifndef CONFIG_MCL |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1673 | wmi_handle->rx_ops.wma_process_fw_event_handler_cbk |
| 1674 | (wmi_handle->scn_handle, evt_buf, exec_ctx); |
| 1675 | #else |
Govind Singh | 5eb5153 | 2016-03-09 11:34:12 +0530 | [diff] [blame] | 1676 | wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1677 | evt_buf, exec_ctx); |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1678 | #endif |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1679 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1680 | return; |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context |
| 1685 | * @wmi_handle: handle to wmi |
| 1686 | * @htc_packet: pointer to htc packet |
| 1687 | * |
| 1688 | * Event process by below function will be in worker thread context. |
| 1689 | * Use this method for events which are not critical and not |
| 1690 | * handled in protocol stack. |
| 1691 | * |
| 1692 | * Return: none |
| 1693 | */ |
| 1694 | static void wmi_process_fw_event_worker_thread_ctx |
| 1695 | (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet) |
| 1696 | { |
| 1697 | wmi_buf_t evt_buf; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1698 | |
| 1699 | evt_buf = (wmi_buf_t) htc_packet->pPktContext; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1700 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1701 | qdf_spin_lock_bh(&wmi_handle->eventq_lock); |
| 1702 | qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf); |
| 1703 | qdf_spin_unlock_bh(&wmi_handle->eventq_lock); |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 1704 | qdf_queue_work(0, wmi_handle->wmi_rx_work_queue, |
| 1705 | &wmi_handle->rx_event_work); |
| 1706 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1707 | return; |
| 1708 | } |
| 1709 | |
| 1710 | /** |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 1711 | * wmi_get_pdev_ep: Get wmi handle based on endpoint |
| 1712 | * @soc: handle to wmi soc |
| 1713 | * @ep: endpoint id |
| 1714 | * |
| 1715 | * Return: none |
| 1716 | */ |
| 1717 | static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc, |
| 1718 | HTC_ENDPOINT_ID ep) |
| 1719 | { |
| 1720 | uint32_t i; |
| 1721 | |
| 1722 | for (i = 0; i < WMI_MAX_RADIOS; i++) |
| 1723 | if (soc->wmi_endpoint_id[i] == ep) |
| 1724 | break; |
| 1725 | |
| 1726 | if (i == WMI_MAX_RADIOS) |
| 1727 | return NULL; |
| 1728 | |
| 1729 | return soc->wmi_pdev[i]; |
| 1730 | } |
| 1731 | |
| 1732 | /** |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1733 | * wmi_control_rx() - process fw events callbacks |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1734 | * @ctx: handle to wmi |
| 1735 | * @htc_packet: pointer to htc packet |
| 1736 | * |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1737 | * Return: none |
| 1738 | */ |
Jeff Johnson | 9366d7a | 2016-10-07 13:03:02 -0700 | [diff] [blame] | 1739 | static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1740 | { |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 1741 | struct wmi_soc *soc = (struct wmi_soc *) ctx; |
| 1742 | struct wmi_unified *wmi_handle; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1743 | wmi_buf_t evt_buf; |
| 1744 | uint32_t id; |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1745 | uint32_t idx = 0; |
| 1746 | enum wmi_rx_exec_ctx exec_ctx; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1747 | |
| 1748 | evt_buf = (wmi_buf_t) htc_packet->pPktContext; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 1749 | |
| 1750 | wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint); |
| 1751 | if (wmi_handle == NULL) { |
| 1752 | qdf_print |
| 1753 | ("%s :unable to get wmi_handle to Endpoint %d\n", |
| 1754 | __func__, htc_packet->Endpoint); |
| 1755 | qdf_nbuf_free(evt_buf); |
| 1756 | return; |
| 1757 | } |
| 1758 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1759 | id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1760 | idx = wmi_unified_get_event_handler_ix(wmi_handle, id); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1761 | if (qdf_unlikely(idx == A_ERROR)) { |
yeshwanth sriram guntuka | 0a050d7 | 2017-07-10 15:01:15 +0530 | [diff] [blame] | 1762 | WMI_LOGD("%s :event handler is not registered: event id 0x%x\n", |
| 1763 | __func__, id); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1764 | qdf_nbuf_free(evt_buf); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1765 | return; |
| 1766 | } |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1767 | qdf_spin_lock_bh(&soc->ctx_lock); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1768 | exec_ctx = wmi_handle->ctx[idx]; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 1769 | qdf_spin_unlock_bh(&soc->ctx_lock); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1770 | |
Houston Hoffman | c85276b | 2017-10-11 14:50:30 -0700 | [diff] [blame] | 1771 | #ifdef WMI_INTERFACE_EVENT_LOGGING |
| 1772 | if (wmi_handle->log_info.wmi_logging_enable) { |
| 1773 | uint8_t *data; |
| 1774 | data = qdf_nbuf_data(evt_buf); |
| 1775 | |
| 1776 | qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock); |
| 1777 | /* Exclude 4 bytes of TLV header */ |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 1778 | WMI_RX_EVENT_RECORD(wmi_handle, id, data + |
| 1779 | wmi_handle->log_info.buf_offset_event); |
Houston Hoffman | c85276b | 2017-10-11 14:50:30 -0700 | [diff] [blame] | 1780 | qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock); |
| 1781 | } |
| 1782 | #endif |
| 1783 | |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1784 | if (exec_ctx == WMI_RX_WORK_CTX) { |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1785 | wmi_process_fw_event_worker_thread_ctx |
| 1786 | (wmi_handle, htc_packet); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1787 | } else if (exec_ctx > WMI_RX_WORK_CTX) { |
| 1788 | wmi_process_fw_event_default_ctx |
| 1789 | (wmi_handle, htc_packet, exec_ctx); |
| 1790 | } else { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1791 | qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx); |
| 1792 | qdf_nbuf_free(evt_buf); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1793 | } |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1794 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | /** |
| 1798 | * wmi_process_fw_event() - process any fw event |
| 1799 | * @wmi_handle: wmi handle |
| 1800 | * @evt_buf: fw event buffer |
| 1801 | * |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1802 | * This function process fw event in caller context |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1803 | * |
| 1804 | * Return: none |
| 1805 | */ |
| 1806 | void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf) |
| 1807 | { |
| 1808 | __wmi_control_rx(wmi_handle, evt_buf); |
| 1809 | } |
| 1810 | |
| 1811 | /** |
| 1812 | * __wmi_control_rx() - process serialize wmi event callback |
| 1813 | * @wmi_handle: wmi handle |
| 1814 | * @evt_buf: fw event buffer |
| 1815 | * |
| 1816 | * Return: none |
| 1817 | */ |
| 1818 | void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf) |
| 1819 | { |
| 1820 | uint32_t id; |
| 1821 | uint8_t *data; |
| 1822 | uint32_t len; |
| 1823 | void *wmi_cmd_struct_ptr = NULL; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1824 | #ifndef WMI_NON_TLV_SUPPORT |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1825 | int tlv_ok_status = 0; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1826 | #endif |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1827 | uint32_t idx = 0; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1828 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1829 | id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1830 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1831 | if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1832 | goto end; |
| 1833 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1834 | data = qdf_nbuf_data(evt_buf); |
| 1835 | len = qdf_nbuf_len(evt_buf); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1836 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1837 | #ifndef WMI_NON_TLV_SUPPORT |
| 1838 | if (wmi_handle->target_type == WMI_TLV_TARGET) { |
| 1839 | /* Validate and pad(if necessary) the TLVs */ |
| 1840 | tlv_ok_status = |
| 1841 | wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle, |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1842 | data, len, id, |
| 1843 | &wmi_cmd_struct_ptr); |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1844 | if (tlv_ok_status != 0) { |
| 1845 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
| 1846 | "%s: Error: id=0x%d, wmitlv check status=%d\n", |
| 1847 | __func__, id, tlv_ok_status); |
| 1848 | goto end; |
| 1849 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1850 | } |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1851 | #endif |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1852 | |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1853 | idx = wmi_unified_get_event_handler_ix(wmi_handle, id); |
| 1854 | if (idx == A_ERROR) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1855 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR, |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1856 | "%s : event handler is not registered: event id 0x%x\n", |
| 1857 | __func__, id); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1858 | goto end; |
| 1859 | } |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1860 | #ifdef WMI_INTERFACE_EVENT_LOGGING |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1861 | if (wmi_handle->log_info.wmi_logging_enable) { |
| 1862 | qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock); |
| 1863 | /* Exclude 4 bytes of TLV header */ |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 1864 | if (wmi_handle->ops->is_management_record(id)) { |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 1865 | WMI_MGMT_EVENT_RECORD(wmi_handle, id, data |
| 1866 | + wmi_handle->log_info.buf_offset_event); |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1867 | } else { |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 1868 | WMI_EVENT_RECORD(wmi_handle, id, data + |
| 1869 | wmi_handle->log_info.buf_offset_event); |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 1870 | } |
| 1871 | qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1872 | } |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1873 | #endif |
| 1874 | /* Call the WMI registered event handler */ |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1875 | if (wmi_handle->target_type == WMI_TLV_TARGET) |
| 1876 | wmi_handle->event_handler[idx] (wmi_handle->scn_handle, |
| 1877 | wmi_cmd_struct_ptr, len); |
| 1878 | else |
| 1879 | wmi_handle->event_handler[idx] (wmi_handle->scn_handle, |
| 1880 | data, len); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1881 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1882 | end: |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1883 | /* Free event buffer and allocated event tlv */ |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 1884 | #ifndef WMI_NON_TLV_SUPPORT |
| 1885 | if (wmi_handle->target_type == WMI_TLV_TARGET) |
| 1886 | wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr); |
| 1887 | #endif |
Kiran Venkatappa | 1d5f5ab | 2016-08-09 22:52:35 +0530 | [diff] [blame] | 1888 | |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1889 | qdf_nbuf_free(evt_buf); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1890 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1891 | } |
| 1892 | |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1893 | #define WMI_WQ_WD_TIMEOUT (10 * 1000) /* 10s */ |
| 1894 | |
Surabhi Vishnoi | 209f7d4 | 2017-11-29 15:07:10 +0530 | [diff] [blame] | 1895 | static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id) |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1896 | { |
| 1897 | QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, |
| 1898 | "%s: Message type %x has exceeded its alloted time of %ds", |
| 1899 | __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000); |
| 1900 | } |
| 1901 | |
| 1902 | #ifdef CONFIG_SLUB_DEBUG_ON |
| 1903 | static void wmi_workqueue_watchdog_bite(void *arg) |
| 1904 | { |
Govind Singh | c646e10 | 2017-11-21 10:53:40 +0530 | [diff] [blame] | 1905 | struct wmi_wq_dbg_info *info = arg; |
| 1906 | |
| 1907 | wmi_workqueue_watchdog_warn(info->wd_msg_type_id); |
| 1908 | qdf_print_thread_trace(info->task); |
| 1909 | |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1910 | QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, |
| 1911 | "%s: Going down for WMI WQ Watchdog Bite!", __func__); |
| 1912 | QDF_BUG(0); |
| 1913 | } |
| 1914 | #else |
| 1915 | static inline void wmi_workqueue_watchdog_bite(void *arg) |
| 1916 | { |
Govind Singh | c646e10 | 2017-11-21 10:53:40 +0530 | [diff] [blame] | 1917 | struct wmi_wq_dbg_info *info = arg; |
| 1918 | |
| 1919 | wmi_workqueue_watchdog_warn(info->wd_msg_type_id); |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1920 | } |
| 1921 | #endif |
| 1922 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1923 | /** |
| 1924 | * wmi_rx_event_work() - process rx event in rx work queue context |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 1925 | * @arg: opaque pointer to wmi handle |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1926 | * |
| 1927 | * This function process any fw event to serialize it through rx worker thread. |
| 1928 | * |
| 1929 | * Return: none |
| 1930 | */ |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 1931 | static void wmi_rx_event_work(void *arg) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1932 | { |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1933 | wmi_buf_t buf; |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 1934 | struct wmi_unified *wmi = arg; |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1935 | qdf_timer_t wd_timer; |
Govind Singh | c646e10 | 2017-11-21 10:53:40 +0530 | [diff] [blame] | 1936 | struct wmi_wq_dbg_info info; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1937 | |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1938 | /* initialize WMI workqueue watchdog timer */ |
| 1939 | qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite, |
Govind Singh | c646e10 | 2017-11-21 10:53:40 +0530 | [diff] [blame] | 1940 | &info, QDF_TIMER_TYPE_SW); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1941 | qdf_spin_lock_bh(&wmi->eventq_lock); |
| 1942 | buf = qdf_nbuf_queue_remove(&wmi->event_queue); |
| 1943 | qdf_spin_unlock_bh(&wmi->eventq_lock); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1944 | while (buf) { |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1945 | qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT); |
Govind Singh | c646e10 | 2017-11-21 10:53:40 +0530 | [diff] [blame] | 1946 | info.wd_msg_type_id = |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1947 | WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID); |
Govind Singh | c646e10 | 2017-11-21 10:53:40 +0530 | [diff] [blame] | 1948 | info.wmi_wq = wmi->wmi_rx_work_queue; |
| 1949 | info.task = qdf_get_current_task(); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1950 | __wmi_control_rx(wmi, buf); |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1951 | qdf_timer_stop(&wd_timer); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1952 | qdf_spin_lock_bh(&wmi->eventq_lock); |
| 1953 | buf = qdf_nbuf_queue_remove(&wmi->event_queue); |
| 1954 | qdf_spin_unlock_bh(&wmi->eventq_lock); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1955 | } |
Govind Singh | 97b8e7c | 2017-09-07 18:23:39 +0530 | [diff] [blame] | 1956 | qdf_timer_free(&wd_timer); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1957 | } |
| 1958 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1959 | #ifdef FEATURE_RUNTIME_PM |
| 1960 | /** |
| 1961 | * wmi_runtime_pm_init() - initialize runtime pm wmi variables |
| 1962 | * @wmi_handle: wmi context |
| 1963 | */ |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1964 | static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1965 | { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1966 | qdf_atomic_init(&wmi_handle->runtime_pm_inprogress); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1967 | } |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1968 | |
| 1969 | /** |
| 1970 | * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag |
| 1971 | * @wmi_handle: wmi context |
| 1972 | * @val: runtime pm progress flag |
| 1973 | */ |
| 1974 | void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val) |
| 1975 | { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1976 | qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | /** |
| 1980 | * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag |
| 1981 | * @wmi_handle: wmi context |
| 1982 | */ |
| 1983 | inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle) |
| 1984 | { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 1985 | return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress); |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1986 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1987 | #else |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 1988 | static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 1989 | { |
| 1990 | } |
| 1991 | #endif |
| 1992 | |
| 1993 | /** |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 1994 | * wmi_unified_get_soc_handle: Get WMI SoC handle |
| 1995 | * @param wmi_handle: WMI context got from wmi_attach |
| 1996 | * |
| 1997 | * return: Pointer to Soc handle |
| 1998 | */ |
| 1999 | void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle) |
| 2000 | { |
| 2001 | return wmi_handle->soc; |
| 2002 | } |
| 2003 | |
| 2004 | /** |
| 2005 | * wmi_interface_logging_init: Interface looging init |
| 2006 | * @param wmi_handle: Pointer to wmi handle object |
| 2007 | * |
| 2008 | * return: None |
| 2009 | */ |
| 2010 | #ifdef WMI_INTERFACE_EVENT_LOGGING |
| 2011 | static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle) |
| 2012 | { |
| 2013 | if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) { |
| 2014 | qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock); |
| 2015 | wmi_debugfs_init(wmi_handle); |
| 2016 | } |
| 2017 | } |
| 2018 | #else |
| 2019 | void wmi_interface_logging_init(struct wmi_unified *wmi_handle) |
| 2020 | { |
| 2021 | } |
| 2022 | #endif |
| 2023 | |
| 2024 | /** |
| 2025 | * wmi_target_params_init: Target specific params init |
| 2026 | * @param wmi_soc: Pointer to wmi soc object |
| 2027 | * @param wmi_handle: Pointer to wmi handle object |
| 2028 | * |
| 2029 | * return: None |
| 2030 | */ |
| 2031 | #ifndef CONFIG_MCL |
| 2032 | static inline void wmi_target_params_init(struct wmi_soc *soc, |
| 2033 | struct wmi_unified *wmi_handle) |
| 2034 | { |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2035 | wmi_handle->pdev_param = soc->pdev_param; |
| 2036 | wmi_handle->vdev_param = soc->vdev_param; |
Kris Muthusamy | 76e2241 | 2018-01-26 16:18:37 -0800 | [diff] [blame] | 2037 | wmi_handle->services = soc->services; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2038 | } |
| 2039 | #else |
| 2040 | static inline void wmi_target_params_init(struct wmi_soc *soc, |
| 2041 | struct wmi_unified *wmi_handle) |
| 2042 | { |
Kris Muthusamy | 76e2241 | 2018-01-26 16:18:37 -0800 | [diff] [blame] | 2043 | wmi_handle->services = soc->services; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2044 | } |
| 2045 | #endif |
| 2046 | |
| 2047 | /** |
| 2048 | * wmi_unified_get_pdev_handle: Get WMI SoC handle |
| 2049 | * @param wmi_soc: Pointer to wmi soc object |
| 2050 | * @param pdev_idx: pdev index |
| 2051 | * |
| 2052 | * return: Pointer to wmi handle or NULL on failure |
| 2053 | */ |
| 2054 | void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx) |
| 2055 | { |
| 2056 | struct wmi_unified *wmi_handle; |
| 2057 | |
| 2058 | if (pdev_idx >= WMI_MAX_RADIOS) |
| 2059 | return NULL; |
| 2060 | |
Kiran Venkatappa | ea88a4e | 2017-06-15 17:27:38 +0530 | [diff] [blame] | 2061 | if (soc->wmi_pdev[pdev_idx] == NULL) { |
| 2062 | wmi_handle = |
| 2063 | (struct wmi_unified *) qdf_mem_malloc( |
| 2064 | sizeof(struct wmi_unified)); |
| 2065 | if (wmi_handle == NULL) { |
| 2066 | qdf_print("allocation of wmi handle failed %zu\n", |
| 2067 | sizeof(struct wmi_unified)); |
| 2068 | return NULL; |
| 2069 | } |
| 2070 | wmi_handle->scn_handle = soc->scn_handle; |
| 2071 | wmi_handle->event_id = soc->event_id; |
| 2072 | wmi_handle->event_handler = soc->event_handler; |
| 2073 | wmi_handle->ctx = soc->ctx; |
| 2074 | wmi_handle->ops = soc->ops; |
| 2075 | qdf_spinlock_create(&wmi_handle->eventq_lock); |
| 2076 | qdf_nbuf_queue_init(&wmi_handle->event_queue); |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2077 | |
Kiran Venkatappa | ea88a4e | 2017-06-15 17:27:38 +0530 | [diff] [blame] | 2078 | qdf_create_work(0, &wmi_handle->rx_event_work, |
| 2079 | wmi_rx_event_work, wmi_handle); |
| 2080 | wmi_handle->wmi_rx_work_queue = |
| 2081 | qdf_create_workqueue("wmi_rx_event_work_queue"); |
| 2082 | if (NULL == wmi_handle->wmi_rx_work_queue) { |
| 2083 | WMI_LOGE("failed to create wmi_rx_event_work_queue"); |
| 2084 | goto error; |
| 2085 | } |
| 2086 | wmi_handle->wmi_events = soc->wmi_events; |
| 2087 | wmi_target_params_init(soc, wmi_handle); |
| 2088 | wmi_interface_logging_init(wmi_handle); |
| 2089 | qdf_atomic_init(&wmi_handle->pending_cmds); |
| 2090 | qdf_atomic_init(&wmi_handle->is_target_suspended); |
| 2091 | wmi_handle->target_type = soc->target_type; |
| 2092 | wmi_handle->soc = soc; |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 2093 | |
Kiran Venkatappa | ea88a4e | 2017-06-15 17:27:38 +0530 | [diff] [blame] | 2094 | soc->wmi_pdev[pdev_idx] = wmi_handle; |
| 2095 | } else |
| 2096 | wmi_handle = soc->wmi_pdev[pdev_idx]; |
| 2097 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2098 | wmi_handle->wmi_stopinprogress = 0; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2099 | wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx]; |
| 2100 | wmi_handle->htc_handle = soc->htc_handle; |
| 2101 | wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx]; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2102 | |
| 2103 | return wmi_handle; |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 2104 | |
| 2105 | error: |
| 2106 | qdf_mem_free(wmi_handle); |
| 2107 | |
| 2108 | return NULL; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | /** |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2112 | * wmi_unified_attach() - attach for unified WMI |
Govind Singh | c458f38 | 2016-02-04 18:42:30 +0530 | [diff] [blame] | 2113 | * @scn_handle: handle to SCN |
| 2114 | * @osdev: OS device context |
| 2115 | * @target_type: TLV or not-TLV based target |
| 2116 | * @use_cookie: cookie based allocation enabled/disabled |
| 2117 | * @ops: umac rx callbacks |
Mukul Sharma | f8a1708 | 2017-01-30 19:55:40 +0530 | [diff] [blame] | 2118 | * @psoc: objmgr psoc |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2119 | * |
| 2120 | * @Return: wmi handle. |
| 2121 | */ |
Govind Singh | c458f38 | 2016-02-04 18:42:30 +0530 | [diff] [blame] | 2122 | void *wmi_unified_attach(void *scn_handle, |
| 2123 | osdev_t osdev, enum wmi_target_type target_type, |
Mukul Sharma | f8a1708 | 2017-01-30 19:55:40 +0530 | [diff] [blame] | 2124 | bool use_cookie, struct wmi_rx_ops *rx_ops, |
| 2125 | struct wlan_objmgr_psoc *psoc) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2126 | { |
| 2127 | struct wmi_unified *wmi_handle; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2128 | struct wmi_soc *soc; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2129 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2130 | soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc)); |
| 2131 | if (soc == NULL) { |
| 2132 | qdf_print("Allocation of wmi_soc failed %zu\n", |
| 2133 | sizeof(struct wmi_soc)); |
| 2134 | return NULL; |
| 2135 | } |
Mukul Sharma | 2c66f7e | 2017-11-03 19:26:54 +0530 | [diff] [blame] | 2136 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2137 | wmi_handle = |
| 2138 | (struct wmi_unified *) qdf_mem_malloc( |
| 2139 | sizeof(struct wmi_unified)); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2140 | if (wmi_handle == NULL) { |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2141 | qdf_mem_free(soc); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2142 | qdf_print("allocation of wmi handle failed %zu\n", |
Govind Singh | d52faac | 2016-03-09 12:03:29 +0530 | [diff] [blame] | 2143 | sizeof(struct wmi_unified)); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2144 | return NULL; |
| 2145 | } |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2146 | wmi_handle->soc = soc; |
| 2147 | wmi_handle->event_id = soc->event_id; |
| 2148 | wmi_handle->event_handler = soc->event_handler; |
| 2149 | wmi_handle->ctx = soc->ctx; |
Soumya Bhat | 488092d | 2017-03-22 14:41:01 +0530 | [diff] [blame] | 2150 | wmi_handle->wmi_events = soc->wmi_events; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2151 | wmi_target_params_init(soc, wmi_handle); |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2152 | wmi_handle->scn_handle = scn_handle; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2153 | soc->scn_handle = scn_handle; |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2154 | qdf_atomic_init(&wmi_handle->pending_cmds); |
| 2155 | qdf_atomic_init(&wmi_handle->is_target_suspended); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2156 | wmi_runtime_pm_init(wmi_handle); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2157 | qdf_spinlock_create(&wmi_handle->eventq_lock); |
| 2158 | qdf_nbuf_queue_init(&wmi_handle->event_queue); |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 2159 | qdf_create_work(0, &wmi_handle->rx_event_work, |
| 2160 | wmi_rx_event_work, wmi_handle); |
| 2161 | wmi_handle->wmi_rx_work_queue = |
| 2162 | qdf_create_workqueue("wmi_rx_event_work_queue"); |
| 2163 | if (NULL == wmi_handle->wmi_rx_work_queue) { |
| 2164 | WMI_LOGE("failed to create wmi_rx_event_work_queue"); |
| 2165 | goto error; |
| 2166 | } |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2167 | wmi_interface_logging_init(wmi_handle); |
Govind Singh | c458f38 | 2016-02-04 18:42:30 +0530 | [diff] [blame] | 2168 | /* Attach mc_thread context processing function */ |
Govind Singh | 5eb5153 | 2016-03-09 11:34:12 +0530 | [diff] [blame] | 2169 | wmi_handle->rx_ops.wma_process_fw_event_handler_cbk = |
| 2170 | rx_ops->wma_process_fw_event_handler_cbk; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2171 | wmi_handle->target_type = target_type; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2172 | soc->target_type = target_type; |
Govind Singh | c458f38 | 2016-02-04 18:42:30 +0530 | [diff] [blame] | 2173 | if (target_type == WMI_TLV_TARGET) |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2174 | wmi_tlv_attach(wmi_handle); |
Govind Singh | c458f38 | 2016-02-04 18:42:30 +0530 | [diff] [blame] | 2175 | else |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2176 | wmi_non_tlv_attach(wmi_handle); |
Govind Singh | c458f38 | 2016-02-04 18:42:30 +0530 | [diff] [blame] | 2177 | /* Assign target cookie capablity */ |
| 2178 | wmi_handle->use_cookie = use_cookie; |
| 2179 | wmi_handle->osdev = osdev; |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2180 | wmi_handle->wmi_stopinprogress = 0; |
Mukul Sharma | f8a1708 | 2017-01-30 19:55:40 +0530 | [diff] [blame] | 2181 | /* Increase the ref count once refcount infra is present */ |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2182 | soc->wmi_psoc = psoc; |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 2183 | qdf_spinlock_create(&soc->ctx_lock); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2184 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2185 | soc->ops = wmi_handle->ops; |
| 2186 | soc->wmi_pdev[0] = wmi_handle; |
| 2187 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2188 | return wmi_handle; |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 2189 | |
| 2190 | error: |
| 2191 | qdf_mem_free(soc); |
| 2192 | qdf_mem_free(wmi_handle); |
| 2193 | |
| 2194 | return NULL; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * wmi_unified_detach() - detach for unified WMI |
| 2199 | * |
| 2200 | * @wmi_handle : handle to wmi. |
| 2201 | * |
| 2202 | * @Return: none. |
| 2203 | */ |
| 2204 | void wmi_unified_detach(struct wmi_unified *wmi_handle) |
| 2205 | { |
| 2206 | wmi_buf_t buf; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2207 | struct wmi_soc *soc; |
| 2208 | uint8_t i; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2209 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2210 | soc = wmi_handle->soc; |
| 2211 | for (i = 0; i < WMI_MAX_RADIOS; i++) { |
| 2212 | if (soc->wmi_pdev[i]) { |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 2213 | qdf_flush_workqueue(0, |
| 2214 | soc->wmi_pdev[i]->wmi_rx_work_queue); |
| 2215 | qdf_destroy_workqueue(0, |
| 2216 | soc->wmi_pdev[i]->wmi_rx_work_queue); |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2217 | wmi_debugfs_remove(soc->wmi_pdev[i]); |
| 2218 | buf = qdf_nbuf_queue_remove( |
| 2219 | &soc->wmi_pdev[i]->event_queue); |
| 2220 | while (buf) { |
| 2221 | qdf_nbuf_free(buf); |
| 2222 | buf = qdf_nbuf_queue_remove( |
| 2223 | &soc->wmi_pdev[i]->event_queue); |
| 2224 | } |
Rajeev Kumar | ae91c40 | 2016-05-25 16:07:23 -0700 | [diff] [blame] | 2225 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2226 | wmi_log_buffer_free(soc->wmi_pdev[i]); |
Wu Gao | 21e6938 | 2017-06-23 16:39:17 +0800 | [diff] [blame] | 2227 | |
| 2228 | /* Free events logs list */ |
| 2229 | if (soc->wmi_pdev[i]->events_logs_list) |
| 2230 | qdf_mem_free( |
| 2231 | soc->wmi_pdev[i]->events_logs_list); |
| 2232 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2233 | qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock); |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2234 | qdf_mem_free(soc->wmi_pdev[i]); |
| 2235 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2236 | } |
Kiran Venkatappa | f285aba | 2017-03-20 20:38:44 +0530 | [diff] [blame] | 2237 | qdf_spinlock_destroy(&soc->ctx_lock); |
Kiran Venkatappa | 7d73914 | 2017-09-01 17:02:34 +0530 | [diff] [blame] | 2238 | |
| 2239 | if (soc->wmi_service_bitmap) { |
| 2240 | qdf_mem_free(soc->wmi_service_bitmap); |
| 2241 | soc->wmi_service_bitmap = NULL; |
| 2242 | } |
| 2243 | |
| 2244 | if (soc->wmi_ext_service_bitmap) { |
| 2245 | qdf_mem_free(soc->wmi_ext_service_bitmap); |
| 2246 | soc->wmi_ext_service_bitmap = NULL; |
| 2247 | } |
| 2248 | |
Mukul Sharma | f8a1708 | 2017-01-30 19:55:40 +0530 | [diff] [blame] | 2249 | /* Decrease the ref count once refcount infra is present */ |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2250 | soc->wmi_psoc = NULL; |
| 2251 | qdf_mem_free(soc); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /** |
| 2255 | * wmi_unified_remove_work() - detach for WMI work |
| 2256 | * @wmi_handle: handle to WMI |
| 2257 | * |
| 2258 | * A function that does not fully detach WMI, but just remove work |
| 2259 | * queue items associated with it. This is used to make sure that |
| 2260 | * before any other processing code that may destroy related contexts |
| 2261 | * (HTC, etc), work queue processing on WMI has already been stopped. |
| 2262 | * |
| 2263 | * Return: None |
| 2264 | */ |
| 2265 | void |
| 2266 | wmi_unified_remove_work(struct wmi_unified *wmi_handle) |
| 2267 | { |
| 2268 | wmi_buf_t buf; |
| 2269 | |
Rajeev Kumar | 2ec8d47 | 2017-03-29 17:14:14 -0700 | [diff] [blame] | 2270 | qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2271 | qdf_spin_lock_bh(&wmi_handle->eventq_lock); |
| 2272 | buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2273 | while (buf) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2274 | qdf_nbuf_free(buf); |
| 2275 | buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2276 | } |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2277 | qdf_spin_unlock_bh(&wmi_handle->eventq_lock); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2278 | } |
| 2279 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2280 | /** |
| 2281 | * wmi_htc_tx_complete() - Process htc tx completion |
| 2282 | * |
| 2283 | * @ctx: handle to wmi |
| 2284 | * @htc_packet: pointer to htc packet |
| 2285 | * |
| 2286 | * @Return: none. |
| 2287 | */ |
Jeff Johnson | 9366d7a | 2016-10-07 13:03:02 -0700 | [diff] [blame] | 2288 | static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2289 | { |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2290 | struct wmi_soc *soc = (struct wmi_soc *) ctx; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2291 | wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt); |
Govind Singh | 82ea326 | 2016-09-02 15:24:25 +0530 | [diff] [blame] | 2292 | u_int8_t *buf_ptr; |
| 2293 | u_int32_t len; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2294 | struct wmi_unified *wmi_handle; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2295 | #ifdef WMI_INTERFACE_EVENT_LOGGING |
| 2296 | uint32_t cmd_id; |
| 2297 | #endif |
| 2298 | |
| 2299 | ASSERT(wmi_cmd_buf); |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2300 | wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint); |
| 2301 | if (wmi_handle == NULL) { |
| 2302 | WMI_LOGE("%s: Unable to get wmi handle\n", __func__); |
| 2303 | QDF_ASSERT(0); |
| 2304 | return; |
| 2305 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2306 | #ifdef WMI_INTERFACE_EVENT_LOGGING |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2307 | if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) { |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 2308 | cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf), |
| 2309 | WMI_CMD_HDR, COMMANDID); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2310 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 2311 | qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2312 | /* Record 16 bytes of WMI cmd tx complete data |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 2313 | - exclude TLV and WMI headers */ |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2314 | if (wmi_handle->ops->is_management_record(cmd_id)) { |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 2315 | WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id, |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 2316 | qdf_nbuf_data(wmi_cmd_buf) + |
| 2317 | wmi_handle->log_info.buf_offset_command); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2318 | } else { |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 2319 | WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id, |
Rakesh Pillai | 0511046 | 2017-12-27 14:08:59 +0530 | [diff] [blame] | 2320 | qdf_nbuf_data(wmi_cmd_buf) + |
| 2321 | wmi_handle->log_info.buf_offset_command); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2322 | } |
| 2323 | |
Govind Singh | ecf03cd | 2016-05-12 12:45:51 +0530 | [diff] [blame] | 2324 | qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock); |
| 2325 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2326 | #endif |
Govind Singh | 82ea326 | 2016-09-02 15:24:25 +0530 | [diff] [blame] | 2327 | buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf); |
| 2328 | len = qdf_nbuf_len(wmi_cmd_buf); |
| 2329 | qdf_mem_zero(buf_ptr, len); |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2330 | qdf_nbuf_free(wmi_cmd_buf); |
| 2331 | qdf_mem_free(htc_pkt); |
| 2332 | qdf_atomic_dec(&wmi_handle->pending_cmds); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | /** |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2336 | * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2337 | * |
| 2338 | * @wmi_handle: handle to WMI. |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2339 | * @pdev_idx: Pdev index |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2340 | * |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2341 | * @Return: status. |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2342 | */ |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2343 | static int wmi_connect_pdev_htc_service(struct wmi_soc *soc, |
| 2344 | uint32_t pdev_idx) |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2345 | { |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2346 | int status; |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2347 | uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1, |
| 2348 | WMI_CONTROL_SVC_WMAC2}; |
Manikandan Mohan | f940db8 | 2017-04-13 20:19:26 -0700 | [diff] [blame] | 2349 | struct htc_service_connect_resp response; |
| 2350 | struct htc_service_connect_req connect; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2351 | |
| 2352 | OS_MEMZERO(&connect, sizeof(connect)); |
| 2353 | OS_MEMZERO(&response, sizeof(response)); |
| 2354 | |
| 2355 | /* meta data is unused for now */ |
| 2356 | connect.pMetaData = NULL; |
| 2357 | connect.MetaDataLength = 0; |
| 2358 | /* these fields are the same for all service endpoints */ |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2359 | connect.EpCallbacks.pContext = soc; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2360 | connect.EpCallbacks.EpTxCompleteMultiple = |
| 2361 | NULL /* Control path completion ar6000_tx_complete */; |
| 2362 | connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */; |
| 2363 | connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */; |
| 2364 | connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */; |
| 2365 | connect.EpCallbacks.EpTxComplete = |
| 2366 | wmi_htc_tx_complete /* ar6000_tx_queue_full */; |
| 2367 | |
| 2368 | /* connect to control service */ |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2369 | connect.service_id = svc_id[pdev_idx]; |
| 2370 | status = htc_connect_service(soc->htc_handle, &connect, |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2371 | &response); |
| 2372 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2373 | |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2374 | if (status != EOK) { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2375 | qdf_print |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2376 | ("Failed to connect to WMI CONTROL service status:%d\n", |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2377 | status); |
| 2378 | return status; |
| 2379 | } |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2380 | |
Kiran Venkatappa | 5bffce5 | 2017-02-10 16:57:59 +0530 | [diff] [blame] | 2381 | soc->wmi_endpoint_id[pdev_idx] = response.Endpoint; |
| 2382 | soc->max_msg_len[pdev_idx] = response.MaxMsgLength; |
| 2383 | |
| 2384 | return 0; |
| 2385 | } |
| 2386 | |
| 2387 | /** |
| 2388 | * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service |
| 2389 | * |
| 2390 | * @wmi_handle: handle to WMI. |
| 2391 | * |
| 2392 | * @Return: status. |
| 2393 | */ |
| 2394 | QDF_STATUS |
| 2395 | wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle, |
| 2396 | void *htc_handle) |
| 2397 | { |
| 2398 | uint32_t i; |
| 2399 | uint8_t wmi_ep_count; |
| 2400 | |
| 2401 | wmi_handle->soc->htc_handle = htc_handle; |
| 2402 | |
| 2403 | wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle); |
| 2404 | if (wmi_ep_count > WMI_MAX_RADIOS) |
| 2405 | return QDF_STATUS_E_FAULT; |
| 2406 | |
| 2407 | for (i = 0; i < wmi_ep_count; i++) |
| 2408 | wmi_connect_pdev_htc_service(wmi_handle->soc, i); |
| 2409 | |
| 2410 | wmi_handle->htc_handle = htc_handle; |
| 2411 | wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0]; |
| 2412 | wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0]; |
| 2413 | |
| 2414 | return QDF_STATUS_SUCCESS; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | /** |
| 2418 | * wmi_get_host_credits() - WMI API to get updated host_credits |
| 2419 | * |
| 2420 | * @wmi_handle: handle to WMI. |
| 2421 | * |
| 2422 | * @Return: updated host_credits. |
| 2423 | */ |
| 2424 | int wmi_get_host_credits(wmi_unified_t wmi_handle) |
| 2425 | { |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2426 | int host_credits = 0; |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2427 | |
| 2428 | htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle, |
| 2429 | &host_credits); |
| 2430 | return host_credits; |
| 2431 | } |
| 2432 | |
| 2433 | /** |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2434 | * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC |
| 2435 | * queue |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2436 | * |
| 2437 | * @wmi_handle: handle to WMI. |
| 2438 | * |
| 2439 | * @Return: Pending Commands in the HTC queue. |
| 2440 | */ |
| 2441 | int wmi_get_pending_cmds(wmi_unified_t wmi_handle) |
| 2442 | { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2443 | return qdf_atomic_read(&wmi_handle->pending_cmds); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * wmi_set_target_suspend() - WMI API to set target suspend state |
| 2448 | * |
| 2449 | * @wmi_handle: handle to WMI. |
| 2450 | * @val: suspend state boolean. |
| 2451 | * |
| 2452 | * @Return: none. |
| 2453 | */ |
| 2454 | void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val) |
| 2455 | { |
Govind Singh | b53420c | 2016-03-09 14:32:57 +0530 | [diff] [blame] | 2456 | qdf_atomic_set(&wmi_handle->is_target_suspended, val); |
Govind Singh | 6b411b5 | 2016-03-06 19:55:02 +0530 | [diff] [blame] | 2457 | } |
| 2458 | |
Sarada Prasanna Garnayak | 17b9e9e | 2017-01-05 19:30:07 +0530 | [diff] [blame] | 2459 | /** |
| 2460 | * WMI API to set crash injection state |
| 2461 | * @param wmi_handle: handle to WMI. |
| 2462 | * @param val: crash injection state boolean. |
| 2463 | */ |
| 2464 | void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag) |
| 2465 | { |
| 2466 | wmi_handle->tag_crash_inject = flag; |
| 2467 | } |
| 2468 | |
| 2469 | /** |
| 2470 | * WMI API to set bus suspend state |
| 2471 | * @param wmi_handle: handle to WMI. |
| 2472 | * @param val: suspend state boolean. |
| 2473 | */ |
| 2474 | void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val) |
| 2475 | { |
| 2476 | qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val); |
| 2477 | } |
| 2478 | |
Ravi Kumar Bokka | 7aec5b5 | 2016-11-09 18:07:56 +0530 | [diff] [blame] | 2479 | void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val) |
| 2480 | { |
| 2481 | wmi_handle->tgt_force_assert_enable = val; |
| 2482 | } |
| 2483 | |
Kiran Venkatappa | 1d5f5ab | 2016-08-09 22:52:35 +0530 | [diff] [blame] | 2484 | #ifndef CONFIG_MCL |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2485 | /** |
| 2486 | * API to flush all the previous packets associated with the wmi endpoint |
| 2487 | * |
| 2488 | * @param wmi_handle : handle to WMI. |
| 2489 | */ |
| 2490 | void |
| 2491 | wmi_flush_endpoint(wmi_unified_t wmi_handle) |
| 2492 | { |
| 2493 | htc_flush_endpoint(wmi_handle->htc_handle, |
| 2494 | wmi_handle->wmi_endpoint_id, 0); |
| 2495 | } |
| 2496 | |
| 2497 | /** |
| 2498 | * generic function to block unified WMI command |
| 2499 | * @param wmi_handle : handle to WMI. |
| 2500 | * @return 0 on success and -ve on failure. |
| 2501 | */ |
| 2502 | int |
| 2503 | wmi_stop(wmi_unified_t wmi_handle) |
| 2504 | { |
| 2505 | QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO, |
| 2506 | "WMI Stop\n"); |
| 2507 | wmi_handle->wmi_stopinprogress = 1; |
| 2508 | return 0; |
| 2509 | } |
Kiran Venkatappa | 1241bb8 | 2017-05-10 16:24:51 +0530 | [diff] [blame] | 2510 | |
| 2511 | /** |
| 2512 | * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI |
| 2513 | * By default pdev_id conversion is not done in WMI. |
| 2514 | * This API can be used enable conversion in WMI. |
| 2515 | * @param wmi_handle : handle to WMI |
| 2516 | * Return none |
| 2517 | */ |
| 2518 | void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle) |
| 2519 | { |
| 2520 | if (wmi_handle->target_type == WMI_TLV_TARGET) |
| 2521 | wmi_tlv_pdev_id_conversion_enable(wmi_handle); |
| 2522 | } |
| 2523 | |
Govind Singh | e7d9f3e | 2016-04-15 13:58:27 +0530 | [diff] [blame] | 2524 | #endif |