a9c53ba9b0d7f14fe751785dddde0f32b79708e9
[o-du/l2.git] / src / rlog / rl_rlog.h
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /********************************************************************20**
20
21      Name:     Radisys Logging Framework
22      Type:     C include file
23      Desc:     This file contains logging framework include file for library.
24      File:     rl.h
25
26 *********************************************************************21*/
27 /****************************************************************************
28 @ description: This is header file is used by logging framework module. This
29 file should not be included by any other application. This is internal
30 header file logging framework.
31 *****************************************************************************/
32
33 #ifndef __RL_H__
34 #define __RL_H__
35
36 #include <stdio.h>
37 #include <time.h>
38 #include <ctype.h>
39 #include <sys/types.h>
40 #include <stdlib.h>
41 #include <signal.h>
42 #include <errno.h>
43 #include "rl_common.h"
44
45 #define MAX_FILE_SIZE                   3145728 /* 3MB */
46 #define MAX_LOG_LEN                             256
47 #define MAX_FILENAME_LEN                300
48 #define LOG_TIME_LEN                    64
49 #define MAX_LOG_BUF_SIZE                5000
50 #define RLOG_MAX_CIRBUF_SIZE                    (1024*100)
51 #define RLOG_REMOTE_LOGGING_PORT                9099
52 #define RLOG_MAX_FILES                                  5
53 #define RLOG_MAX_TIME_STAMP                     80
54 #define RLOG_MAX_TAX_NAME                               16
55 #define RLOG_FIFO_FILE                                  "/tmp/l2logs"
56 #define RLOG_CIRBUF_READ_INTERVAL       1       /* 60 seconds read interval */
57 #define RLOG_MAX_THREADS                                16
58 #define RLOG_TIME_ZONE_LEN                              8
59 #define RLOG_MAX_STACK_DEPTH            24
60 #define RLOG_MAX_BACKTRACE_BUFSZ        2048
61 #define RLOG_READ_POS_THRESHOLD 300
62 #define RLOG_FIXED_LENGTH_BUFFER_SIZE 50
63 #define RLOGTICKSCNTTOPRCL2LOGS 10
64
65 /* Console handling */
66 #define RLOG_CTRL_L    12
67 #define RLOG_CTRL_Y    25
68 #define RLOG_ENTER_KEY 10
69 #define RLOG_SET_LOGLEVEL  1
70 #define RLOG_SET_MODMASK   2
71
72 /*L2 Logging */
73 #define PROCESS_L2LOG_TTI 10
74
75 typedef enum {
76 LOG_ARG_INT,
77 LOG_ARG_STR,
78 LOG_ARG_HEX,
79 LOG_ARG_SPL
80 } LOG_ARG_TYPE;
81
82 typedef enum rlLogCntLmt
83 {
84    RL_LOG_COUNT_LIMIT_START = 1,
85    RL_LOG_COUNT_LIMIT_STOP
86 }RLLogCntLmt;
87
88 #ifndef RLOG_ENABLE_TEXT_LOGGING
89
90 typedef enum
91 {
92         L_TIME_REFERENCE=0,
93         L_TIME_DELIMITER,
94         L_SIGSEGV,
95     L_TIME_TTI_UPDT
96 } LOGID_TYPE;
97
98 typedef struct
99 {
100         time_t tv_sec;
101         uint32_t        ms_tti;
102 } __attribute__ ((__packed__)) LOGTIME;
103
104 typedef struct
105 {
106         LOGID                   logId;          /* 4 bytes | 32 bits */
107         LOGTIME         logTime;                /* 8 bytes */
108         unsigned int argType    :2;
109         unsigned int logLevel   :3;
110         unsigned int numOfArgs  :3;
111         uint16_t                        len;
112 } __attribute__ ((__packed__)) LOGDATA;
113
114 typedef struct
115 {
116         LOGDATA         logData;
117         char            buf[MAX_LOG_BUF_SIZE];
118 }  __attribute__ ((__packed__)) ARGDATA;
119
120 typedef struct
121 {
122         LOGDATA logData;
123         uint32_t arg1;
124         uint32_t arg2;
125         uint32_t arg3;
126         uint32_t arg4;
127    char unusedByte[19]; /* To make it as 50 byte */
128 }  __attribute__ ((__packed__)) ARG4DATA;
129
130 typedef struct
131 {
132         LOGDATA logData;
133         uint8_t           splEnum;
134         uint32_t splArg;
135         uint32_t arg1;
136         uint32_t arg2;
137         uint32_t arg3;
138         uint32_t arg4;
139    char unusedByte[14]; /* To make it as 50 byte */
140 }  __attribute__ ((__packed__)) SPL_ARGDATA;
141
142 typedef enum _endian {little_endian, big_endian} EndianType;
143
144 typedef struct
145 {
146         uint16_t                        version;
147         uint32_t                        dummy32;
148         uint8_t                         endianType;
149         char                    szTimeZone[RLOG_TIME_ZONE_LEN+1];
150         uint16_t                        END_MARKER;
151    time_t      time_sec;
152 } __attribute__ ((__packed__)) FILE_HEADER;
153
154 #endif /* RLOG_ENABLE_TEXT_LOGGING */
155
156 typedef struct {
157         
158         char    szTaskName[RLOG_MAX_TAX_NAME];
159         uint8_t*        logBuff;                /* LOG Buffer */
160         uint32_t        logBufLen;  /* Data Written till now */
161         uint32_t        logReadPos; /* Reader thread position */
162         uint8_t         listIndex;      /* Index to global list */
163
164 } THREAD_DATA;
165
166 void readL2LogBuff(void);
167 void processL2LogBuff(void);
168 S16  sendL2LogBuftoL3(void);
169 void rlInitL2Log(void);
170 /* Extern for soc specific file */
171 void rlProcessLogBufFromL2(void *mBuf);
172 void rlInitL2SocSpecific(void);
173 //void processL2LogBuff(void);
174 void rlProcessTicks(void);
175 void rlGetL2LogBufPtr (void *mBuf, uint32_t *logLen,uint8_t **logPtr);
176 void rlInvalidateL2LogsInCache(uint8_t *ptr,uint32_t len);
177
178 uint8_t     *g_l2rlogBuf;        /* buffer pointer for shared memory allocation */
179 uint8_t     *g_l2LogBufStartPtr; /* buffer pointer where logs has to be written */
180 uint8_t     *g_l2LogBufBasePtr;  /* Base pointer for log buffer */
181 uint8_t     *g_logBufRcvdFromL2; /* Buffer pointer received from L2 at L3*/
182 uint8_t     *g_l2LogBaseBuff;    /* Base log buffer received at L3 */
183 uint32_t     g_l2LogBufLen;      /* Log Buffer length written at L2 */
184 uint32_t     startL2Logging;     /* flag to start processing of L2 logs */
185 uint32_t     g_l2logBuffPos;     /* Log Buffer block which is in use for L2 logging */
186 uint8_t      g_writeCirBuf;      /* Flag to indicate whether to write logs or not */
187 //Pst    g_rlog_pst;
188
189 #endif /* __RL_H__*/