blob: 19e156ea988764e03db5ea71f3d6ec10f7b2dbef [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2016:DUAL/GPL:standard
3
4 Broadcom Proprietary and Confidential.(c) 2016 Broadcom
5 All Rights Reserved
6
7Unless you and Broadcom execute a separate written software license
8agreement governing use of this software, this software is licensed
9to you under the terms of the GNU General Public License version 2
10(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
11with the following added to such license:
12
13 As a special exception, the copyright holders of this software give
14 you permission to link this software with independent modules, and
15 to copy and distribute the resulting executable under terms of your
16 choice, provided that you also meet, for each linked independent
17 module, the terms and conditions of the license of that module.
18 An independent module is a module which is not derived from this
19 software. The special exception does not apply to any modifications
20 of the software.
21
22Not withstanding the above, under no circumstances may you combine
23this software in any way with any other Broadcom software provided
24under a license other than the GPL, without Broadcom's express prior
25written consent.
26
27:>
28 */
29
30#ifndef __BCM_DEV_LOG_H_
31#define __BCM_DEV_LOG_H_
32
33#ifdef ENABLE_LOG
34
35#include <bcmos_system.h>
36#include "bcm_dev_log_task.h"
37#ifdef ENABLE_CLI
38#include "bcm_dev_log_cli.h"
39#endif
40
41/********************************************/
42/* */
43/* Log macros */
44/* */
45/********************************************/
46
47#define MACRO_ARG_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,N,...) N
48#define MACROS_ARGS_SEQUENCE 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
49#define MACRO_NUM_ARGS_HELPER(...) MACRO_ARG_N(__VA_ARGS__)
50#define MACRO_NUM_ARGS(...) MACRO_NUM_ARGS_HELPER(__VA_ARGS__, MACROS_ARGS_SEQUENCE)
51
52/* IMPORTANT! DO NOT USE THESE MACROS, USE BCM_LOG ONLY ! */
53/* These macros force number of arguments in compile time. A single macro for each number of arguments (including the format) */
54#ifdef __BASENAME__
55#define _BCM_LOG_ARGS1(level, id, flags, ...) \
56 bcm_dev_log_log(id, level, flags, STRINGIFY_EXPAND(__BASENAME__) " " STRINGIFY_EXPAND(__LINE__) "| " __VA_ARGS__)
57#else
58#define _BCM_LOG_ARGS1(level, id, flags, ...) \
59 bcm_dev_log_log(id, level, flags | BCM_LOG_FLAG_FILENAME_IN_FMT, __FILE__ " " STRINGIFY_EXPAND(__LINE__) "| " __VA_ARGS__)
60#endif
61#define _BCM_LOG_ARGS2(...) _BCM_LOG_ARGS1(__VA_ARGS__)
62#define _BCM_LOG_ARGS3(...) _BCM_LOG_ARGS1(__VA_ARGS__)
63#define _BCM_LOG_ARGS4(...) _BCM_LOG_ARGS1(__VA_ARGS__)
64#define _BCM_LOG_ARGS5(...) _BCM_LOG_ARGS1(__VA_ARGS__)
65#define _BCM_LOG_ARGS6(...) _BCM_LOG_ARGS1(__VA_ARGS__)
66#define _BCM_LOG_ARGS7(...) _BCM_LOG_ARGS1(__VA_ARGS__)
67#define _BCM_LOG_ARGS8(...) _BCM_LOG_ARGS1(__VA_ARGS__)
68#define _BCM_LOG_ARGS9(...) _BCM_LOG_ARGS1(__VA_ARGS__)
69#define _BCM_LOG_ARGS10(...) _BCM_LOG_ARGS1(__VA_ARGS__)
70#define _BCM_LOG_ARGS11(...) _BCM_LOG_ARGS1(__VA_ARGS__)
71#define _BCM_LOG_ARGS12(...) _BCM_LOG_ARGS1(__VA_ARGS__)
72#define _BCM_LOG_ARGS13(...) _BCM_LOG_ARGS1(__VA_ARGS__)
73#define _BCM_LOG_ARGS14(...) _BCM_LOG_ARGS1(__VA_ARGS__)
74#define _BCM_LOG_ARGS15(...) _BCM_LOG_ARGS1(__VA_ARGS__)
75#define _BCM_LOG_ARGS16(...) _BCM_LOG_ARGS1(__VA_ARGS__)
76#define _BCM_LOG_ARGS17(...) _BCM_LOG_ARGS1(__VA_ARGS__)
77#define _BCM_LOG_ARGS18(...) _BCM_LOG_ARGS1(__VA_ARGS__)
78#define _BCM_LOG_ARGS19(...) _BCM_LOG_ARGS1(__VA_ARGS__)
79#define _BCM_LOG_ARGS20(...) _BCM_LOG_ARGS1(__VA_ARGS__)
80#define _BCM_LOG_ARGS21(...) _BCM_LOG_ARGS1(__VA_ARGS__)
81#define _BCM_LOG_ARGS22(...) _BCM_LOG_ARGS1(__VA_ARGS__)
82#define _BCM_LOG_ARGS23(...) _BCM_LOG_ARGS1(__VA_ARGS__)
83#define _BCM_LOG_ARGS24(...) _BCM_LOG_ARGS1(__VA_ARGS__)
84#define _BCM_LOG_ARGS25(...) _BCM_LOG_ARGS1(__VA_ARGS__)
85#define _BCM_LOG_ARGS26(...) _BCM_LOG_ARGS1(__VA_ARGS__)
86#define _BCM_LOG_ARGS27(...) _BCM_LOG_ARGS1(__VA_ARGS__)
87#define _BCM_LOG_ARGS28(...) _BCM_LOG_ARGS1(__VA_ARGS__)
88#define _BCM_LOG_ARGS29(...) _BCM_LOG_ARGS1(__VA_ARGS__)
89#define _BCM_LOG_ARGS30(...) _BCM_LOG_ARGS1(__VA_ARGS__)
90#define _BCM_LOG_ARGS31(...) _BCM_LOG_ARGS1(__VA_ARGS__)
91#define _BCM_LOG_ARGS32(...) _BCM_LOG_ARGS1(__VA_ARGS__)
92#define _BCM_LOG_ARGS33(...) _BCM_LOG_ARGS1(__VA_ARGS__)
93#define _BCM_LOG_ARGS34(...) _BCM_LOG_ARGS1(__VA_ARGS__)
94#define _BCM_LOG_ARGS35(...) _BCM_LOG_ARGS1(__VA_ARGS__)
95#define _BCM_LOG_ARGS36(...) _BCM_LOG_ARGS1(__VA_ARGS__)
96#define _BCM_LOG_ARGS(n) _BCM_LOG_ARGS##n
97#define _BCM_LOG_EXPAND(n,...) _BCM_LOG_ARGS(n) (__VA_ARGS__)
98
99/*
100 * IMPORTANT! you should use only this macro for logging
101 *
102 * 1. Support prints up to DEV_LOG_MAX_ARGS parameters each with maximum size of 32bits
103 * 2. Support also prints of arguments with size 64bits but each one counted as two arguments of 32bits,
104 * so you can only print up to (DEV_LOG_MAX_ARGS/2) arguments of 64bits.
105 * Mix of 64 and 32 are allowed as long you don't exceed DEV_LOG_MAX_ARGS.
106 * 3. Any possible combination of mix 32 and 64 arguments are allowed.
107 */
108#define BCM_LOG(level, id, ...) _BCM_LOG_EXPAND(MACRO_NUM_ARGS(__VA_ARGS__), DEV_LOG_LEVEL_##level, id, 0, __VA_ARGS__)
109/* Same as BCM_LOG(), but overrides BCM_LOG() default behavior by letting the format be done in the context of the caller task. This allows using stack/heap strings
110 * for fmt and args. See comment for BCM_LOG_FLAG_CALLER_FMT. */
111#define BCM_LOG_CALLER_FMT(level, id, ...) _BCM_LOG_EXPAND(MACRO_NUM_ARGS(__VA_ARGS__), DEV_LOG_LEVEL_##level, id, BCM_LOG_FLAG_CALLER_FMT, __VA_ARGS__)
112
113/* Same as BCM_LOG(), but the level is not given as a token for concatenation, but as a regular enum. */
114#define BCM_LOG_LEVEL(level, id, ...) _BCM_LOG_EXPAND(MACRO_NUM_ARGS(__VA_ARGS__), level, id, 0, __VA_ARGS__)
115
116#define BCM_LOG_FLAG_NONE 0
117#define BCM_LOG_FLAG_NO_HEADER (1 << 0) /* Avoid inserting header to each message. */
118#define BCM_LOG_FLAG_CALLER_FMT (1 << 1) /* The log message will be formatted in the context of the caller task, not the logger task (override default behavior).
119 * This has a penalty - bcm_dev_log_log() becomes slower. */
120#define BCM_LOG_FLAG_FILENAME_IN_FMT (1 << 2) /* Indicates that __FILE__ is inserted at the beginning of the message format. */
121#define BCM_LOG_FLAG_DONT_SKIP_PRINT (1 << 3) /* The message should always be printed even if the msg pool is nearly full. */
122
123/********************************************/
124/* */
125/* Callbacks functions */
126/* */
127/********************************************/
128
129/********************************************/
130/* */
131/* Functions prototypes */
132/* */
133/********************************************/
134
135const char *dev_log_basename(const char *str);
136
137/****************************************************************************************/
138/* */
139/* Name: bcm_dev_log_log */
140/* Abstract: Log function */
141/* It is better using the macros and not the function directly. */
142/* */
143/* Arguments: */
144/* - xi_id - The Log ID this message is connected to. */
145/* (The ID we got form bcm_dev_log_id_register) */
146/* - xi_log_level - The Log level of this message */
147/* - xi_flags - Can be one of BCM_LOG_FLAG_XXX above. */
148/* - fmt - The print format */
149/* Note: The default behavior is to format the string in the logger */
150/* task context, not the caller task context, to reduce the */
151/* penalty of calling bcm_dev_log_log(). This means 'fmt' can */
152/* point only to strings in data segment, but not to head/stack. */
153/* You can override this behavior with BCM_LOG_FLAG_CALLER_FMT. */
154/* */
155/* - param1 - Format parameter No. 1. Like 'fmt', can reside only in data */
156/* segment, unless choosing BCM_LOG_FLAG_CALLER_FMT */
157/* - ... */
158/* - paramN - Format parameter No. N */
159/* */
160/* IMPORTANT! */
161/* 1. The function bcm_dev_log_log() must have even number of arguments before the '...'*/
162/* This comes from the 64bits limitation that must be align to 8bytes in some */
163/* platforms who doesn't support unaligned access, */
164/* on xponsw (x86) it doesn't matter but on device (arm) you must have that. */
165/* */
166/****************************************************************************************/
167void bcm_dev_log_log(dev_log_id xi_id,
168 bcm_dev_log_level xi_log_level,
169 uint32_t xi_flags,
170 const char *fmt,
171 ...) __attribute__((format(__printf__, 4, 5))); /* compiler attribute to check as printf style for arguments 4 (fmt) and 5 (all other) */
172
173void bcm_dev_log_vlog(dev_log_id xi_id,
174 bcm_dev_log_level xi_log_level,
175 uint32_t xi_flags,
176 const char *fmt,
177 va_list args);
178
179typedef enum
180{
181 DEV_LOG_RATE_LIMIT_ID_NONE,
182 DEV_LOG_RATE_LIMIT_ID_BWS_DBA_BD_ADD_ALLOC_FAILED,
183 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_RT_ADD_ALLOC_FAILED,
184 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_RT_ADD_ACCESS_FAILED,
185 DEV_LOG_RATE_LIMIT_ID_BWS_QW_CBR_RT_ADD_ACCESS_FAILED,
186 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_NRT_ADD_ALLOC_FAILED,
187 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_COMPENSATION_ADD_ACCESS_FAILED,
188 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_NO_COMPENSATION_ADD_ACCESS_FAILED,
189 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_COPY_COMPENSATION_ADD_ACCESS_FAILED,
190 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_RT_SAVE_ACCESS_FOR_COMPENSATION_FAILED,
191 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_NRT_SAVE_ACCESS_FOR_COMPENSATION_FAILED,
192 DEV_LOG_RATE_LIMIT_ID_BWS_CBR_FLUSH_FAILED,
193 DEV_LOG_RATE_LIMIT_ID__NUM_OF,
194} dev_log_rate_limit_id;
195
196void bcm_dev_log_log_ratelimit(dev_log_id xi_id,
197 bcm_dev_log_level xi_log_level,
198 uint32_t xi_flags,
199 uint32_t rate_us,
200 dev_log_rate_limit_id rate_limit_id,
201 const char *fmt,
202 ...) __attribute__((format(__printf__, 6, 7))); /* compiler attribute to check as printf style for arguments 6 (fmt) and 7 (all other) */
203
204/********************************************************************************************/
205/* */
206/* Name: bcm_dev_log_os_trace_init */
207/* */
208/* Abstract: Direct bcmos_trace() output to log */
209/* Arguments: NONE */
210/* */
211/* Return Value: */
212/* bcmos_errno - Success code (BCM_ERR_OK) or Error code (see bcmos_errno.h) */
213/* */
214/********************************************************************************************/
215bcmos_errno bcm_dev_log_os_trace_init(void);
216
217#else /* #ifndef ENABLE_LOG */
218
219#define BCM_LOG(level, id, ...)
220#define BCM_LOG_CALLER_FMT(level, id, ...)
221
222#endif /* ENABLE_LOG */
223
224#endif /* __BCM_DEV_LOG_H_ */