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