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