1 /* 2 * EVENT_LOG system definitions 3 * 4 * Copyright (C) 2020, Broadcom. 5 * 6 * Unless you and Broadcom execute a separate written software license 7 * agreement governing use of this software, this software is licensed to you 8 * under the terms of the GNU General Public License version 2 (the "GPL"), 9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10 * following added to such license: 11 * 12 * As a special exception, the copyright holders of this software give you 13 * permission to link this software with independent modules, and to copy and 14 * distribute the resulting executable under terms of your choice, provided that 15 * you also meet, for each linked independent module, the terms and conditions of 16 * the license of that module. An independent module is a module which is not 17 * derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * 21 * <<Broadcom-WL-IPTag/Dual:>> 22 */ 23 24 #ifndef _EVENT_LOG_H_ 25 #define _EVENT_LOG_H_ 26 27 #include <typedefs.h> 28 #include <event_log_set.h> 29 #include <event_log_tag.h> 30 #include <event_log_payload.h> 31 32 /* logstrs header */ 33 #define LOGSTRS_MAGIC 0x4C4F4753 34 #define LOGSTRS_VERSION 0x1 35 36 /* max log size */ 37 #define EVENT_LOG_MAX_SIZE (64u * 1024u) 38 39 /* We make sure that the block size will fit in a single packet 40 * (allowing for a bit of overhead on each packet 41 */ 42 #if defined(BCMPCIEDEV) 43 #define EVENT_LOG_MAX_BLOCK_SIZE 1648 44 #else 45 #define EVENT_LOG_MAX_BLOCK_SIZE 1400 46 #endif 47 48 #define EVENT_LOG_BLOCK_SIZE_1K 0x400u 49 #define EVENT_LOG_WL_BLOCK_SIZE 0x200 50 #define EVENT_LOG_PSM_BLOCK_SIZE 0x200 51 #define EVENT_LOG_MEM_API_BLOCK_SIZE 0x200 52 #define EVENT_LOG_BUS_BLOCK_SIZE 0x200 53 #define EVENT_LOG_ERROR_BLOCK_SIZE 0x400 54 #define EVENT_LOG_MSCH_BLOCK_SIZE 0x400 55 #define EVENT_LOG_WBUS_BLOCK_SIZE 0x100 56 #define EVENT_LOG_PRSV_PERIODIC_BLOCK_SIZE (0x200u) 57 58 #define EVENT_LOG_WL_BUF_SIZE (EVENT_LOG_WL_BLOCK_SIZE * 3u) 59 60 #define EVENT_LOG_TOF_INLINE_BLOCK_SIZE 1300u 61 #define EVENT_LOG_TOF_INLINE_BUF_SIZE (EVENT_LOG_TOF_INLINE_BLOCK_SIZE * 3u) 62 63 #define EVENT_LOG_PRSRV_BUF_SIZE (EVENT_LOG_MAX_BLOCK_SIZE * 2) 64 #define EVENT_LOG_BUS_PRSRV_BUF_SIZE (EVENT_LOG_BUS_BLOCK_SIZE * 2) 65 #define EVENT_LOG_WBUS_PRSRV_BUF_SIZE (EVENT_LOG_WBUS_BLOCK_SIZE * 2) 66 67 #define EVENT_LOG_BLOCK_SIZE_PRSRV_CHATTY (EVENT_LOG_MAX_BLOCK_SIZE * 1) 68 #define EVENT_LOG_BLOCK_SIZE_BUS_PRSRV_CHATTY (EVENT_LOG_MAX_BLOCK_SIZE * 1) 69 70 /* Maximum event log record payload size = 1016 bytes or 254 words. */ 71 #define EVENT_LOG_MAX_RECORD_PAYLOAD_SIZE 254 72 73 #define EVENT_LOG_EXT_HDR_IND (0x01) 74 #define EVENT_LOG_EXT_HDR_BIN_DATA_IND (0x01 << 1) 75 /* Format number to send binary data with extended event log header */ 76 #define EVENT_LOG_EXT_HDR_BIN_FMT_NUM (0x3FFE << 2) 77 78 #define EVENT_LOGSET_ID_MASK 0x3F 79 /* For event_log_get iovar, set values from 240 to 255 mean special commands for a group of sets */ 80 #define EVENT_LOG_GET_IOV_CMD_MASK (0xF0u) 81 #define EVENT_LOG_GET_IOV_CMD_ID_MASK (0xFu) 82 #define EVENT_LOG_GET_IOV_CMD_ID_FORCE_FLUSH_PRSRV (0xEu) /* 240 + 14 = 254 */ 83 #define EVENT_LOG_GET_IOV_CMD_ID_FORCE_FLUSH_ALL (0xFu) /* 240 + 15 = 255 */ 84 85 /* 86 * There are multiple levels of objects define here: 87 * event_log_set - a set of buffers 88 * event log groups - every event log call is part of just one. All 89 * event log calls in a group are handled the 90 * same way. Each event log group is associated 91 * with an event log set or is off. 92 */ 93 94 #ifndef __ASSEMBLER__ 95 96 /* On the external system where the dumper is we need to make sure 97 * that these types are the same size as they are on the ARM the 98 * produced them 99 */ 100 #ifdef EVENT_LOG_DUMPER 101 #define _EL_BLOCK_PTR uint32 102 #define _EL_TYPE_PTR uint32 103 #define _EL_SET_PTR uint32 104 #define _EL_TOP_PTR uint32 105 #else 106 #define _EL_BLOCK_PTR struct event_log_block * 107 #define _EL_TYPE_PTR uint32 * 108 #define _EL_SET_PTR struct event_log_set ** 109 #define _EL_TOP_PTR struct event_log_top * 110 #endif /* EVENT_LOG_DUMPER */ 111 112 /* Event log sets (a logical circurlar buffer) consist of one or more 113 * event_log_blocks. The blocks themselves form a logical circular 114 * list. The log entries are placed in each event_log_block until it 115 * is full. Logging continues with the next event_log_block in the 116 * event_set until the last event_log_block is reached and then 117 * logging starts over with the first event_log_block in the 118 * event_set. 119 */ 120 typedef struct event_log_block { 121 _EL_BLOCK_PTR next_block; 122 _EL_BLOCK_PTR prev_block; 123 _EL_TYPE_PTR end_ptr; 124 125 /* Start of packet sent for log tracing */ 126 uint16 pktlen; /* Size of rest of block */ 127 uint16 count; /* Logtrace counter */ 128 uint32 extra_hdr_info; /* LSB: 6 bits set id. MSB 24 bits reserved */ 129 uint32 event_logs; /* Pointer to BEGINNING of event logs */ 130 /* Event logs go here. Do not put extra fields below. */ 131 } event_log_block_t; 132 133 /* Relative offset of extra_hdr_info field frpm pktlen field in log block */ 134 #define EVENT_LOG_BUF_EXTRA_HDR_INFO_REL_PKTLEN_OFFSET \ 135 (OFFSETOF(event_log_block_t, extra_hdr_info) - OFFSETOF(event_log_block_t, pktlen)) 136 137 #define EVENT_LOG_SETID_MASK (0x3Fu) 138 139 #define EVENT_LOG_BLOCK_HDRLEN (sizeof(((event_log_block_t *) 0)->pktlen) \ 140 + sizeof(((event_log_block_t *) 0)->count) \ 141 + sizeof(((event_log_block_t *) 0)->extra_hdr_info)) 142 #define EVENT_LOG_BLOCK_LEN (EVENT_LOG_BLOCK_HDRLEN + sizeof(event_log_hdr_t)) 143 144 #define EVENT_LOG_PRESERVE_BLOCK (1 << 0) 145 #define EVENT_LOG_BLOCK_FLAG_MASK 0xff000000u 146 #define EVENT_LOG_BLOCK_FLAG_SHIFT 24u 147 148 #define EVENT_LOG_BLOCK_GET_PREV_BLOCK(block) ((_EL_BLOCK_PTR)(((uint32)((block)->prev_block)) & \ 149 ~EVENT_LOG_BLOCK_FLAG_MASK)) 150 #define EVENT_LOG_BLOCK_SET_PREV_BLOCK(block, prev) ((block)->prev_block = \ 151 ((_EL_BLOCK_PTR)((((uint32)(block)->prev_block) & EVENT_LOG_BLOCK_FLAG_MASK) | \ 152 (((uint32)(prev)) & ~EVENT_LOG_BLOCK_FLAG_MASK)))) 153 #define EVENT_LOG_BLOCK_GET_FLAG(block) ((((uint32)(block)->prev_block) & \ 154 EVENT_LOG_BLOCK_FLAG_MASK) >> EVENT_LOG_BLOCK_FLAG_SHIFT) 155 #define EVENT_LOG_BLOCK_SET_FLAG(block, flag) ((block)->prev_block = \ 156 (_EL_BLOCK_PTR)(((uint32)EVENT_LOG_BLOCK_GET_PREV_BLOCK(block)) | flag)) 157 #define EVENT_LOG_BLOCK_OR_FLAG(block, flag) EVENT_LOG_BLOCK_SET_FLAG(block, \ 158 (EVENT_LOG_BLOCK_GET_FLAG(block) | flag) << EVENT_LOG_BLOCK_FLAG_SHIFT) 159 160 typedef enum { 161 SET_DESTINATION_INVALID = -1, 162 SET_DESTINATION_HOST = 0, /* Eventlog buffer is sent out to host once filled. */ 163 SET_DESTINATION_NONE = 1, /* The buffer is not sent out, and it will be overwritten 164 * with new messages. 165 */ 166 SET_DESTINATION_FORCE_FLUSH_TO_HOST = 2, /* Buffers are sent to host once and then the 167 * value is reset back to SET_DESTINATION_NONE. 168 */ 169 SET_DESTINATION_FLUSH_ON_WATERMARK = 3, /* Buffers are sent to host when the watermark is 170 * reached, defined by the feature /chip 171 */ 172 SET_DESTINATION_MAX 173 } event_log_set_destination_t; 174 175 /* sub destination for routing at the host */ 176 typedef enum { 177 SET_SUB_DESTINATION_0 = 0, 178 SET_SUB_DESTINATION_1 = 1, 179 SET_SUB_DESTINATION_2 = 2, 180 SET_SUB_DESTINATION_3 = 3, 181 SET_SUB_DESTINATION_DEFAULT = SET_SUB_DESTINATION_0 182 } event_log_set_sub_destination_t; 183 184 /* There can be multiple event_sets with each logging a set of 185 * associated events (i.e, "fast" and "slow" events). 186 */ 187 typedef struct event_log_set { 188 _EL_BLOCK_PTR first_block; /* Pointer to first event_log block */ 189 _EL_BLOCK_PTR last_block; /* Pointer to last event_log block */ 190 _EL_BLOCK_PTR logtrace_block; /* next block traced */ 191 _EL_BLOCK_PTR cur_block; /* Pointer to current event_log block */ 192 _EL_TYPE_PTR cur_ptr; /* Current event_log pointer */ 193 uint32 blockcount; /* Number of blocks */ 194 uint16 logtrace_count; /* Last count for logtrace */ 195 uint16 blockfill_count; /* Fill count for logtrace */ 196 uint32 timestamp; /* Last timestamp event */ 197 uint32 cyclecount; /* Cycles at last timestamp event */ 198 event_log_set_destination_t destination; 199 uint16 size; /* same size for all buffers in one set */ 200 uint16 flags; 201 uint16 num_preserve_blocks; 202 event_log_set_sub_destination_t sub_destination; 203 uint16 water_mark; /* not used yet: threshold to flush host in percent */ 204 uint32 period; /* period to flush host in ms */ 205 uint32 last_rpt_ts; /* last time to flush in ms */ 206 } event_log_set_t; 207 208 /* Definition of flags in set */ 209 #define EVENT_LOG_SET_SHRINK_ACTIVE (1 << 0) 210 #define EVENT_LOG_SET_CONFIG_PARTIAL_BLK_SEND (0x1 << 1) 211 #define EVENT_LOG_SET_CHECK_LOG_RATE (1 << 2) 212 #define EVENT_LOG_SET_PERIODIC (1 << 3) 213 #define EVENT_LOG_SET_D3PRSV (1 << 4) 214 215 /* Top data structure for access to everything else */ 216 typedef struct event_log_top { 217 uint32 magic; 218 #define EVENT_LOG_TOP_MAGIC 0x474C8669 /* 'EVLG' */ 219 uint32 version; 220 #define EVENT_LOG_VERSION 1 221 uint32 num_sets; 222 uint32 logstrs_size; /* Size of lognums + logstrs area */ 223 uint32 timestamp; /* Last timestamp event */ 224 uint32 cyclecount; /* Cycles at last timestamp event */ 225 _EL_SET_PTR sets; /* Ptr to array of <num_sets> set ptrs */ 226 uint16 log_count; /* Number of event logs from last flush */ 227 uint16 rate_hc; /* Max number of prints per second */ 228 uint32 hc_timestamp; /* Timestamp of last hc window starting */ 229 bool cpu_freq_changed; /* Set to TRUE when CPU freq changed */ 230 bool hostmem_access_enabled; /* Is host memory access enabled for log delivery */ 231 bool event_trace_enabled; /* WLC_E_TRACE enabled/disabled */ 232 } event_log_top_t; 233 234 /* structure of the trailing 3 words in logstrs.bin */ 235 typedef struct { 236 uint32 fw_id; /* FWID will be written by tool later */ 237 uint32 flags; /* 0th bit indicates whether encrypted or not */ 238 /* Keep version and magic last since "header" is appended to the end of logstrs file. */ 239 uint32 version; /* Header version */ 240 uint32 log_magic; /* MAGIC number for verification 'LOGS' */ 241 } logstr_trailer_t; 242 243 /* Data structure of Keeping the Header from logstrs.bin */ 244 typedef struct { 245 uint32 logstrs_size; /* Size of the file */ 246 uint32 rom_lognums_offset; /* Offset to the ROM lognum */ 247 uint32 ram_lognums_offset; /* Offset to the RAM lognum */ 248 uint32 rom_logstrs_offset; /* Offset to the ROM logstr */ 249 uint32 ram_logstrs_offset; /* Offset to the RAM logstr */ 250 uint32 fw_id; /* FWID will be written by tool later */ 251 uint32 flags; /* 0th bit indicates whether encrypted or not */ 252 /* Keep version and magic last since "header" is appended to the end of logstrs file. */ 253 uint32 version; /* Header version */ 254 uint32 log_magic; /* MAGIC number for verification 'LOGS' */ 255 } logstr_header_t; 256 257 /* Data structure of Keeping the Header from logstrs.bin */ 258 typedef struct { 259 uint32 logstrs_size; /* Size of the file */ 260 uint32 rom_lognums_offset; /* Offset to the ROM lognum */ 261 uint32 ram_lognums_offset; /* Offset to the RAM lognum */ 262 uint32 rom_logstrs_offset; /* Offset to the ROM logstr */ 263 uint32 ram_logstrs_offset; /* Offset to the RAM logstr */ 264 /* Keep version and magic last since "header" is appended to the end of logstrs file. */ 265 uint32 version; /* Header version */ 266 uint32 log_magic; /* MAGIC number for verification 'LOGS' */ 267 } logstr_header_v1_t; 268 269 /* Event log configuration table */ 270 typedef struct evt_log_tag_entry { 271 uint16 tag; /* Tag value. */ 272 uint8 set; /* Set number. */ 273 uint8 refcnt; /* Ref_count if sdc is used */ 274 } evt_log_tag_entry_t; 275 276 #ifdef BCMDRIVER 277 /* !!! The following section is for kernel mode code only !!! */ 278 #include <osl_decl.h> 279 280 extern bool d3_preserve_enab; 281 #if defined(ROM_ENAB_RUNTIME_CHECK) 282 #define D3_PRESERVE_ENAB() (d3_preserve_enab) 283 #elif defined(EVENTLOG_D3_PRESERVE_DISABLED) 284 #define D3_PRESERVE_ENAB() (0) 285 #else 286 #define D3_PRESERVE_ENAB() (1) 287 #endif 288 289 #if defined(EVENTLOG_PRSV_PERIODIC) 290 extern bool prsv_periodic_enab; 291 #if defined(ROM_ENAB_RUNTIME_CHECK) 292 #define PRSV_PRD_ENAB() (prsv_periodic_enab) 293 #elif defined(EVENTLOG_PRSV_PERIODIC_DISABLED) 294 #define PRSV_PRD_ENAB() (0) 295 #else 296 #define PRSV_PRD_ENAB() (1) 297 #endif 298 #endif /* EVENTLOG_PRSV_PERIODIC */ 299 300 /* 301 * Use the following macros for generating log events. 302 * 303 * The FAST versions check the enable of the tag before evaluating the arguments and calling the 304 * event_log function. This adds 5 instructions. The COMPACT versions evaluate the arguments 305 * and call the event_log function unconditionally. The event_log function will then skip logging 306 * if this tag is disabled. 307 * 308 * To support easy usage of existing debugging (e.g. msglevel) via macro re-definition there are 309 * two variants of these macros to help. 310 * 311 * First there are the CAST versions. The event_log function normally logs uint32 values or else 312 * they have to be cast to uint32. The CAST versions blindly cast for you so you don't have to edit 313 * any existing code. 314 * 315 * Second there are the PAREN_ARGS versions. These expect the logging format string and arguments 316 * to be enclosed in parentheses. This allows us to make the following mapping of an existing 317 * msglevel macro: 318 * #define WL_ERROR(args) EVENT_LOG_CAST_PAREN_ARGS(EVENT_LOG_TAG_WL_ERROR, args) 319 * 320 * The versions of the macros without FAST or COMPACT in their name are just synonyms for the 321 * COMPACT versions. 322 * 323 * You should use the COMPACT macro (or its synonym) in cases where there is some preceding logic 324 * that prevents the execution of the macro, e.g. WL_ERROR by definition rarely gets executed. 325 * Use the FAST macro in performance sensitive paths. The key concept here is that you should be 326 * assuming that your macro usage is compiled into ROM and can't be changed ... so choose wisely. 327 * 328 */ 329 330 #if !defined(EVENT_LOG_DUMPER) && !defined(DHD_EFI) 331 332 #ifndef EVENT_LOG_COMPILE 333 334 /* Null define if no tracing */ 335 #define EVENT_LOG(tag, fmt, ...) 336 #define EVENT_LOG_FAST(tag, fmt, ...) 337 #define EVENT_LOG_COMPACT(tag, fmt, ...) 338 339 #define EVENT_LOG_CAST(tag, fmt, ...) 340 #define EVENT_LOG_FAST_CAST(tag, fmt, ...) 341 #define EVENT_LOG_COMPACT_CAST(tag, fmt, ...) 342 343 #define EVENT_LOG_CAST_PAREN_ARGS(tag, pargs) 344 #define EVENT_LOG_FAST_CAST_PAREN_ARGS(tag, pargs) 345 #define EVENT_LOG_COMPACT_CAST_PAREN_ARGS(tag, pargs) 346 347 #define EVENT_LOG_IF_READY(tag, fmt, ...) 348 #define EVENT_LOG_IS_ON(tag) 0 349 #define EVENT_LOG_IS_LOG_ON(tag) 0 350 351 #define EVENT_LOG_BUFFER(tag, buf, size) 352 #define EVENT_LOG_PRSRV_FLUSH() 353 #define EVENT_LOG_FORCE_FLUSH_ALL() 354 #define EVENT_LOG_FORCE_FLUSH_PRSRV_LOG_ALL() 355 356 #else /* EVENT_LOG_COMPILE */ 357 358 /* The first few _EVENT_LOGX() macros are special because they can be done more 359 * efficiently this way and they are the common case. Once there are too many 360 * parameters the code size starts to be an issue and a loop is better 361 * The trailing arguments to the _EVENT_LOGX() macros are the format string, 'fmt', 362 * followed by the variable parameters for the format. The format string is not 363 * needed in the event_logX() replacement text, so fmt is dropped in all cases. 364 */ 365 #define _EVENT_LOG0(tag, fmt_num, fmt) \ 366 event_log0(tag, fmt_num) 367 #define _EVENT_LOG1(tag, fmt_num, fmt, t1) \ 368 event_log1(tag, fmt_num, t1) 369 #define _EVENT_LOG2(tag, fmt_num, fmt, t1, t2) \ 370 event_log2(tag, fmt_num, t1, t2) 371 #define _EVENT_LOG3(tag, fmt_num, fmt, t1, t2, t3) \ 372 event_log3(tag, fmt_num, t1, t2, t3) 373 #define _EVENT_LOG4(tag, fmt_num, fmt, t1, t2, t3, t4) \ 374 event_log4(tag, fmt_num, t1, t2, t3, t4) 375 376 /* The rest call the generic routine that takes a count */ 377 #define _EVENT_LOG5(tag, fmt_num, fmt, ...) event_logn(5, tag, fmt_num, __VA_ARGS__) 378 #define _EVENT_LOG6(tag, fmt_num, fmt, ...) event_logn(6, tag, fmt_num, __VA_ARGS__) 379 #define _EVENT_LOG7(tag, fmt_num, fmt, ...) event_logn(7, tag, fmt_num, __VA_ARGS__) 380 #define _EVENT_LOG8(tag, fmt_num, fmt, ...) event_logn(8, tag, fmt_num, __VA_ARGS__) 381 #define _EVENT_LOG9(tag, fmt_num, fmt, ...) event_logn(9, tag, fmt_num, __VA_ARGS__) 382 #define _EVENT_LOGA(tag, fmt_num, fmt, ...) event_logn(10, tag, fmt_num, __VA_ARGS__) 383 #define _EVENT_LOGB(tag, fmt_num, fmt, ...) event_logn(11, tag, fmt_num, __VA_ARGS__) 384 #define _EVENT_LOGC(tag, fmt_num, fmt, ...) event_logn(12, tag, fmt_num, __VA_ARGS__) 385 #define _EVENT_LOGD(tag, fmt_num, fmt, ...) event_logn(13, tag, fmt_num, __VA_ARGS__) 386 #define _EVENT_LOGE(tag, fmt_num, fmt, ...) event_logn(14, tag, fmt_num, __VA_ARGS__) 387 #define _EVENT_LOGF(tag, fmt_num, fmt, ...) event_logn(15, tag, fmt_num, __VA_ARGS__) 388 389 /* Casting low level macros */ 390 #define _EVENT_LOG_CAST0(tag, fmt_num, fmt) \ 391 event_log0(tag, fmt_num) 392 #define _EVENT_LOG_CAST1(tag, fmt_num, fmt, t1) \ 393 event_log1(tag, fmt_num, (uint32)(t1)) 394 #define _EVENT_LOG_CAST2(tag, fmt_num, fmt, t1, t2) \ 395 event_log2(tag, fmt_num, (uint32)(t1), (uint32)(t2)) 396 #define _EVENT_LOG_CAST3(tag, fmt_num, fmt, t1, t2, t3) \ 397 event_log3(tag, fmt_num, (uint32)(t1), (uint32)(t2), (uint32)(t3)) 398 #define _EVENT_LOG_CAST4(tag, fmt_num, fmt, t1, t2, t3, t4) \ 399 event_log4(tag, fmt_num, (uint32)(t1), (uint32)(t2), (uint32)(t3), (uint32)(t4)) 400 401 /* The rest call the generic routine that takes a count */ 402 #define _EVENT_LOG_CAST5(tag, fmt_num, ...) _EVENT_LOG5(tag, fmt_num, __VA_ARGS__) 403 #define _EVENT_LOG_CAST6(tag, fmt_num, ...) _EVENT_LOG6(tag, fmt_num, __VA_ARGS__) 404 #define _EVENT_LOG_CAST7(tag, fmt_num, ...) _EVENT_LOG7(tag, fmt_num, __VA_ARGS__) 405 #define _EVENT_LOG_CAST8(tag, fmt_num, ...) _EVENT_LOG8(tag, fmt_num, __VA_ARGS__) 406 #define _EVENT_LOG_CAST9(tag, fmt_num, ...) _EVENT_LOG9(tag, fmt_num, __VA_ARGS__) 407 #define _EVENT_LOG_CASTA(tag, fmt_num, ...) _EVENT_LOGA(tag, fmt_num, __VA_ARGS__) 408 #define _EVENT_LOG_CASTB(tag, fmt_num, ...) _EVENT_LOGB(tag, fmt_num, __VA_ARGS__) 409 #define _EVENT_LOG_CASTC(tag, fmt_num, ...) _EVENT_LOGC(tag, fmt_num, __VA_ARGS__) 410 #define _EVENT_LOG_CASTD(tag, fmt_num, ...) _EVENT_LOGD(tag, fmt_num, __VA_ARGS__) 411 #define _EVENT_LOG_CASTE(tag, fmt_num, ...) _EVENT_LOGE(tag, fmt_num, __VA_ARGS__) 412 #define _EVENT_LOG_CASTF(tag, fmt_num, ...) _EVENT_LOGF(tag, fmt_num, __VA_ARGS__) 413 414 /* Hack to make the proper routine call when variadic macros get 415 * passed. Note the max of 15 arguments. More than that can't be 416 * handled by the event_log entries anyways so best to catch it at compile 417 * time 418 * 419 * Here is what happens with this macro: when _EVENT_LOG expands this macro, 420 * its __VA_ARGS__ argument is expanded. If __VA_ARGS__ contains only ONE 421 * argument, for example, then F maps to _1, E maps to _2, and so on, so that 422 * N maps to 0, and the macro expands to BASE ## N or BASE ## 0 which is 423 * EVENT_LOG0. If __VA_ARGS__ contains two arguments, then everything is 424 * shifted down by one, because the second argument in __VA_ARGS__ now maps 425 * to _1, so F maps to _2, E maps to _3, and so on, and 1 (instead of 0) maps 426 * to N, and this macro expands to become _EVENT_LOG1. This continues all 427 * the way up until __VA_ARGS__ has 15 arguments, in which case, stuff in 428 * __VA_ARGS__ maps to all of the values _1 through _F, which makes F (in' 429 * the _EVENT_LOG macro) map to N, and this macro then expands to EVENT_LOGF. 430 */ 431 432 #define _EVENT_LOG_VA_NUM_ARGS(BASE, _FMT, _1, _2, _3, _4, _5, _6, _7, _8, _9, \ 433 _A, _B, _C, _D, _E, _F, N, ...) BASE ## N 434 435 /* Take a variable number of args and replace with only the first */ 436 #define FIRST_ARG(a1, ...) a1 437 438 /* base = _EVENT_LOG for no casting 439 * base = _EVENT_LOG_CAST for casting of fmt arguments to uint32. 440 * Only first 4 arguments are cast to uint32. event_logn() is called 441 * if more than 4 arguments are present. This function internally assumes 442 * all arguments are uint32 443 * 444 * The variable args in this call are the format string followed by the variable 445 * parameters for the format. E.g. 446 * 447 * __VA_ARGS__ = "answer: %d", 42 448 * 449 * This means __VA_ARGS__ always has one or more arguments. Guaranteeing a non-empty 450 * __VA_ARGS__ means the special use of " , ## __VA_ARGS__" is not required to deal 451 * with a dangling comma --- the comma will always be followed with at leaset the format 452 * string. The use of ## caused issues when the format args contained a function like 453 * macro that expanded to more than one arg. The ## prevented macro expansion, so the 454 * _EVENT_LOG_VA_NUM_ARGS() calculation of the number of args was incorrect. 455 * Without the ##, the __VA_ARGS__ are macro replaced, and the num args calculation is 456 * accurate. 457 * 458 * This macro is setup so that if __VA_ARGS__ is as short as possible, then the "0" will 459 * map to "N" in the _EVENT_LOG_VA_NUM_ARGS macro, and that macro then expands to become 460 * _EVENT_LOG0. As __VA_ARGS__ gets longer, then the item that gets mapped to "N" gets 461 * pushed further and further up, so that by the time __VA_ARGS__ has 15 additional 462 * arguments, then "F" maps to "N" in the _EVENT_LOG_VA_NUM_ARGS macro. 463 */ 464 #define _EVENT_LOG(base, tag, ...) \ 465 static char logstr[] __attribute__ ((section(".logstrs"))) = FIRST_ARG(__VA_ARGS__); \ 466 static uint32 fmtnum __attribute__ ((section(".lognums"))) = (uint32) &logstr; \ 467 _EVENT_LOG_VA_NUM_ARGS(base, __VA_ARGS__, \ 468 F, E, D, C, B, A, 9, 8, \ 469 7, 6, 5, 4, 3, 2, 1, 0) \ 470 (tag, (int) &fmtnum, __VA_ARGS__) 471 472 #define EVENT_LOG_FAST(tag, ...) \ 473 do { \ 474 if (event_log_tag_sets != NULL) { \ 475 uint8 tag_flag = *(event_log_tag_sets + tag); \ 476 if ((tag_flag & ~EVENT_LOG_TAG_FLAG_SET_MASK) != 0) { \ 477 _EVENT_LOG(_EVENT_LOG, tag, __VA_ARGS__); \ 478 } \ 479 } \ 480 } while (0) 481 482 #define EVENT_LOG_COMPACT(tag, ...) \ 483 do { \ 484 _EVENT_LOG(_EVENT_LOG, tag, __VA_ARGS__); \ 485 } while (0) 486 487 /* Event log macro with casting to uint32 of arguments */ 488 #define EVENT_LOG_FAST_CAST(tag, ...) \ 489 do { \ 490 if (event_log_tag_sets != NULL) { \ 491 uint8 tag_flag = *(event_log_tag_sets + tag); \ 492 if ((tag_flag & ~EVENT_LOG_TAG_FLAG_SET_MASK) != 0) { \ 493 _EVENT_LOG(_EVENT_LOG_CAST, tag, __VA_ARGS__); \ 494 } \ 495 } \ 496 } while (0) 497 498 #define EVENT_LOG_COMPACT_CAST(tag, ...) \ 499 do { \ 500 _EVENT_LOG(_EVENT_LOG_CAST, tag, __VA_ARGS__); \ 501 } while (0) 502 503 #define EVENT_LOG(tag, ...) EVENT_LOG_COMPACT(tag, __VA_ARGS__) 504 505 #define EVENT_LOG_CAST(tag, ...) EVENT_LOG_COMPACT_CAST(tag, __VA_ARGS__) 506 507 #define _EVENT_LOG_REMOVE_PAREN(...) __VA_ARGS__ 508 #define EVENT_LOG_REMOVE_PAREN(args) _EVENT_LOG_REMOVE_PAREN args 509 510 #define EVENT_LOG_CAST_PAREN_ARGS(tag, pargs) \ 511 EVENT_LOG_CAST(tag, EVENT_LOG_REMOVE_PAREN(pargs)) 512 513 #define EVENT_LOG_FAST_CAST_PAREN_ARGS(tag, pargs) \ 514 EVENT_LOG_FAST_CAST(tag, EVENT_LOG_REMOVE_PAREN(pargs)) 515 516 #define EVENT_LOG_COMPACT_CAST_PAREN_ARGS(tag, pargs) \ 517 EVENT_LOG_COMPACT_CAST(tag, EVENT_LOG_REMOVE_PAREN(pargs)) 518 519 /* Minimal event logging. Event log internally calls event_logx() 520 * log return address in caller. 521 * Note that the if(0){..} below is to avoid compiler warnings 522 * due to unused variables caused by this macro 523 */ 524 #define EVENT_LOG_RA(tag, args) \ 525 do { \ 526 if (0) { \ 527 EVENT_LOG_COMPACT_CAST_PAREN_ARGS(tag, args); \ 528 } \ 529 event_log_caller_return_address(tag); \ 530 } while (0) 531 532 #define EVENT_LOG_IF_READY(_tag, ...) \ 533 do { \ 534 if (event_log_is_ready()) { \ 535 EVENT_LOG(_tag, __VA_ARGS__); \ 536 } \ 537 } \ 538 while (0) 539 540 #define EVENT_LOG_IS_ON(tag) (*(event_log_tag_sets + (tag)) & ~EVENT_LOG_TAG_FLAG_SET_MASK) 541 #define EVENT_LOG_IS_LOG_ON(tag) (*(event_log_tag_sets + (tag)) & EVENT_LOG_TAG_FLAG_LOG) 542 543 #define EVENT_LOG_BUFFER(tag, buf, size) event_log_buffer(tag, buf, size) 544 #define EVENT_DUMP event_log_buffer 545 546 /* EVENT_LOG_PRSRV_FLUSH() will be deprecated. Use EVENT_LOG_FORCE_FLUSH_ALL instead */ 547 #define EVENT_LOG_PRSRV_FLUSH() event_log_force_flush_all() 548 #define EVENT_LOG_FORCE_FLUSH_ALL() event_log_force_flush_all() 549 550 #ifdef PRESERVE_LOG 551 #define EVENT_LOG_FORCE_FLUSH_PRSRV_LOG_ALL() event_log_force_flush_preserve_all() 552 #else 553 #define EVENT_LOG_FORCE_FLUSH_PRSRV_LOG_ALL() 554 #endif /* PRESERVE_LOG */ 555 556 extern uint8 *event_log_tag_sets; 557 558 extern int event_log_init(osl_t *osh); 559 extern int event_log_set_init(osl_t *osh, int set_num, int size); 560 extern int event_log_set_expand(osl_t *osh, int set_num, int size); 561 extern int event_log_set_shrink(osl_t *osh, int set_num, int size); 562 563 extern int event_log_tag_start(int tag, int set_num, int flags); 564 extern int event_log_tag_set_retrieve(int tag); 565 extern int event_log_tag_flags_retrieve(int tag); 566 extern int event_log_tag_stop(int tag); 567 568 typedef void (*event_log_logtrace_trigger_fn_t)(void *ctx); 569 void event_log_set_logtrace_trigger_fn(event_log_logtrace_trigger_fn_t fn, void *ctx); 570 571 event_log_top_t *event_log_get_top(void); 572 573 extern int event_log_get(int set_num, int buflen, void *buf); 574 575 extern uint8 *event_log_next_logtrace(int set_num); 576 extern uint32 event_log_logtrace_max_buf_count(int set_num); 577 extern int event_log_set_type(int set_num, uint8 *type, int is_get); 578 extern int event_log_flush_set(wl_el_set_flush_prsrv_t *flush, int is_set); 579 580 extern void event_log0(int tag, int fmtNum); 581 extern void event_log1(int tag, int fmtNum, uint32 t1); 582 extern void event_log2(int tag, int fmtNum, uint32 t1, uint32 t2); 583 extern void event_log3(int tag, int fmtNum, uint32 t1, uint32 t2, uint32 t3); 584 extern void event_log4(int tag, int fmtNum, uint32 t1, uint32 t2, uint32 t3, uint32 t4); 585 extern void event_logn(int num_args, int tag, int fmtNum, ...); 586 #ifdef ROM_COMPAT_MSCH_PROFILER 587 /* For compatibility with ROM, for old msch event log function to pass parameters in stack */ 588 extern void event_logv(int num_args, int tag, int fmtNum, va_list ap); 589 #endif /* ROM_COMPAT_MSCH_PROFILER */ 590 591 extern void event_log_time_sync(uint32 ms); 592 extern bool event_log_time_sync_required(void); 593 extern void event_log_cpu_freq_changed(void); 594 extern void event_log_buffer(int tag, const uint8 *buf, int size); 595 extern void event_log_caller_return_address(int tag); 596 extern int event_log_set_destination_set(int set, event_log_set_destination_t dest); 597 extern event_log_set_destination_t event_log_set_destination_get(int set); 598 extern int event_log_set_sub_destination_set(uint set, event_log_set_sub_destination_t dest); 599 extern event_log_set_sub_destination_t event_log_set_sub_destination_get(uint set); 600 extern int event_log_flush_log_buffer(int set); 601 extern int event_log_force_flush_all(void); 602 extern int event_log_force_flush(int set); 603 604 extern uint16 event_log_get_available_space(int set); 605 extern bool event_log_is_tag_valid(int tag); 606 /* returns number of blocks available for writing */ 607 extern int event_log_free_blocks_get(int set); 608 extern bool event_log_is_ready(void); 609 extern bool event_log_is_preserve_active(uint set); 610 extern uint event_log_get_percentage_available_space(uint set); 611 extern bool event_log_set_watermark_reached(int set_num); 612 613 extern void event_log_set_config(int set, uint32 period, uint16 watermark, uint32 config_flags); 614 #ifdef EVENTLOG_D3_PRESERVE 615 #define EVENT_LOG_PRESERVE_EXPAND_SIZE 5u 616 extern int event_log_preserve_set_shrink(osl_t *osh, int set_num); 617 extern void event_log_d3_preserve_active_set(osl_t* osh, int set, bool active); 618 extern void event_log_d3_prsv_set_all(osl_t *osh, bool active); 619 #endif /* EVENTLOG_D3_PRESERVE */ 620 621 #ifdef EVENTLOG_PRSV_PERIODIC 622 #define EVENT_LOG_SET_SIZE_INVALID 0xFFFFFFFFu 623 #define EVENT_LOG_DEFAULT_PERIOD 3000u 624 extern void event_log_prsv_periodic_wd_trigger(osl_t *osh); 625 #endif /* EVENTLOG_PRSV_PERIODIC */ 626 627 /* Enable/disable rate health check for a set */ 628 #ifdef EVENT_LOG_RATE_HC 629 extern int event_log_enable_hc_for_set(int set_num, bool enable); 630 extern void event_log_set_hc_rate(uint16 num_prints); 631 extern uint16 event_log_get_hc_rate(void); 632 #endif /* EVENT_LOG_RATE_HC */ 633 634 /* Configure a set with ability to send partial log blocks */ 635 extern int event_log_send_partial_block_set(int set_num); 636 637 /* Get number of log blocks associated to a log set */ 638 extern int event_log_num_blocks_get(int set, uint32 *num_blocks); 639 640 /* Get a log buffer of a desired set */ 641 extern int event_log_block_get(int set, uint32 **buf, uint16 *len); 642 extern uint32 event_log_get_maxsets(void); 643 644 /* For all other non-logtrace consumers */ 645 extern int event_log_set_is_valid(int set); 646 647 /* To be used by logtrace only */ 648 extern int event_log_get_num_sets(void); 649 650 /* Given a buffer, return to which set it belongs to */ 651 extern int event_log_get_set_for_buffer(const void *buf); 652 653 extern int event_log_flush_multiple_sets(const int *sets, uint16 num_sets); 654 extern int event_log_force_flush_preserve_all(void); 655 extern int event_log_get_iovar_handler(int set); 656 extern int event_log_enable_hostmem_access(bool hostmem_access_enabled); 657 extern int event_log_enable_event_trace(bool event_trace_enabled); 658 #endif /* EVENT_LOG_COMPILE */ 659 660 #endif /* !EVENT_LOG_DUMPER && !DHD_EFI */ 661 662 #endif /* BCMDRIVER */ 663 664 #endif /* __ASSEMBLER__ */ 665 666 #endif /* _EVENT_LOG_H_ */ 667