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