MT6620: add the new driver JB2 V1.0
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / common / linux / include / stp_dbg.h
1 #ifndef _STP_DEBUG_H_
2 #define _STP_DEBUG_H_
3
4 #include <linux/time.h>
5 #include "osal.h"
6
7 #define CONFIG_LOG_STP_INTERNAL
8
9 #if 1//#ifndef CONFIG_LOG_STP_INTERNAL
10 #define STP_PKT_SZ  16
11 #define STP_DMP_SZ 2048
12 #define STP_PKT_NO 2048
13
14 #define STP_DBG_LOG_ENTRY_NUM 2048
15 #define STP_DBG_LOG_ENTRY_SZ  2048
16
17 #else
18
19 #define STP_PKT_SZ  16
20 #define STP_DMP_SZ 16
21 #define STP_PKT_NO 16
22
23 #define STP_DBG_LOG_ENTRY_NUM 28
24 #define STP_DBG_LOG_ENTRY_SZ 64
25
26
27 #endif
28
29
30 typedef enum {
31     STP_DBG_EN         = 0,
32     STP_DBG_PKT        = 1,
33     STP_DBG_DR         = 2,
34     STP_DBG_FW_ASSERT  = 3,
35     STP_DBG_FW_LOG = 4,
36     STP_DBG_FW_DMP = 5, 
37     STP_DBG_MAX
38 }STP_DBG_OP_T;
39
40 typedef enum {
41     STP_DBG_PKT_FIL_ALL = 0,
42     STP_DBG_PKT_FIL_BT  = 1,
43     STP_DBG_PKT_FIL_GPS = 2,
44     STP_DBG_PKT_FIL_FM  = 3,
45     STP_DBG_PKT_FIL_WMT = 4,
46     STP_DBG_PKT_FIL_MAX
47 } STP_DBG_PKT_FIL_T;
48
49 static  char * const gStpDbgType[]={
50     "< BT>",
51     "< FM>",
52     "<GPS>",
53     "<WiFi>",
54     "<WMT>",
55     "<STP>",
56     "<DBG>",
57     "<UNKOWN>"
58 };
59
60
61 typedef enum {
62     STP_DBG_DR_MAX = 0,
63 } STP_DBG_DR_FIL_T;
64
65 typedef enum {
66     STP_DBG_FW_MAX = 0,
67 } STP_DBG_FW_FIL_T;
68
69 typedef enum {
70     PKT_DIR_RX = 0,
71     PKT_DIR_TX
72 } STP_DBG_PKT_DIR_T;
73
74 /*simple log system ++*/
75
76 typedef struct {
77     int  id; /*type: 0. pkt trace 1. fw info 2. assert info 3. trace32 dump . -1. linked to the the previous*/
78     int  len;
79     char buffer[STP_DBG_LOG_ENTRY_SZ];
80 } MTKSTP_LOG_ENTRY_T;
81
82 typedef struct log_sys {
83     MTKSTP_LOG_ENTRY_T  queue[STP_DBG_LOG_ENTRY_NUM];
84     unsigned int size;
85     unsigned int in;
86     unsigned int out;
87     spinlock_t   lock;
88 } MTKSTP_LOG_SYS_T;
89 /*--*/
90
91 typedef struct stp_dbg_pkt_hdr{
92     //packet information
93     unsigned int   sec;
94     unsigned int   usec;
95     unsigned int   dbg_type;
96     unsigned int   dmy;
97     unsigned int   no;
98     unsigned int   dir;
99
100     //packet content
101     unsigned int  type;
102     unsigned int  len;
103     unsigned int  ack;
104     unsigned int  seq;
105     unsigned int  chs;
106     unsigned int  crc;
107 }STP_DBG_HDR_T;
108
109 typedef struct stp_dbg_pkt{
110     struct stp_dbg_pkt_hdr hdr;
111     unsigned char raw[STP_DMP_SZ];
112 }STP_PACKET_T;
113
114 typedef struct mtkstp_dbg_t{
115     /*log_sys*/
116     int pkt_trace_no;
117     void *btm;
118     int is_enable;
119     MTKSTP_LOG_SYS_T *logsys;
120 }MTKSTP_DBG_T;
121
122 extern void aed_combo_exception(const int *, int, const int *, int, const char *);
123
124 #define STP_CORE_DUMP_TIMEOUT 5*60*1000 // default 5minutes
125 #define STP_OJB_NAME_SZ 20
126 #define STP_CORE_DUMP_INFO_SZ 500
127 typedef enum wcn_compress_algorithm_t {
128     GZIP = 0,
129     BZIP2 = 1,
130     RAR = 2,
131     LMA = 3,
132     MAX
133 }WCN_COMPRESS_ALG_T;
134
135 typedef INT32 (*COMPRESS_HANDLER)(void *worker, UINT8 *in_buf, INT32 in_sz, UINT8 *out_buf, INT32 *out_sz, INT32 finish);
136 typedef struct wcn_compressor_t {
137     // current object name
138     UINT8 name[STP_OJB_NAME_SZ + 1];
139     
140     // buffer for raw data, named L1
141     PUINT8 L1_buf;
142     INT32 L1_buf_sz;
143     INT32 L1_pos;
144     
145     // target buffer, named L2
146     PUINT8 L2_buf;
147     INT32 L2_buf_sz;
148     INT32 L2_pos;
149
150     // compress state
151     UINT8 f_done;
152     UINT16 reserved;
153     UINT32 uncomp_size;
154     UINT32 crc32;
155     
156     // compress algorithm
157     UINT8 f_compress_en;
158     WCN_COMPRESS_ALG_T compress_type;
159     void *worker;
160     COMPRESS_HANDLER handler;    
161 }WCN_COMPRESSOR_T, *P_WCN_COMPRESSOR_T;
162
163 P_WCN_COMPRESSOR_T wcn_compressor_init(PUINT8 name, INT32 L1_buf_sz, INT32 L2_buf_sz);
164 INT32 wcn_compressor_deinit(P_WCN_COMPRESSOR_T compressor);
165 INT32 wcn_compressor_in(P_WCN_COMPRESSOR_T compressor, PUINT8 buf, INT32 len, INT32 finish);
166 INT32 wcn_compressor_out(P_WCN_COMPRESSOR_T compressor, PUINT8 *pbuf, PINT32 len);
167 INT32 wcn_compressor_reset(P_WCN_COMPRESSOR_T compressor, UINT8 enable, WCN_COMPRESS_ALG_T type);
168
169 typedef enum core_dump_state_t {
170     CORE_DUMP_INIT = 0,
171     CORE_DUMP_DOING,
172     CORE_DUMP_TIMEOUT,
173     CORE_DUMP_DONE,
174     CORE_DUMP_MAX
175 }CORE_DUMP_STA;
176
177 typedef struct core_dump_t {
178     // compress dump data and buffered
179     P_WCN_COMPRESSOR_T compressor;
180
181     // timer for monitor timeout
182     OSAL_TIMER dmp_timer;
183     UINT32 timeout;
184
185     OSAL_SLEEPABLE_LOCK dmp_lock;
186     
187     // state machine for core dump flow
188     CORE_DUMP_STA sm;
189
190     // dump info
191     CHAR info[STP_CORE_DUMP_INFO_SZ + 1];
192 } WCN_CORE_DUMP_T, *P_WCN_CORE_DUMP_T;
193
194 P_WCN_CORE_DUMP_T wcn_core_dump_init(UINT32 timeout);
195 INT32 wcn_core_dump_deinit(P_WCN_CORE_DUMP_T dmp);
196 INT32 wcn_core_dump_in(P_WCN_CORE_DUMP_T dmp, PUINT8 buf, INT32 len);
197 INT32 wcn_core_dump_out(P_WCN_CORE_DUMP_T dmp, PUINT8 *pbuf, PINT32 len);
198 INT32 wcn_core_dump_reset(P_WCN_CORE_DUMP_T dmp, UINT32 timeout);
199 extern INT32 wcn_core_dump_flush(INT32 rst);
200
201 extern int stp_dbg_enable(MTKSTP_DBG_T *stp_dbg);
202 extern int stp_dbg_disable(MTKSTP_DBG_T *stp_dbg);
203 extern MTKSTP_DBG_T *stp_dbg_init(void *);
204 extern int stp_dbg_deinit(MTKSTP_DBG_T *stp_dbg);
205 extern int stp_dbg_dmp_out_ex (char *buf, int *len);
206 extern int stp_dbg_dmp_out(MTKSTP_DBG_T *stp_dbg, char *buf, int *len);
207 extern int stp_dbg_dmp_printk(MTKSTP_DBG_T *stp_dbg);
208 extern char
209 stp_dbg_nl_send(
210     char *  aucMsg,
211     unsigned char      cmd
212     );
213
214 extern INT32 stp_dbg_aee_send(unsigned char *aucMsg, INT32 len, INT32 cmd);
215
216 extern int
217 stp_dbg_log_pkt (
218     MTKSTP_DBG_T *stp_dbg,
219     int dbg_type,
220     int type,
221     int ack_no,
222     int seq_no,
223     int crc,
224     int dir,
225     int len,
226     const unsigned char *body);
227 extern int stp_dbg_log_ctrl (unsigned int on);
228 #endif /* end of _STP_DEBUG_H_ */
229