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