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