1 /* 2 * EVENT_LOG system definitions 3 * 4 * Copyright (C) 1999-2019, 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 16 * of the license of that module. An independent module is a module which is 17 * not derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * Notwithstanding the above, under no circumstances may you combine this 21 * software in any way with any other Broadcom software provided under a license 22 * other than the GPL, without Broadcom's express prior written consent. 23 * 24 * 25 * <<Broadcom-WL-IPTag/Open:>> 26 * 27 * $Id: event_log.h 717896 2017-08-28 21:56:11Z $ 28 */ 29 30 #ifndef _EVENT_LOG_H_ 31 #define _EVENT_LOG_H_ 32 33 #include <typedefs.h> 34 #include <event_log_set.h> 35 #include <event_log_tag.h> 36 #include <event_log_payload.h> 37 #include <osl_decl.h> 38 39 /* logstrs header */ 40 #define LOGSTRS_MAGIC 0x4C4F4753 41 #define LOGSTRS_VERSION 0x1 42 43 /* We make sure that the block size will fit in a single packet 44 * (allowing for a bit of overhead on each packet 45 */ 46 #if defined(BCMPCIEDEV) 47 #define EVENT_LOG_MAX_BLOCK_SIZE 1648 48 #else 49 #define EVENT_LOG_MAX_BLOCK_SIZE 1400 50 #endif // endif 51 #define EVENT_LOG_WL_BLOCK_SIZE 0x200 52 #define EVENT_LOG_PSM_BLOCK_SIZE 0x200 53 #define EVENT_LOG_BUS_BLOCK_SIZE 0x200 54 #define EVENT_LOG_ERROR_BLOCK_SIZE 0x200 55 /* Maximum event log record payload size = 1016 bytes or 254 words. */ 56 #define EVENT_LOG_MAX_RECORD_PAYLOAD_SIZE 254 57 58 /* 59 * There are multiple levels of objects define here: 60 * event_log_set - a set of buffers 61 * event log groups - every event log call is part of just one. All 62 * event log calls in a group are handled the 63 * same way. Each event log group is associated 64 * with an event log set or is off. 65 */ 66 67 #ifndef __ASSEMBLER__ 68 69 /* On the external system where the dumper is we need to make sure 70 * that these types are the same size as they are on the ARM the 71 * produced them 72 */ 73 #ifdef EVENT_LOG_DUMPER 74 #define _EL_BLOCK_PTR uint32 75 #define _EL_TYPE_PTR uint32 76 #define _EL_SET_PTR uint32 77 #define _EL_TOP_PTR uint32 78 #else 79 #define _EL_BLOCK_PTR struct event_log_block * 80 #define _EL_TYPE_PTR uint32 * 81 #define _EL_SET_PTR struct event_log_set ** 82 #define _EL_TOP_PTR struct event_log_top * 83 #endif /* EVENT_LOG_DUMPER */ 84 85 /* Event log sets (a logical circurlar buffer) consist of one or more 86 * event_log_blocks. The blocks themselves form a logical circular 87 * list. The log entries are placed in each event_log_block until it 88 * is full. Logging continues with the next event_log_block in the 89 * event_set until the last event_log_block is reached and then 90 * logging starts over with the first event_log_block in the 91 * event_set. 92 */ 93 typedef struct event_log_block { 94 _EL_BLOCK_PTR next_block; 95 _EL_BLOCK_PTR prev_block; 96 _EL_TYPE_PTR end_ptr; 97 98 /* Start of packet sent for log tracing */ 99 uint16 pktlen; /* Size of rest of block */ 100 uint16 count; /* Logtrace counter */ 101 uint32 extra_hdr_info; /* LSB: 6 bits set id. MSB 24 bits reserved */ 102 uint32 event_logs; 103 } event_log_block_t; 104 #define EVENT_LOG_BLOCK_HDRLEN 8 /* pktlen 2 + count 2 + extra_hdr_info 4 */ 105 106 #define EVENT_LOG_BLOCK_LEN 12 107 108 typedef enum { 109 SET_DESTINATION_INVALID = -1, 110 SET_DESTINATION_HOST = 0, 111 SET_DESTINATION_NONE = 1, 112 SET_DESTINATION_MAX 113 } event_log_set_destination_t; 114 115 /* There can be multiple event_sets with each logging a set of 116 * associated events (i.e, "fast" and "slow" events). 117 */ 118 typedef struct event_log_set { 119 _EL_BLOCK_PTR first_block; /* Pointer to first event_log block */ 120 _EL_BLOCK_PTR last_block; /* Pointer to last event_log block */ 121 _EL_BLOCK_PTR logtrace_block; /* next block traced */ 122 _EL_BLOCK_PTR cur_block; /* Pointer to current event_log block */ 123 _EL_TYPE_PTR cur_ptr; /* Current event_log pointer */ 124 uint32 blockcount; /* Number of blocks */ 125 uint16 logtrace_count; /* Last count for logtrace */ 126 uint16 blockfill_count; /* Fill count for logtrace */ 127 uint32 timestamp; /* Last timestamp event */ 128 uint32 cyclecount; /* Cycles at last timestamp event */ 129 event_log_set_destination_t destination; 130 uint16 size; /* same size for all buffers in one set */ 131 } event_log_set_t; 132 133 /* logstr_hdr_flags */ 134 #define LOGSTRS_ENCRYPTED 0x1 135 136 /* Top data structure for access to everything else */ 137 typedef struct event_log_top { 138 uint32 magic; 139 #define EVENT_LOG_TOP_MAGIC 0x474C8669 /* 'EVLG' */ 140 uint32 version; 141 #define EVENT_LOG_VERSION 1 142 uint32 num_sets; 143 uint32 logstrs_size; /* Size of lognums + logstrs area */ 144 uint32 timestamp; /* Last timestamp event */ 145 uint32 cyclecount; /* Cycles at last timestamp event */ 146 _EL_SET_PTR sets; /* Ptr to array of <num_sets> set ptrs */ 147 } event_log_top_t; 148 149 /* structure of the trailing 3 words in logstrs.bin */ 150 typedef struct { 151 uint32 fw_id; /* FWID will be written by tool later */ 152 uint32 flags; /* 0th bit indicates whether encrypted or not */ 153 /* Keep version and magic last since "header" is appended to the end of 154 * logstrs file. */ 155 uint32 version; /* Header version */ 156 uint32 log_magic; /* MAGIC number for verification 'LOGS' */ 157 } logstr_trailer_t; 158 159 /* Data structure of Keeping the Header from logstrs.bin */ 160 typedef struct { 161 uint32 logstrs_size; /* Size of the file */ 162 uint32 rom_lognums_offset; /* Offset to the ROM lognum */ 163 uint32 ram_lognums_offset; /* Offset to the RAM lognum */ 164 uint32 rom_logstrs_offset; /* Offset to the ROM logstr */ 165 uint32 ram_logstrs_offset; /* Offset to the RAM logstr */ 166 logstr_trailer_t trailer; 167 } logstr_header_t; 168 169 /* Ver 1 Header from logstrs.bin */ 170 typedef struct { 171 uint32 logstrs_size; /* Size of the file */ 172 uint32 rom_lognums_offset; /* Offset to the ROM lognum */ 173 uint32 ram_lognums_offset; /* Offset to the RAM lognum */ 174 uint32 rom_logstrs_offset; /* Offset to the ROM logstr */ 175 uint32 ram_logstrs_offset; /* Offset to the RAM logstr */ 176 /* Keep version and magic last since "header" is appended to the end of 177 * logstrs file. */ 178 uint32 version; /* Header version */ 179 uint32 log_magic; /* MAGIC number for verification 'LOGS' */ 180 } logstr_header_v1_t; 181 182 /* 183 * Use the following macros for generating log events. 184 * 185 * The FAST versions check the enable of the tag before evaluating the arguments 186 * and calling the event_log function. This adds 5 instructions. The COMPACT 187 * versions evaluate the arguments and call the event_log function 188 * unconditionally. The event_log function will then skip logging if this tag 189 * is disabled. 190 * 191 * To support easy usage of existing debugging (e.g. msglevel) via macro 192 * re-definition there are two variants of these macros to help. 193 * 194 * First there are the CAST versions. The event_log function normally logs 195 * uint32 values or else they have to be cast to uint32. The CAST versions 196 * blindly cast for you so you don't have to edit any existing code. 197 * 198 * Second there are the PAREN_ARGS versions. These expect the logging format 199 * string and arguments to be enclosed in parentheses. This allows us to make 200 * the following mapping of an existing msglevel macro: #define WL_ERROR(args) 201 * EVENT_LOG_CAST_PAREN_ARGS(EVENT_LOG_TAG_WL_ERROR, args) 202 * 203 * The versions of the macros without FAST or COMPACT in their name are just 204 * synonyms for the COMPACT versions. 205 * 206 * You should use the COMPACT macro (or its synonym) in cases where there is 207 * some preceding logic that prevents the execution of the macro, e.g. WL_ERROR 208 * by definition rarely gets executed. Use the FAST macro in performance 209 * sensitive paths. The key concept here is that you should be assuming that 210 * your macro usage is compiled into ROM and can't be changed ... so choose 211 * wisely. 212 * 213 */ 214 215 #if !defined(EVENT_LOG_DUMPER) 216 217 #ifndef EVENT_LOG_COMPILE 218 219 /* Null define if no tracing */ 220 #define EVENT_LOG(format, ...) 221 #define EVENT_LOG_FAST(tag, fmt, ...) 222 #define EVENT_LOG_COMPACT(tag, fmt, ...) 223 224 #define EVENT_LOG_CAST(tag, fmt, ...) 225 #define EVENT_LOG_FAST_CAST(tag, fmt, ...) 226 #define EVENT_LOG_COMPACT_CAST(tag, fmt, ...) 227 228 #define EVENT_LOG_CAST_PAREN_ARGS(tag, pargs) 229 #define EVENT_LOG_FAST_CAST_PAREN_ARGS(tag, pargs) 230 #define EVENT_LOG_COMPACT_CAST_PAREN_ARGS(tag, pargs) 231 232 #define EVENT_LOG_IS_ON(tag) 0 233 #define EVENT_LOG_IS_LOG_ON(tag) 0 234 235 #define EVENT_LOG_BUFFER(tag, buf, size) 236 237 #else /* EVENT_LOG_COMPILE */ 238 239 /* The first few are special because they can be done more efficiently 240 * this way and they are the common case. Once there are too many 241 * parameters the code size starts to be an issue and a loop is better 242 */ 243 #define _EVENT_LOG0(tag, fmt_num) event_log0(tag, fmt_num) 244 #define _EVENT_LOG1(tag, fmt_num, t1) event_log1(tag, fmt_num, t1) 245 #define _EVENT_LOG2(tag, fmt_num, t1, t2) event_log2(tag, fmt_num, t1, t2) 246 #define _EVENT_LOG3(tag, fmt_num, t1, t2, t3) \ 247 event_log3(tag, fmt_num, t1, t2, t3) 248 #define _EVENT_LOG4(tag, fmt_num, t1, t2, t3, t4) \ 249 event_log4(tag, fmt_num, t1, t2, t3, t4) 250 251 /* The rest call the generic routine that takes a count */ 252 #define _EVENT_LOG5(tag, fmt_num, ...) event_logn(5, tag, fmt_num, __VA_ARGS__) 253 #define _EVENT_LOG6(tag, fmt_num, ...) event_logn(6, tag, fmt_num, __VA_ARGS__) 254 #define _EVENT_LOG7(tag, fmt_num, ...) event_logn(7, tag, fmt_num, __VA_ARGS__) 255 #define _EVENT_LOG8(tag, fmt_num, ...) event_logn(8, tag, fmt_num, __VA_ARGS__) 256 #define _EVENT_LOG9(tag, fmt_num, ...) event_logn(9, tag, fmt_num, __VA_ARGS__) 257 #define _EVENT_LOGA(tag, fmt_num, ...) event_logn(10, tag, fmt_num, __VA_ARGS__) 258 #define _EVENT_LOGB(tag, fmt_num, ...) event_logn(11, tag, fmt_num, __VA_ARGS__) 259 #define _EVENT_LOGC(tag, fmt_num, ...) event_logn(12, tag, fmt_num, __VA_ARGS__) 260 #define _EVENT_LOGD(tag, fmt_num, ...) event_logn(13, tag, fmt_num, __VA_ARGS__) 261 #define _EVENT_LOGE(tag, fmt_num, ...) event_logn(14, tag, fmt_num, __VA_ARGS__) 262 #define _EVENT_LOGF(tag, fmt_num, ...) event_logn(15, tag, fmt_num, __VA_ARGS__) 263 264 /* Casting low level macros */ 265 #define _EVENT_LOG_CAST0(tag, fmt_num) event_log0(tag, fmt_num) 266 #define _EVENT_LOG_CAST1(tag, fmt_num, t1) \ 267 event_log1(tag, fmt_num, (uint32)(t1)) 268 #define _EVENT_LOG_CAST2(tag, fmt_num, t1, t2) \ 269 event_log2(tag, fmt_num, (uint32)(t1), (uint32)(t2)) 270 #define _EVENT_LOG_CAST3(tag, fmt_num, t1, t2, t3) \ 271 event_log3(tag, fmt_num, (uint32)(t1), (uint32)(t2), (uint32)(t3)) 272 #define _EVENT_LOG_CAST4(tag, fmt_num, t1, t2, t3, t4) \ 273 event_log4(tag, fmt_num, (uint32)(t1), (uint32)(t2), (uint32)(t3), \ 274 (uint32)(t4)) 275 276 /* The rest call the generic routine that takes a count */ 277 #define _EVENT_LOG_CAST5(tag, fmt_num, ...) \ 278 _EVENT_LOG5(tag, fmt_num, __VA_ARGS__) 279 #define _EVENT_LOG_CAST6(tag, fmt_num, ...) \ 280 _EVENT_LOG6(tag, fmt_num, __VA_ARGS__) 281 #define _EVENT_LOG_CAST7(tag, fmt_num, ...) \ 282 _EVENT_LOG7(tag, fmt_num, __VA_ARGS__) 283 #define _EVENT_LOG_CAST8(tag, fmt_num, ...) \ 284 _EVENT_LOG8(tag, fmt_num, __VA_ARGS__) 285 #define _EVENT_LOG_CAST9(tag, fmt_num, ...) \ 286 _EVENT_LOG9(tag, fmt_num, __VA_ARGS__) 287 #define _EVENT_LOG_CASTA(tag, fmt_num, ...) \ 288 _EVENT_LOGA(tag, fmt_num, __VA_ARGS__) 289 #define _EVENT_LOG_CASTB(tag, fmt_num, ...) \ 290 _EVENT_LOGB(tag, fmt_num, __VA_ARGS__) 291 #define _EVENT_LOG_CASTC(tag, fmt_num, ...) \ 292 _EVENT_LOGC(tag, fmt_num, __VA_ARGS__) 293 #define _EVENT_LOG_CASTD(tag, fmt_num, ...) \ 294 _EVENT_LOGD(tag, fmt_num, __VA_ARGS__) 295 #define _EVENT_LOG_CASTE(tag, fmt_num, ...) \ 296 _EVENT_LOGE(tag, fmt_num, __VA_ARGS__) 297 #define _EVENT_LOG_CASTF(tag, fmt_num, ...) \ 298 _EVENT_LOGF(tag, fmt_num, __VA_ARGS__) 299 300 /* Hack to make the proper routine call when variadic macros get 301 * passed. Note the max of 15 arguments. More than that can't be 302 * handled by the event_log entries anyways so best to catch it at compile 303 * time 304 */ 305 306 #define _EVENT_LOG_VA_NUM_ARGS(F, _1, _2, _3, _4, _5, _6, _7, _8, _9, _A, _B, \ 307 _C, _D, _E, _F, N, ...) \ 308 F##N 309 310 /* cast = _EVENT_LOG for no casting 311 * cast = _EVENT_LOG_CAST for casting of fmt arguments to uint32. 312 * Only first 4 arguments are casted to uint32. event_logn() is called 313 * if more than 4 arguments are present. This function internally assumes 314 * all arguments are uint32 315 */ 316 #define _EVENT_LOG(cast, tag, fmt, ...) \ 317 static char logstr[] __attribute__((section(".logstrs"))) = fmt; \ 318 static uint32 fmtnum __attribute__((section(".lognums"))) = \ 319 (uint32)&logstr; \ 320 _EVENT_LOG_VA_NUM_ARGS(cast, ##__VA_ARGS__, F, E, D, C, B, A, 9, 8, 7, 6, \ 321 5, 4, 3, 2, 1, 0) \ 322 (tag, (int)&fmtnum, ##__VA_ARGS__) 323 324 #define EVENT_LOG_FAST(tag, fmt, ...) \ 325 do { \ 326 if (event_log_tag_sets != NULL) { \ 327 uint8 tag_flag = *(event_log_tag_sets + tag); \ 328 if ((tag_flag & ~EVENT_LOG_TAG_FLAG_SET_MASK) != 0) { \ 329 _EVENT_LOG(_EVENT_LOG, tag, fmt, ##__VA_ARGS__); \ 330 } \ 331 } \ 332 } while (0) 333 334 #define EVENT_LOG_COMPACT(tag, fmt, ...) \ 335 do { \ 336 _EVENT_LOG(_EVENT_LOG, tag, fmt, ##__VA_ARGS__); \ 337 } while (0) 338 339 /* Event log macro with casting to uint32 of arguments */ 340 #define EVENT_LOG_FAST_CAST(tag, fmt, ...) \ 341 do { \ 342 if (event_log_tag_sets != NULL) { \ 343 uint8 tag_flag = *(event_log_tag_sets + tag); \ 344 if ((tag_flag & ~EVENT_LOG_TAG_FLAG_SET_MASK) != 0) { \ 345 _EVENT_LOG(_EVENT_LOG_CAST, tag, fmt, ##__VA_ARGS__); \ 346 } \ 347 } \ 348 } while (0) 349 350 #define EVENT_LOG_COMPACT_CAST(tag, fmt, ...) \ 351 do { \ 352 _EVENT_LOG(_EVENT_LOG_CAST, tag, fmt, ##__VA_ARGS__); \ 353 } while (0) 354 355 #define EVENT_LOG(tag, fmt, ...) EVENT_LOG_COMPACT(tag, fmt, ##__VA_ARGS__) 356 357 #define EVENT_LOG_CAST(tag, fmt, ...) \ 358 EVENT_LOG_COMPACT_CAST(tag, fmt, ##__VA_ARGS__) 359 360 #define _EVENT_LOG_REMOVE_PAREN(...) __VA_ARGS__ 361 #define EVENT_LOG_REMOVE_PAREN(args) _EVENT_LOG_REMOVE_PAREN args 362 363 #define EVENT_LOG_CAST_PAREN_ARGS(tag, pargs) \ 364 EVENT_LOG_CAST(tag, EVENT_LOG_REMOVE_PAREN(pargs)) 365 366 #define EVENT_LOG_FAST_CAST_PAREN_ARGS(tag, pargs) \ 367 EVENT_LOG_FAST_CAST(tag, EVENT_LOG_REMOVE_PAREN(pargs)) 368 369 #define EVENT_LOG_COMPACT_CAST_PAREN_ARGS(tag, pargs) \ 370 EVENT_LOG_COMPACT_CAST(tag, EVENT_LOG_REMOVE_PAREN(pargs)) 371 372 /* Minimal event logging. Event log internally calls event_logx() 373 * log return address in caller. 374 * Note that the if(0){..} below is to avoid compiler warnings 375 * due to unused variables caused by this macro 376 */ 377 #define EVENT_LOG_RA(tag, args) \ 378 do { \ 379 if (0) { \ 380 EVENT_LOG_COMPACT_CAST_PAREN_ARGS(tag, args); \ 381 } \ 382 event_log_caller_return_address(tag); \ 383 } while (0) 384 385 #define EVENT_LOG_IS_ON(tag) \ 386 (*(event_log_tag_sets + (tag)) & ~EVENT_LOG_TAG_FLAG_SET_MASK) 387 #define EVENT_LOG_IS_LOG_ON(tag) \ 388 (*(event_log_tag_sets + (tag)) & EVENT_LOG_TAG_FLAG_LOG) 389 390 #define EVENT_LOG_BUFFER(tag, buf, size) event_log_buffer(tag, buf, size) 391 #define EVENT_DUMP event_log_buffer 392 393 extern uint8 *event_log_tag_sets; 394 395 extern int event_log_init(osl_t *osh); 396 extern int event_log_set_init(osl_t *osh, int set_num, int size); 397 extern int event_log_set_expand(osl_t *osh, int set_num, int size); 398 extern int event_log_set_shrink(osl_t *osh, int set_num, int size); 399 400 extern int event_log_tag_start(int tag, int set_num, int flags); 401 extern int event_log_tag_set_retrieve(int tag); 402 extern int event_log_tag_stop(int tag); 403 404 typedef void (*event_log_logtrace_trigger_fn_t)(void *ctx); 405 void event_log_set_logtrace_trigger_fn(event_log_logtrace_trigger_fn_t fn, 406 void *ctx); 407 408 event_log_top_t *event_log_get_top(void); 409 410 extern int event_log_get(int set_num, int buflen, void *buf); 411 412 extern uint8 *event_log_next_logtrace(int set_num); 413 414 extern void event_log0(int tag, int fmtNum); 415 extern void event_log1(int tag, int fmtNum, uint32 t1); 416 extern void event_log2(int tag, int fmtNum, uint32 t1, uint32 t2); 417 extern void event_log3(int tag, int fmtNum, uint32 t1, uint32 t2, uint32 t3); 418 extern void event_log4(int tag, int fmtNum, uint32 t1, uint32 t2, uint32 t3, 419 uint32 t4); 420 extern void event_logn(int num_args, int tag, int fmtNum, ...); 421 422 extern void event_log_time_sync(uint32 ms); 423 extern void event_log_buffer(int tag, uint8 *buf, int size); 424 extern void event_log_caller_return_address(int tag); 425 extern int event_log_set_destination_set(int set, 426 event_log_set_destination_t dest); 427 extern event_log_set_destination_t event_log_set_destination_get(int set); 428 extern int event_log_flush_log_buffer(int set); 429 extern uint16 event_log_get_available_space(int set); 430 extern bool event_log_is_set_configured(int set_num); 431 extern bool event_log_is_tag_valid(int tag); 432 /* returns number of blocks available for writing */ 433 extern int event_log_free_blocks_get(int set); 434 extern bool event_log_is_ready(void); 435 436 #endif /* EVENT_LOG_DUMPER */ 437 438 #endif /* EVENT_LOG_COMPILE */ 439 440 #endif /* __ASSEMBLER__ */ 441 442 #endif /* _EVENT_LOG_H_ */ 443