1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2017 Realtek Corporation.
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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
16 *
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
21 *
22 * Larry Finger <Larry.Finger@lwfinger.net>
23 *
24 *****************************************************************************/
25
26 #ifndef __ODM_DBG_H__
27 #define __ODM_DBG_H__
28
29 /*#define DEBUG_VERSION "1.1"*/ /*2015.07.29 YuChen*/
30 /*#define DEBUG_VERSION "1.2"*/ /*2015.08.28 Dino*/
31 /*#define DEBUG_VERSION "1.3"*/ /*2016.04.28 YuChen*/
32 /*#define DEBUG_VERSION "1.4"*/ /*2017.03.13 Dino*/
33 /*#define DEBUG_VERSION "2.0"*/ /*2018.01.10 Dino*/
34 /*2020.07.03 fix cck report bug due to 8723F coding error*/
35 #define DEBUG_VERSION "4.6"
36
37 /*@
38 * ============================================================
39 * Definition
40 * ============================================================
41 */
42
43 /*@FW DBG MSG*/
44 #define RATE_DECISION 1
45 #define INIT_RA_TABLE 2
46 #define RATE_UP 4
47 #define RATE_DOWN 8
48 #define TRY_DONE 16
49 #define RA_H2C 32
50 #define F_RATE_AP_RPT 64
51 #define DBC_FW_CLM 9
52
53 #define PHYDM_SNPRINT_SIZE 64
54 /* @----------------------------------------------------------------------------
55 * Define the tracing components
56 *
57 * -----------------------------------------------------------------------------
58 * BB FW Functions
59 */
60 #define PHYDM_FW_COMP_RA BIT(0)
61 #define PHYDM_FW_COMP_MU BIT(1)
62 #define PHYDM_FW_COMP_PATH_DIV BIT(2)
63 #define PHYDM_FW_COMP_PT BIT(3)
64
65 /*@------------------------Export Marco Definition---------------------------*/
66
67 #define config_phydm_read_txagc_check(data) (data != INVALID_TXAGC_DATA)
68
69 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
70 #if (DBG_CMD_SUPPORT == 1)
71 extern VOID DCMD_Printf(const char *pMsg);
72 #else
73 #define DCMD_Printf(_pMsg)
74 #endif
75
76 #if OS_WIN_FROM_WIN10(OS_VERSION)
77 #define pr_debug(fmt, ...) DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, fmt, ##__VA_ARGS__)
78 #else
79 #define pr_debug DbgPrint
80 #endif
81
82 #define dcmd_printf DCMD_Printf
83 #define dcmd_scanf DCMD_Scanf
84 #define RT_PRINTK pr_debug
85 #define PRINT_MAX_SIZE 512
86 #define PHYDM_SNPRINTF RT_SPRINTF
87 #define PHYDM_TRACE(_MSG_) EXhalPHYDMoutsrc_Print(_MSG_)
88 #elif (DM_ODM_SUPPORT_TYPE == ODM_CE) && defined(DM_ODM_CE_MAC80211)
89 #define PHYDM_SNPRINTF snprintf
90 #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
91 #undef pr_debug
92 #define pr_debug printk
93 #define RT_PRINTK(fmt, args...) pr_debug(fmt, ## args)
94 #define RT_DISP(dbgtype, dbgflag, printstr)
95 #define RT_TRACE(adapter, comp, drv_level, fmt, args...) \
96 RTW_INFO(fmt, ## args)
97 #define PHYDM_SNPRINTF snprintf
98 #elif (DM_ODM_SUPPORT_TYPE == ODM_IOT)
99 #define pr_debug(fmt, args...) RTW_PRINT_MSG(fmt, ## args)
100 #define RT_DEBUG(comp, drv_level, fmt, args...) \
101 RTW_PRINT_MSG(fmt, ## args)
102 #define PHYDM_SNPRINTF snprintf
103 #else
104 #define pr_debug panic_printk
105 /*@#define RT_PRINTK(fmt, args...) pr_debug("%s(): " fmt, __FUNCTION__, ## args);*/
106 #define RT_PRINTK(fmt, args...) pr_debug(fmt, ## args)
107 #define PHYDM_SNPRINTF snprintf
108 #endif
109
110 #ifndef ASSERT
111 #define ASSERT(expr)
112 #endif
113
114 #if DBG
115 #if (DM_ODM_SUPPORT_TYPE == ODM_AP)
116 #define PHYDM_DBG(dm, comp, fmt, args...) \
117 do { \
118 if ((comp) & dm->debug_components) { \
119 pr_debug("[PHYDM] "); \
120 RT_PRINTK(fmt, ## args); \
121 } \
122 } while (0)
123
124 #define PHYDM_DBG_F(dm, comp, fmt, args...) \
125 do { \
126 if ((comp) & dm->debug_components) { \
127 RT_PRINTK(fmt, ## args); \
128 } \
129 } while (0)
130
131 #define PHYDM_PRINT_ADDR(dm, comp, title_str, addr) \
132 do { \
133 if ((comp) & dm->debug_components) { \
134 int __i; \
135 u8 *__ptr = (u8 *)addr; \
136 pr_debug("[PHYDM] "); \
137 pr_debug(title_str); \
138 pr_debug(" "); \
139 for (__i = 0; __i < 6; __i++) \
140 pr_debug("%02X%s", __ptr[__i], (__i == 5) ? "" : "-");\
141 pr_debug("\n"); \
142 } \
143 } while (0)
144 #elif (DM_ODM_SUPPORT_TYPE == ODM_WIN)
145
PHYDM_DBG(PDM_ODM_T dm,int comp,char * fmt,...)146 static __inline void PHYDM_DBG(PDM_ODM_T dm, int comp, char *fmt, ...)
147 {
148 RT_STATUS rt_status;
149 va_list args;
150 char buf[PRINT_MAX_SIZE] = {0};
151
152 if ((comp & dm->debug_components) == 0)
153 return;
154
155 if (fmt == NULL)
156 return;
157
158 va_start(args, fmt);
159 rt_status = (RT_STATUS)RtlStringCbVPrintfA(buf, PRINT_MAX_SIZE, fmt, args);
160 va_end(args);
161
162 if (rt_status != RT_STATUS_SUCCESS) {
163 DbgPrint("Failed (%d) to print message to buffer\n", rt_status);
164 return;
165 }
166
167 #if OS_WIN_FROM_WIN10(OS_VERSION)
168 DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, "%s", buf);
169 #else
170 DbgPrint("%s", buf);
171 #endif
172 }
173
PHYDM_DBG_F(PDM_ODM_T dm,int comp,char * fmt,...)174 static __inline void PHYDM_DBG_F(PDM_ODM_T dm, int comp, char *fmt, ...)
175 {
176 RT_STATUS rt_status;
177 va_list args;
178 char buf[PRINT_MAX_SIZE] = {0};
179
180 if ((comp & dm->debug_components) == 0)
181 return;
182
183 if (fmt == NULL)
184 return;
185
186 va_start(args, fmt);
187 rt_status = (RT_STATUS)RtlStringCbVPrintfA(buf, PRINT_MAX_SIZE, fmt, args);
188 va_end(args);
189
190 if (rt_status != RT_STATUS_SUCCESS) {
191 /*@DbgPrint("DM Print Fail\n");*/
192 return;
193 }
194
195 #if OS_WIN_FROM_WIN10(OS_VERSION)
196 DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, "%s", buf);
197 #else
198 DbgPrint("%s", buf);
199 #endif
200 }
201
202 #define PHYDM_PRINT_ADDR(p_dm, comp, title_str, ptr) \
203 do { \
204 if ((comp) & p_dm->debug_components) { \
205 \
206 int __i; \
207 u8 *__ptr = (u8 *)ptr; \
208 pr_debug("[PHYDM] "); \
209 pr_debug(title_str); \
210 pr_debug(" "); \
211 for (__i = 0; __i < 6; __i++) \
212 pr_debug("%02X%s", __ptr[__i], (__i == 5) ? "" : "-"); \
213 pr_debug("\n"); \
214 } \
215 } while (0)
216 #elif (DM_ODM_SUPPORT_TYPE == ODM_IOT)
217
218 #define PHYDM_DBG(dm, comp, fmt, args...) \
219 do { \
220 if ((comp) & dm->debug_components) { \
221 RT_DEBUG(COMP_PHYDM, \
222 DBG_DMESG, "[PHYDM] " fmt, ##args); \
223 } \
224 } while (0)
225
226 #define PHYDM_DBG_F(dm, comp, fmt, args...) \
227 do { \
228 if ((comp) & dm->debug_components) { \
229 RT_DEBUG(COMP_PHYDM, \
230 DBG_DMESG, fmt, ##args); \
231 } \
232 } while (0)
233
234 #define PHYDM_PRINT_ADDR(dm, comp, title_str, addr) \
235 do { \
236 if ((comp) & dm->debug_components) { \
237 RT_DEBUG(COMP_PHYDM, \
238 DBG_DMESG, "[PHYDM] " title_str "%pM\n", \
239 addr); \
240 } \
241 } while (0)
242
243 #elif defined(DM_ODM_CE_MAC80211_V2)
244
245 #define PHYDM_DBG(dm, comp, fmt, args...)
246 #define PHYDM_DBG_F(dm, comp, fmt, args...)
247 #define PHYDM_PRINT_ADDR(dm, comp, title_str, addr)
248
249 #else
250
251 #define PHYDM_DBG(dm, comp, fmt, args...) \
252 do { \
253 struct dm_struct *__dm = (dm); \
254 if ((comp) & __dm->debug_components) { \
255 RT_TRACE(((struct rtl_priv *)__dm->adapter),\
256 COMP_PHYDM, DBG_DMESG, \
257 "[PHYDM] " fmt, ##args); \
258 } \
259 } while (0)
260
261 #define PHYDM_DBG_F(dm, comp, fmt, args...) \
262 do { \
263 struct dm_struct *__dm = (dm); \
264 if ((comp) & __dm->debug_components) { \
265 RT_TRACE(((struct rtl_priv *)__dm->adapter),\
266 COMP_PHYDM, DBG_DMESG, fmt, ##args); \
267 } \
268 } while (0)
269
270 #define PHYDM_PRINT_ADDR(dm, comp, title_str, addr) \
271 do { \
272 struct dm_struct *__dm = (dm); \
273 if ((comp) & __dm->debug_components) { \
274 RT_TRACE(((struct rtl_priv *)__dm->adapter),\
275 COMP_PHYDM, DBG_DMESG, \
276 "[PHYDM] " title_str "%pM\n", addr);\
277 } \
278 } while (0)
279 #endif
280
281 #else /*@#if DBG*/
282 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
PHYDM_DBG(struct dm_struct * dm,int comp,char * fmt,...)283 static __inline void PHYDM_DBG(struct dm_struct *dm, int comp, char *fmt, ...)
284 {
285 RT_STATUS rt_status;
286 va_list args;
287 char buf[PRINT_MAX_SIZE] = {0};
288
289 if ((comp & dm->debug_components) == 0)
290 return;
291
292 if (fmt == NULL)
293 return;
294
295 va_start(args, fmt);
296 rt_status = (RT_STATUS)RtlStringCbVPrintfA(buf, PRINT_MAX_SIZE, fmt, args);
297 va_end(args);
298
299 if (rt_status != RT_STATUS_SUCCESS) {
300 DbgPrint("Failed (%d) to print message to buffer\n", rt_status);
301 return;
302 }
303
304 PHYDM_TRACE(buf);
305 }
PHYDM_DBG_F(struct dm_struct * dm,int comp,char * fmt,...)306 static __inline void PHYDM_DBG_F(struct dm_struct *dm, int comp, char *fmt, ...)
307 {
308 }
309 #else
310 #define PHYDM_DBG(dm, comp, fmt, args...)
311 #define PHYDM_DBG_F(dm, comp, fmt, args...)
312 #endif
313 #define PHYDM_PRINT_ADDR(dm, comp, title_str, ptr)
314
315 #endif
316
317 #define DBGPORT_PRI_3 3 /*@Debug function (the highest priority)*/
318 #define DBGPORT_PRI_2 2 /*@Check hang function & Strong function*/
319 #define DBGPORT_PRI_1 1 /*Watch dog function*/
320 #define DBGPORT_RELEASE 0 /*@Init value (the lowest priority)*/
321
322 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
323 #define PHYDM_DBGPRINT 0
324 #define PHYDM_SSCANF(x, y, z) dcmd_scanf(x, y, z)
325 #define PDM_VAST_SNPF PDM_SNPF
326 #if (PHYDM_DBGPRINT == 1)
327 #define PDM_SNPF(msg) \
328 do {\
329 rsprintf msg;\
330 pr_debug("%s", output);\
331 } while (0)
332 #else
333
PDM_SNPF(u32 out_len,u32 used,char * buff,int len,char * fmt,...)334 static __inline void PDM_SNPF(u32 out_len, u32 used, char *buff, int len,
335 char *fmt, ...)
336 {
337 RT_STATUS rt_status;
338 va_list args;
339 char buf[PRINT_MAX_SIZE] = {0};
340
341 if (fmt == NULL)
342 return;
343
344 va_start(args, fmt);
345 rt_status = (RT_STATUS)RtlStringCbVPrintfA(buf, PRINT_MAX_SIZE, fmt, args);
346 va_end(args);
347
348 if (rt_status != RT_STATUS_SUCCESS) {
349 /*@DbgPrint("DM Print Fail\n");*/
350 return;
351 }
352
353 DCMD_Printf(buf);
354 }
355
356
357
358 #endif /*@#if (PHYDM_DBGPRINT == 1)*/
359 #else /*@(DM_ODM_SUPPORT_TYPE & (ODM_CE | ODM_AP))*/
360 #if (DM_ODM_SUPPORT_TYPE == ODM_CE) || defined(__OSK__)
361 #define PHYDM_DBGPRINT 0
362 #else
363 #define PHYDM_DBGPRINT 1
364 #endif
365 #define MAX_ARGC 20
366 #define MAX_ARGV 16
367 #define DCMD_DECIMAL "%d"
368 #define DCMD_CHAR "%c"
369 #define DCMD_HEX "%x"
370
371 #define PHYDM_SSCANF(x, y, z) sscanf(x, y, z)
372
373 #if (DM_ODM_SUPPORT_TYPE & ODM_AP)
374 #define PDM_VAST_SNPF(out_len, used, buff, len, fmt, args...) RT_PRINTK(fmt, ## args)
375
376 #elif (DM_ODM_SUPPORT_TYPE & ODM_IOT)
377 #define PDM_VAST_SNPF(out_len, used, buff, len, fmt, args...) \
378 do { \
379 RT_DEBUG(COMP_PHYDM, DBG_DMESG, fmt, ##args); \
380 } while (0)
381 #elif (DM_ODM_SUPPORT_TYPE == ODM_CE) && defined(DM_ODM_CE_MAC80211_V2)
382 #define PDM_VAST_SNPF(out_len, used, buff, len, fmt, args...)
383 #else
384 #define PDM_VAST_SNPF(out_len, used, buff, len, fmt, args...) \
385 RT_TRACE(((struct rtl_priv *)dm->adapter), COMP_PHYDM, \
386 DBG_DMESG, fmt, ##args)
387 #endif
388
389 #if (PHYDM_DBGPRINT == 1)
390 #define PDM_SNPF(out_len, used, buff, len, fmt, args...) \
391 do { \
392 snprintf(buff, len, fmt, ##args); \
393 pr_debug("%s", output); \
394 } while (0)
395 #else
396 #define PDM_SNPF(out_len, used, buff, len, fmt, args...) \
397 do { \
398 u32 *__pdm_snpf_u = &(used); \
399 if (out_len > *__pdm_snpf_u) \
400 *__pdm_snpf_u += snprintf(buff, len, fmt, ##args);\
401 } while (0)
402 #endif
403 #endif
404 /* @1 ============================================================
405 * 1 enumeration
406 * 1 ============================================================
407 */
408
409 enum auto_detection_state { /*@Fast antenna training*/
410 AD_LEGACY_MODE = 0,
411 AD_HT_MODE = 1,
412 AD_VHT_MODE = 2
413 };
414
415 /*@
416 * ============================================================
417 * 1 structure
418 * ============================================================
419 */
420
421 #ifdef CONFIG_PHYDM_DEBUG_FUNCTION
422 u8 phydm_get_l_sig_rate(void *dm_void, u8 rate_idx_l_sig);
423 #endif
424
425 void phydm_init_debug_setting(struct dm_struct *dm);
426
427 void phydm_bb_dbg_port_header_sel(void *dm_void, u32 header_idx);
428
429 u32 phydm_get_bb_dbg_port_idx(void *dm_void);
430
431 u8 phydm_set_bb_dbg_port(void *dm_void, u8 curr_dbg_priority, u32 debug_port);
432
433 void phydm_release_bb_dbg_port(void *dm_void);
434
435 u32 phydm_get_bb_dbg_port_val(void *dm_void);
436
437 void phydm_reset_rx_rate_distribution(struct dm_struct *dm);
438
439 void phydm_rx_rate_distribution(void *dm_void);
440
441 u16 phydm_rx_avg_phy_rate(void *dm_void);
442
443 void phydm_show_phy_hitogram(void *dm_void);
444
445 void phydm_get_avg_phystatus_val(void *dm_void);
446
447 void phydm_get_phy_statistic(void *dm_void);
448
449 void phydm_dm_summary(void *dm_void, u8 macid);
450
451 void phydm_basic_dbg_message(void *dm_void);
452
453 void phydm_basic_profile(void *dm_void, u32 *_used, char *output,
454 u32 *_out_len);
455 #if (DM_ODM_SUPPORT_TYPE & (ODM_CE | ODM_AP))
456 s32 phydm_cmd(struct dm_struct *dm, char *input, u32 in_len, u8 flag,
457 char *output, u32 out_len);
458 #endif
459 void phydm_cmd_parser(struct dm_struct *dm, char input[][16], u32 input_num,
460 u8 flag, char *output, u32 out_len);
461
462 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
463 void phydm_basic_dbg_msg_cli_win(void *dm_void, char *buf);
464
465 void phydm_sbd_check(
466 struct dm_struct *dm);
467
468 void phydm_sbd_callback(
469 struct phydm_timer_list *timer);
470
471 void phydm_sbd_workitem_callback(
472 void *context);
473 #endif
474
475 void phydm_fw_trace_en_h2c(void *dm_void, boolean enable,
476 u32 fw_debug_component, u32 monitor_mode, u32 macid);
477
478 void phydm_fw_trace_handler(void *dm_void, u8 *cmd_buf, u8 cmd_len);
479
480 void phydm_fw_trace_handler_code(void *dm_void, u8 *buffer, u8 cmd_len);
481
482 void phydm_fw_trace_handler_8051(void *dm_void, u8 *cmd_buf, u8 cmd_len);
483
484 #endif /* @__ODM_DBG_H__ */
485