net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / hal / phydm / phydm_debug.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20
21
22 #ifndef __ODM_DBG_H__
23 #define __ODM_DBG_H__
24
25 /*#define DEBUG_VERSION "1.1"*/  /*2015.07.29 YuChen*/
26 /*#define DEBUG_VERSION "1.2"*/  /*2015.08.28 Dino*/
27 #define DEBUG_VERSION   "1.3"  /*2016.04.28 YuChen*/
28 /* -----------------------------------------------------------------------------
29  *      Define the debug levels
30  *
31  *      1.      DBG_TRACE and DBG_LOUD are used for normal cases.
32  *      So that, they can help SW engineer to develope or trace states changed
33  *      and also help HW enginner to trace every operation to and from HW,
34  *      e.g IO, Tx, Rx.
35  *
36  *      2.      DBG_WARNNING and DBG_SERIOUS are used for unusual or error cases,
37  *      which help us to debug SW or HW.
38  *
39  * -----------------------------------------------------------------------------
40  *
41  *      Never used in a call to ODM_RT_TRACE()!
42  *   */
43 #define ODM_DBG_OFF                                     1
44
45 /*
46  *      Fatal bug.
47  *      For example, Tx/Rx/IO locked up, OS hangs, memory access violation,
48  *      resource allocation failed, unexpected HW behavior, HW BUG and so on.
49  *   */
50 #define ODM_DBG_SERIOUS                         2
51
52 /*
53  *      Abnormal, rare, or unexpeted cases.
54  *      For example, IRP/Packet/OID canceled, device suprisely unremoved and so on.
55  *   */
56 #define ODM_DBG_WARNING                         3
57
58 /*
59  *      Normal case with useful information about current SW or HW state.
60  *      For example, Tx/Rx descriptor to fill, Tx/Rx descriptor completed status,
61  *      SW protocol state change, dynamic mechanism state change and so on.
62  *   */
63 #define ODM_DBG_LOUD                                    4
64
65 /*
66  *      Normal case with detail execution flow or information.
67  *   */
68 #define ODM_DBG_TRACE                                   5
69
70 /*FW DBG MSG*/
71 #define RATE_DECISION   BIT(0)
72 #define INIT_RA_TABLE   BIT(1)
73 #define RATE_UP                 BIT(2)
74 #define RATE_DOWN               BIT(3)
75 #define TRY_DONE                BIT(4)
76 #define RA_H2C          BIT(5)
77 #define F_RATE_AP_RPT   BIT(7)
78
79 /* -----------------------------------------------------------------------------
80  * Define the tracing components
81  *
82  * -----------------------------------------------------------------------------
83  *BB FW Functions*/
84 #define PHYDM_FW_COMP_RA                        BIT(0)
85 #define PHYDM_FW_COMP_MU                        BIT(1)
86 #define PHYDM_FW_COMP_PATH_DIV          BIT(2)
87 #define PHYDM_FW_COMP_PHY_CONFIG        BIT(3)
88
89
90 /*BB Driver Functions*/
91 #define ODM_COMP_DIG                                    BIT(0)
92 #define ODM_COMP_RA_MASK                                BIT(1)
93 #define ODM_COMP_DYNAMIC_TXPWR          BIT(2)
94 #define ODM_COMP_FA_CNT                         BIT(3)
95 #define ODM_COMP_RSSI_MONITOR           BIT(4)
96 #define ODM_COMP_SNIFFER                                BIT(5)
97 #define ODM_COMP_ANT_DIV                                BIT(6)
98 #define ODM_COMP_DFS                                    BIT(7)
99 #define ODM_COMP_NOISY_DETECT           BIT(8)
100 #define ODM_COMP_RATE_ADAPTIVE          BIT(9)
101 #define ODM_COMP_PATH_DIV                       BIT(10)
102 #define ODM_COMP_CCX                                    BIT(11)
103
104 #define ODM_COMP_DYNAMIC_PRICCA         BIT(12)
105 /*BIT13 TBD*/
106 #define ODM_COMP_MP                                     BIT(14)
107 #define ODM_COMP_CFO_TRACKING           BIT(15)
108 #define ODM_COMP_ACS                                    BIT(16)
109 #define PHYDM_COMP_ADAPTIVITY           BIT(17)
110 #define PHYDM_COMP_RA_DBG                       BIT(18)
111 #define PHYDM_COMP_TXBF                         BIT(19)
112 /* MAC Functions */
113 #define ODM_COMP_EDCA_TURBO                     BIT(20)
114 #define ODM_COMP_DYNAMIC_RX_PATH        BIT(21)
115 #define ODM_FW_DEBUG_TRACE                      BIT(22)
116 /* RF Functions */
117 /*BIT23 TBD*/
118 #define ODM_COMP_TX_PWR_TRACK           BIT(24)
119 /*BIT25 TBD*/
120 #define ODM_COMP_CALIBRATION                    BIT(26)
121 /* Common Functions */
122 /*BIT27 TBD*/
123 #define ODM_PHY_CONFIG                          BIT(28)
124 #define ODM_COMP_INIT                                   BIT(29)
125 #define ODM_COMP_COMMON                         BIT(30)
126 #define ODM_COMP_API                                    BIT(31)
127
128
129 /*------------------------Export Marco Definition---------------------------*/
130
131 #define config_phydm_read_txagc_check(data)             (data != INVALID_TXAGC_DATA)
132
133 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
134         #define dbg_print                               DbgPrint
135         #define dcmd_printf                             DCMD_Printf
136         #define dcmd_scanf                              DCMD_Scanf
137         #define RT_PRINTK                               dbg_print
138 #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
139         #define dbg_print       printk
140         #define RT_PRINTK(fmt, args...) dbg_print("%s(): " fmt, __FUNCTION__, ## args);
141         #define RT_DISP(dbgtype, dbgflag, printstr)
142 #else
143         #define dbg_print       panic_printk
144         /*#define RT_PRINTK(fmt, args...)       dbg_print("%s(): " fmt, __FUNCTION__, ## args);*/
145         #define RT_PRINTK(fmt, args...) dbg_print(fmt, ## args);
146 #endif
147
148 #ifndef ASSERT
149         #define ASSERT(expr)
150 #endif
151
152 #if DBG
153 #define ODM_RT_TRACE(p_dm_odm, comp, level, fmt)                                                                        \
154         do {    \
155                 if (((comp) & p_dm_odm->debug_components) && (level <= p_dm_odm->debug_level || level == ODM_DBG_SERIOUS)) { \
156                         \
157                         if (p_dm_odm->support_ic_type == ODM_RTL8188E)                                                  \
158                                 dbg_print("[PhyDM-8188E] ");                                                                                    \
159                         else if (p_dm_odm->support_ic_type == ODM_RTL8192E)                                             \
160                                 dbg_print("[PhyDM-8192E] ");                                                                                    \
161                         else if (p_dm_odm->support_ic_type == ODM_RTL8812)                                                      \
162                                 dbg_print("[PhyDM-8812A] ");                                                                                    \
163                         else if (p_dm_odm->support_ic_type == ODM_RTL8821)                                                      \
164                                 dbg_print("[PhyDM-8821A] ");                                                                                    \
165                         else if (p_dm_odm->support_ic_type == ODM_RTL8814A)                                                     \
166                                 dbg_print("[PhyDM-8814A] ");                                                                                    \
167                         else if (p_dm_odm->support_ic_type == ODM_RTL8703B)                                                     \
168                                 dbg_print("[PhyDM-8703B] ");                                                                                    \
169                         else if (p_dm_odm->support_ic_type == ODM_RTL8822B)                                                     \
170                                 dbg_print("[PhyDM-8822B] ");                                                                                    \
171                         else if (p_dm_odm->support_ic_type == ODM_RTL8188F)                                                     \
172                                 dbg_print("[PhyDM-8188F] ");                                                                                    \
173                         RT_PRINTK fmt;                                                                                                                  \
174                 }       \
175         } while (0)
176
177 #define ODM_RT_TRACE_F(p_dm_odm, comp, level, fmt)                                                                       do {\
178                 if (((comp) & p_dm_odm->debug_components) && (level <= p_dm_odm->debug_level)) { \
179                         \
180                         RT_PRINTK fmt;                                                                                                                  \
181                 }       \
182         } while (0)
183
184
185 #define ODM_RT_ASSERT(p_dm_odm, expr, fmt)                                                                                       do {\
186                 if (!(expr)) {                                                                                                                                  \
187                         dbg_print("Assertion failed! %s at ......\n", #expr);                                                           \
188                         dbg_print("      ......%s,%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__);                    \
189                         RT_PRINTK fmt;                                                                                                                  \
190                         ASSERT(false);                                                                                                                  \
191                 }       \
192         } while (0)
193
194 #define ODM_dbg_enter() { dbg_print(" == > %s\n", __FUNCTION__); }
195 #define ODM_dbg_exit() { dbg_print("< == %s\n", __FUNCTION__); }
196 #define ODM_dbg_trace(str) { dbg_print("%s:%s\n", __FUNCTION__, str); }
197
198 #define ODM_PRINT_ADDR(p_dm_odm, comp, level, title_str, ptr)                                                    do {\
199                 if (((comp) & p_dm_odm->debug_components) && (level <= p_dm_odm->debug_level)) { \
200                         \
201                         int __i;                                                                                                                                \
202                         u8 *__ptr = (u8 *)ptr;                                                                                  \
203                         dbg_print("[ODM] ");                                                                                                    \
204                         dbg_print(title_str);                                                                                                   \
205                         dbg_print(" ");                                                                                                         \
206                         for (__i = 0; __i < 6; __i++)                                                                                           \
207                                 dbg_print("%02X%s", __ptr[__i], (__i == 5) ? "" : "-");                                         \
208                         dbg_print("\n");                                                                                                                \
209                 }       \
210         } while (0)
211
212 #else
213 #define ODM_RT_TRACE(p_dm_odm, comp, level, fmt)
214 #define ODM_RT_TRACE_F(p_dm_odm, comp, level, fmt)
215 #define ODM_RT_ASSERT(p_dm_odm, expr, fmt)
216 #define ODM_dbg_enter()
217 #define ODM_dbg_exit()
218 #define ODM_dbg_trace(str)
219 #define ODM_PRINT_ADDR(p_dm_odm, comp, level, title_str, ptr)
220 #endif
221
222 #define BB_DBGPORT_PRIORITY_3   3       /*Debug function (the highest priority)*/
223 #define BB_DBGPORT_PRIORITY_2   2       /*Check hang function & Strong function*/
224 #define BB_DBGPORT_PRIORITY_1   1       /*Watch dog function*/
225 #define BB_DBGPORT_RELEASE              0       /*Init value (the lowest priority)*/
226
227 void
228 phydm_init_debug_setting(struct PHY_DM_STRUCT           *p_dm_odm);
229
230
231 u8
232 phydm_set_bb_dbg_port(
233         void                    *p_dm_void,
234         u8                      curr_dbg_priority,
235         u32                     debug_port
236 );
237
238 void
239 phydm_release_bb_dbg_port(
240         void                    *p_dm_void
241 );
242
243 u32
244 phydm_get_bb_dbg_port_value(
245         void                    *p_dm_void
246 );
247
248 void phydm_basic_dbg_message(void                       *p_dm_void);
249
250 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
251 #define PHYDM_DBGPRINT          0
252 #define PHYDM_SSCANF(x, y, z)   dcmd_scanf(x, y, z)
253 #define PHYDM_VAST_INFO_SNPRINTF        PHYDM_SNPRINTF
254 #if (PHYDM_DBGPRINT == 1)
255 #define PHYDM_SNPRINTF(msg)     \
256         do {\
257                 rsprintf msg;\
258                 dbg_print(output);\
259         } while (0)
260 #else
261 #define PHYDM_SNPRINTF(msg)     \
262         do {\
263                 rsprintf msg;\
264                 dcmd_printf(output);\
265         } while (0)
266 #endif
267 #else
268 #if (DM_ODM_SUPPORT_TYPE == ODM_CE) || defined(__OSK__)
269         #define PHYDM_DBGPRINT          0
270 #else
271         #define PHYDM_DBGPRINT          1
272 #endif
273 #define MAX_ARGC                                20
274 #define MAX_ARGV                                16
275 #define DCMD_DECIMAL                    "%d"
276 #define DCMD_CHAR                               "%c"
277 #define DCMD_HEX                                "%x"
278
279 #define PHYDM_SSCANF(x, y, z)   sscanf(x, y, z)
280
281 #define PHYDM_VAST_INFO_SNPRINTF(msg)\
282         do {\
283                 snprintf msg;\
284                 dbg_print(output);\
285         } while (0)
286
287 #if (PHYDM_DBGPRINT == 1)
288 #define PHYDM_SNPRINTF(msg)\
289         do {\
290                 snprintf msg;\
291                 dbg_print(output);\
292         } while (0)
293 #else
294 #define PHYDM_SNPRINTF(msg)\
295         do {\
296                 if (out_len > used)\
297                         used += snprintf msg;\
298         } while (0)
299 #endif
300 #endif
301
302
303 void phydm_basic_profile(
304         void                    *p_dm_void,
305         u32                     *_used,
306         char                            *output,
307         u32                     *_out_len
308 );
309 #if (DM_ODM_SUPPORT_TYPE & (ODM_CE | ODM_AP))
310 s32
311 phydm_cmd(
312         struct PHY_DM_STRUCT    *p_dm_odm,
313         char            *input,
314         u32     in_len,
315         u8      flag,
316         char    *output,
317         u32     out_len
318 );
319 #endif
320 void
321 phydm_cmd_parser(
322         struct PHY_DM_STRUCT    *p_dm_odm,
323         char            input[][16],
324         u32     input_num,
325         u8      flag,
326         char    *output,
327         u32     out_len
328 );
329
330 boolean
331 phydm_api_trx_mode(
332         struct PHY_DM_STRUCT                            *p_dm_odm,
333         enum odm_rf_path_e                      tx_path,
334         enum odm_rf_path_e                      rx_path,
335         boolean                                 is_tx2_path
336 );
337
338 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
339 void phydm_sbd_check(
340         struct PHY_DM_STRUCT                                    *p_dm_odm
341 );
342
343 void phydm_sbd_callback(
344         struct timer_list               *p_timer
345 );
346
347 void phydm_sbd_workitem_callback(
348         void            *p_context
349 );
350 #endif
351
352 void
353 phydm_fw_trace_en_h2c(
354         void            *p_dm_void,
355         boolean         enable,
356         u32             fw_debug_component,
357         u32             monitor_mode,
358         u32             macid
359 );
360
361 void
362 phydm_fw_trace_handler(
363         void    *p_dm_void,
364         u8      *cmd_buf,
365         u8      cmd_len
366 );
367
368 void
369 phydm_fw_trace_handler_code(
370         void    *p_dm_void,
371         u8      *buffer,
372         u8      cmd_len
373 );
374
375 void
376 phydm_fw_trace_handler_8051(
377         void    *p_dm_void,
378         u8      *cmd_buf,
379         u8      cmd_len
380 );
381
382 #endif /* __ODM_DBG_H__ */