79ce933dfd660ad06b58fe19c3689a55ac944542
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931_kk / drv_wlan / include / debug.h
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT662X_593X_WIFI_DRIVER_V2_3/include/debug.h#1 $
3 */
4
5 /*! \file   debug.h
6     \brief  Definition of SW debugging level.
7
8     In this file, it describes the definition of various SW debugging levels and
9     assert functions.
10 */
11
12 /*******************************************************************************
13 * Copyright (c) 2007 MediaTek Inc.
14 *
15 * All rights reserved. Copying, compilation, modification, distribution
16 * or any other use whatsoever of this material is strictly prohibited
17 * except in accordance with a Software License Agreement with
18 * MediaTek Inc.
19 ********************************************************************************
20 */
21
22 /*******************************************************************************
23 * LEGAL DISCLAIMER
24 *
25 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
26 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
27 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
28 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
29 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
30 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
31 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
32 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
33 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
34 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
35 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
36 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
37 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
38 *
39 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
40 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
41 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
42 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
43 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
44 *
45 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
46 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
47 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
48 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
49 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
50 * (ICC).
51 ********************************************************************************
52 */
53
54 /*
55 ** $Log: debug.h $
56  *
57  * 12 16 2011 wh.su
58  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
59  * fixed the Windows DDK free build compiling error.
60  *
61  * 11 24 2011 wh.su
62  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
63  * Adjust code for DBG and CONFIG_XLOG.
64  *
65  * 11 11 2011 wh.su
66  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
67  * modify the xlog related code.
68  *
69  * 11 10 2011 wh.su
70  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
71  * Using the new XLOG define for dum Memory.
72  *
73  * 11 03 2011 wh.su
74  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
75  * Add dumpMemory8 at XLOG support.
76  *
77  * 11 02 2011 wh.su
78  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
79  * adding the code for XLOG.
80  *
81  * 08 31 2011 cm.chang
82  * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
83  * .
84  *
85  * 01 27 2011 tsaiyuan.hsu
86  * [WCXRP00000392] [MT6620 Wi-Fi][Driver] Add Roaming Support
87  * add roaming fsm
88  * 1. not support 11r, only use strength of signal to determine roaming.
89  * 2. not enable CFG_SUPPORT_ROAMING until completion of full test.
90  * 3. in 6620, adopt work-around to avoid sign extension problem of cck of hw
91  * 4. assume that change of link quality in smooth way.
92  *
93  * 01 07 2011 wh.su
94  * [WCXRP00000326] [MT6620][Wi-Fi][Driver] check in the binary format gl_sec.o.new instead of use change type!!!
95  * .
96  *
97  * 09 23 2010 cp.wu
98  * NULL
99  * add BOW index for debugging message and passing compilation
100  *
101  * 07 20 2010 wh.su
102  *
103  * adding the wapi code.
104  *
105  * 07 08 2010 cp.wu
106  *
107  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
108  *
109  * 06 21 2010 yarco.yang
110  * [WPD00003837][MT6620]Data Path Refine
111  * Support CFG_MQM_MIGRATION flag
112  *
113  * 06 17 2010 yuche.tsai
114  * [WPD00003839][MT6620 5931][P2P] Feature migration
115  * Add one more debug moduel for P2P.
116  *
117  * 06 14 2010 cp.wu
118  * [WPD00003833][MT6620 and MT5931] Driver migration
119  * add management dispatching function table.
120  *
121  * 06 11 2010 cp.wu
122  * [WPD00003833][MT6620 and MT5931] Driver migration
123  * add bss.c.
124  *
125  * 06 11 2010 cp.wu
126  * [WPD00003833][MT6620 and MT5931] Driver migration
127  * 1) migrate assoc.c.
128  * 2) add ucTxSeqNum for tracking frames which needs TX-DONE awareness
129  * 3) add configuration options for CNM_MEM and RSN modules
130  * 4) add data path for management frames
131  * 5) eliminate rPacketInfo of MSDU_INFO_T
132  *
133  * 06 10 2010 cp.wu
134  * [WPD00003833][MT6620 and MT5931] Driver migration
135  * add debug module index for cnm and ais.
136  *
137  * 06 06 2010 kevin.huang
138  * [WPD00003832][MT6620 5931] Create driver base
139  * [MT6620 5931] Create driver base
140  *
141  * 05 17 2010 cp.wu
142  * [WPD00001943]Create WiFi test driver framework on WinXP
143  * add CFG_STARTUP_DEBUG for debugging starting up issue.
144  *
145  * 04 26 2010 cp.wu
146  * [WPD00001943]Create WiFi test driver framework on WinXP
147  * 1) surpress compiler warning
148  * 2) when acqruing LP-own, keep writing WHLPCR whenever OWN is not acquired yet
149 **  \main\maintrunk.MT6620WiFiDriver_Prj\4 2009-10-29 19:47:50 GMT mtk01084
150 **  add emu catagory
151 **  \main\maintrunk.MT6620WiFiDriver_Prj\3 2009-04-17 18:12:04 GMT mtk01426
152 **  Don't use dynamic memory allocate for debug message
153 **  \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-03-10 20:11:29 GMT mtk01426
154 **  Init for develop
155 **
156 */
157
158 #ifndef _DEBUG_H
159 #define _DEBUG_H
160
161 /*******************************************************************************
162 *                         C O M P I L E R   F L A G S
163 ********************************************************************************
164 */
165 #ifndef BUILD_QA_DBG
166 #define BUILD_QA_DBG 0
167 #endif
168
169 /*******************************************************************************
170 *                    E X T E R N A L   R E F E R E N C E S
171 ********************************************************************************
172 */
173 #include "gl_typedef.h"
174 #if CFG_SUPPORT_XLOG
175 #include "linux/xlog.h"
176 #endif
177
178 extern UINT_8   aucDebugModule[];
179 extern UINT_32  u4DebugModule;
180
181 /*******************************************************************************
182 *                              C O N S T A N T S
183 ********************************************************************************
184 */
185 /* Define debug category (class):
186  * (1) ERROR (2) WARN (3) STATE (4) EVENT (5) TRACE (6) INFO (7) LOUD (8) TEMP
187  */
188 #define DBG_CLASS_ERROR         BIT(0)
189 #define DBG_CLASS_WARN          BIT(1)
190 #define DBG_CLASS_STATE         BIT(2)
191 #define DBG_CLASS_EVENT         BIT(3)
192 #define DBG_CLASS_TRACE         BIT(4)
193 #define DBG_CLASS_INFO          BIT(5)
194 #define DBG_CLASS_LOUD          BIT(6)
195 #define DBG_CLASS_TEMP          BIT(7)
196 #define DBG_CLASS_MASK          BITS(0,7)
197
198
199 #if defined(LINUX)
200 #define DBG_PRINTF_64BIT_DEC    "lld"
201
202 #else  //Windows
203 #define DBG_PRINTF_64BIT_DEC    "I64d"
204
205 #endif
206 /*******************************************************************************
207 *                             D A T A   T Y P E S
208 ********************************************************************************
209 */
210 /* Define debug module index */
211 typedef enum _ENUM_DBG_MODULE_T {
212     DBG_INIT_IDX = 0,       /* For driver initial */
213     DBG_HAL_IDX,            /* For HAL(HW) Layer */
214     DBG_INTR_IDX,           /* For Interrupt */
215     DBG_REQ_IDX,
216     DBG_TX_IDX,
217     DBG_RX_IDX,
218     DBG_RFTEST_IDX,         /* For RF test mode*/
219     DBG_EMU_IDX,            /* Developer specific */
220
221     DBG_SW1_IDX,            /* Developer specific */
222     DBG_SW2_IDX,            /* Developer specific */
223     DBG_SW3_IDX,            /* Developer specific */
224     DBG_SW4_IDX,            /* Developer specific */
225
226     DBG_HEM_IDX,            /* HEM */
227     DBG_AIS_IDX,            /* AIS */
228     DBG_RLM_IDX,            /* RLM */
229     DBG_MEM_IDX,            /* RLM */
230     DBG_CNM_IDX,            /* CNM */
231     DBG_RSN_IDX,            /* RSN */
232     DBG_BSS_IDX,            /* BSS */
233     DBG_SCN_IDX,            /* SCN */
234     DBG_SAA_IDX,            /* SAA */
235     DBG_AAA_IDX,            /* AAA */
236     DBG_P2P_IDX,            /* P2P */
237     DBG_QM_IDX,             /* QUE_MGT */
238     DBG_SEC_IDX,            /* SEC */
239     DBG_BOW_IDX,            /* BOW */
240     DBG_WAPI_IDX,           /* WAPI */
241     DBG_ROAMING_IDX,        /* ROAMING */
242
243     DBG_MODULE_NUM          /* Notice the XLOG check */
244 } ENUM_DBG_MODULE_T;
245
246 //XLOG
247 //#define XLOG_DBG_MODULE_IDX    28 /* DBG_MODULE_NUM */
248 //#if (XLOG_DBG_MODULE_IDX != XLOG_DBG_MODULE_IDX)
249 //#error "Please modify the DBG_MODULE_NUM and make sure this include at XLOG"
250 //#endif
251
252 /* Define who owns developer specific index */
253 #define DBG_YARCO_IDX           DBG_SW1_IDX
254 #define DBG_KEVIN_IDX           DBG_SW2_IDX
255 #define DBG_CMC_IDX             DBG_SW3_IDX
256 #define DBG_GEORGE_IDX          DBG_SW4_IDX
257
258 /*******************************************************************************
259 *                            P U B L I C   D A T A
260 ********************************************************************************
261 */
262
263 /*******************************************************************************
264 *                           P R I V A T E   D A T A
265 ********************************************************************************
266 */
267
268 /*******************************************************************************
269 *                                 M A C R O S
270 ********************************************************************************
271 */
272 /* Debug print format string for the OS system time */
273 #define OS_SYSTIME_DBG_FORMAT               "0x%08x"
274
275 /* Debug print argument for the OS system time */
276 #define OS_SYSTIME_DBG_ARGUMENT(systime)    (systime)
277
278 /* Debug print format string for the MAC Address */
279 #define MACSTR          "%02x:%02x:%02x:%02x:%02x:%02x"
280
281 /* Debug print argument for the MAC Address */
282 #define MAC2STR(a)      ((PUINT_8)a)[0], ((PUINT_8)a)[1], ((PUINT_8)a)[2], \
283                         ((PUINT_8)a)[3], ((PUINT_8)a)[4], ((PUINT_8)a)[5]
284
285 /* The pre-defined format to dump the value of a varaible with its name shown. */
286 #define DUMPVAR(variable, format)           (#variable " = " format "\n", variable)
287
288 /* The pre-defined format to dump the MAC type value with its name shown. */
289 #define DUMPMACADDR(addr)                   (#addr " = " MACSTR "\n", MAC2STR(addr))
290
291
292 /* Basiclly, we just do renaming of KAL functions although they should
293  * be defined as "Nothing to do" if DBG=0. But in some compiler, the macro
294  * syntax does not support  #define LOG_FUNC(x,...)
295  *
296  * A caller shall not invoke these three macros when DBG=0.
297  */
298 #define LOG_FUNC_TIME           kalPrint
299 #define LOG_FUNC                kalPrint
300
301 #if DBG
302
303     #define TMP_BUF_LEN   256
304     #define TMP_WBUF_LEN  (TMP_BUF_LEN * 2)
305
306     extern PINT_16 g_wbuf_p;
307     extern PINT_8 g_buf_p;
308
309     /* If __FUNCTION__ is already defined by compiler, we just use it. */
310     #if defined(__FUNCTION__)
311         #define DEBUGFUNC(_Func)
312     #else
313         #define DEBUGFUNC(_Func) static const char __FUNCTION__[] = _Func;
314     #endif
315
316     /* The following macros are used for future debug message. */
317     /* TODO(Kevin): We should remove INITLOG/ERRORLOG/WARNLOG macro sooner or later */
318     #define INITLOG(_Fmt) \
319     { \
320         if (aucDebugModule[DBG_INIT_IDX] & DBG_CLASS_TRACE) { \
321             LOG_FUNC("%s: ", __FUNCTION__); \
322             LOG_FUNC _Fmt; \
323         } \
324     }
325
326     #define ERRORLOG(_Fmt) \
327     { \
328         if (aucDebugModule[DBG_INIT_IDX] & DBG_CLASS_ERROR) { \
329             LOG_FUNC("**Error[%s:%d]-", __FILE__, __LINE__); \
330             LOG_FUNC _Fmt; \
331         } \
332     }
333
334     #define WARNLOG(_Fmt) \
335     { \
336         if (aucDebugModule[DBG_INIT_IDX] & DBG_CLASS_WARN) { \
337             LOG_FUNC("**Warning[%s:%d]-", __FILE__, __LINE__); \
338             LOG_FUNC _Fmt; \
339         } \
340     }
341
342     /*lint -save -e960 Multiple use of '#/##' */
343     #define DBGLOG(_Module, _Class, _Fmt) \
344         { \
345             if (aucDebugModule[DBG_##_Module##_IDX] & DBG_CLASS_##_Class) { \
346                 if (DBG_CLASS_##_Class == DBG_CLASS_ERROR) { \
347                     LOG_FUNC_TIME("**Error[%s:%d]-", __FILE__, __LINE__); \
348                     LOG_FUNC("%s: (" #_Module " " #_Class ") ", __FUNCTION__); \
349                 } \
350                 else if (DBG_CLASS_##_Class == DBG_CLASS_WARN) { \
351                     LOG_FUNC_TIME("**Warning[%s:%d]-", __FILE__, __LINE__); \
352                     LOG_FUNC("%s: (" #_Module " " #_Class ") ", __FUNCTION__); \
353                 } \
354                 else if (DBG_CLASS_##_Class == DBG_CLASS_EVENT) { \
355                 } \
356                 else { \
357                     LOG_FUNC_TIME("%s: (" #_Module " " #_Class ") ", __FUNCTION__); \
358                 } \
359                 LOG_FUNC _Fmt; \
360             } \
361         }
362
363     #define DBGLOG_MEM8(_Module, _Class, _StartAddr, _Length) \
364         { \
365             if (aucDebugModule[DBG_##_Module##_IDX] & DBG_CLASS_##_Class) { \
366                 LOG_FUNC("%s: (" #_Module " " #_Class ")\n", __FUNCTION__); \
367                 dumpMemory8((PUINT_8) (_StartAddr), (UINT_32) (_Length)); \
368             } \
369         }
370
371     #define DBGLOG_MEM32(_Module, _Class, _StartAddr, _Length) \
372         { \
373             if (aucDebugModule[DBG_##_Module##_IDX] & DBG_CLASS_##_Class) { \
374                 LOG_FUNC("%s: (" #_Module " " #_Class ")\n", __FUNCTION__); \
375                 dumpMemory32((PUINT_32) (_StartAddr), (UINT_32) (_Length)); \
376             } \
377         }
378     /*lint -restore */
379
380     /*lint -save -e961 use of '#undef' is discouraged */
381     #undef ASSERT
382     /*lint -restore */
383
384     #ifdef _lint
385     #define ASSERT(_exp) \
386         { \
387             if (!(_exp)) {do {} while (1);} \
388         }
389     #else
390     #define ASSERT(_exp) \
391         { \
392             if (!(_exp) && !fgIsBusAccessFailed) { \
393                 LOG_FUNC("Assertion failed: %s:%d %s\n", __FILE__, __LINE__, #_exp); \
394                 kalBreakPoint(); \
395             } \
396         }
397     #endif /* _lint */
398
399     #define ASSERT_REPORT(_exp, _fmt) \
400         { \
401             if (!(_exp) && !fgIsBusAccessFailed) { \
402                 LOG_FUNC("Assertion failed: %s:%d %s\n", __FILE__, __LINE__, #_exp); \
403                 LOG_FUNC _fmt; \
404                 kalBreakPoint(); \
405             } \
406         }
407
408     #define DISP_STRING(_str)       _str
409
410 #else /* !DBG */
411
412     #define DEBUGFUNC(_Func)
413     #define INITLOG(_Fmt)
414     #define ERRORLOG(_Fmt)
415     #define WARNLOG(_Fmt)
416
417 #if defined(LINUX)
418     #define DBGLOG(_Module, _Class, _Fmt) \
419     { \
420         _Module##_##_Class##_LOGFUNC _Fmt; \
421     }
422 #else
423     #define DBGLOG(_Module, _Class, _Fmt)
424 #endif
425
426 #if CFG_SUPPORT_XLOG
427     #define DBGLOG_MEM8(_Module, _Class, _StartAddr, _Length) \
428     { \
429         _Module##_##_Class##_LOGFUNC (__FUNCTION__);\
430         _Module##_##_Class##_LOGDUMP8(_StartAddr, _Length); \
431     }
432 #else
433     #define DBGLOG_MEM8(_Module, _Class, _StartAddr, _Length)
434 #endif
435     #define DBGLOG_MEM32(_Module, _Class, _StartAddr, _Length)
436
437     #undef ASSERT
438
439 #if BUILD_QA_DBG
440     #if defined(LINUX) /* For debugging in Linux w/o GDB */
441         #define ASSERT(_exp) \
442             { \
443                 if (!(_exp) && !fgIsBusAccessFailed) { \
444                     LOG_FUNC("Assertion failed: %s:%d (%s)\n", __FILE__, __LINE__, #_exp); \
445                     kalBreakPoint(); \
446                 } \
447             }
448
449         #define ASSERT_REPORT(_exp, _fmt) \
450             { \
451                 if (!(_exp) && !fgIsBusAccessFailed) { \
452                     LOG_FUNC("Assertion failed: %s:%d (%s)\n", __FILE__, __LINE__, #_exp); \
453                     LOG_FUNC _fmt; \
454                     kalBreakPoint(); \
455                 } \
456             }
457     #else
458         #ifdef WINDOWS_CE
459             #define UNICODE_TEXT(_msg)  TEXT(_msg)
460             #define ASSERT(_exp) \
461                 { \
462                     if (!(_exp) && !fgIsBusAccessFailed) { \
463                         TCHAR rUbuf[256]; \
464                         kalBreakPoint(); \
465                         _stprintf(rUbuf, TEXT("Assertion failed: %s:%d %s\n"), \
466                             UNICODE_TEXT(__FILE__), \
467                             __LINE__, \
468                             UNICODE_TEXT(#_exp)); \
469                         MessageBox(NULL, rUbuf, TEXT("ASSERT!"), MB_OK); \
470                     } \
471                 }
472
473             #define ASSERT_REPORT(_exp, _fmt) \
474                 { \
475                     if (!(_exp) && !fgIsBusAccessFailed) { \
476                         TCHAR rUbuf[256]; \
477                         kalBreakPoint(); \
478                         _stprintf(rUbuf, TEXT("Assertion failed: %s:%d %s\n"), \
479                             UNICODE_TEXT(__FILE__), \
480                             __LINE__, \
481                             UNICODE_TEXT(#_exp)); \
482                         MessageBox(NULL, rUbuf, TEXT("ASSERT!"), MB_OK); \
483                     } \
484                 }
485         #else
486             #define ASSERT(_exp) \
487                 { \
488                     if (!(_exp) && !fgIsBusAccessFailed) { \
489                         kalBreakPoint(); \
490                     } \
491                 }
492
493             #define ASSERT_REPORT(_exp, _fmt) \
494                 { \
495                     if (!(_exp) && !fgIsBusAccessFailed) { \
496                         kalBreakPoint(); \
497                     } \
498                 }
499         #endif /* WINDOWS_CE */
500     #endif /* LINUX */
501 #else
502     #define ASSERT(_exp)
503     #define ASSERT_REPORT(_exp, _fmt)
504 #endif /* BUILD_QA_DBG */
505
506     #define DISP_STRING(_str)       ""
507
508 #endif /* DBG */
509
510 #if CFG_STARTUP_DEBUG
511     #if defined(LINUX)
512 #define DBGPRINTF kalPrint
513     #else
514 #define DBGPRINTF DbgPrint
515     #endif
516 #else
517 #define DBGPRINTF(...)
518 #endif
519
520
521 /* The following macro is used for debugging packed structures. */
522 #ifndef DATA_STRUC_INSPECTING_ASSERT
523 #define DATA_STRUC_INSPECTING_ASSERT(expr) \
524         switch (0) {case 0: case (expr): default:;}
525 #endif
526
527 /*******************************************************************************
528 *                  F U N C T I O N   D E C L A R A T I O N S
529 ********************************************************************************
530 */
531 #if DBG
532 VOID
533 dumpMemory8 (
534     IN PUINT_8 pucStartAddr,
535     IN UINT_32 u4Length
536     );
537
538 VOID
539 dumpMemory32 (
540     IN PUINT_32 pu4StartAddr,
541     IN UINT_32  u4Length
542     );
543 #elif CFG_SUPPORT_XLOG
544 VOID
545 dumpMemory8 (
546     IN UINT_32  log_level,
547     IN PUINT_8 pucStartAddr,
548     IN UINT_32 u4Length
549     );
550 #endif /* DBG */
551
552 /*******************************************************************************
553 *                              F U N C T I O N S
554 ********************************************************************************
555 */
556 #endif /* _DEBUG_H */
557