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