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