xref: /freebsd/sys/dev/aq/aq_dbg.h (revision ae7e2c9170f6f7e39ab3132eb72c89f9f6e3a4d6)
1 /**
2  * aQuantia Corporation Network Driver
3  * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  *   (1) Redistributions of source code must retain the above
10  *   copyright notice, this list of conditions and the following
11  *   disclaimer.
12  *
13  *   (2) Redistributions in binary form must reproduce the above
14  *   copyright notice, this list of conditions and the following
15  *   disclaimer in the documentation and/or other materials provided
16  *   with the distribution.
17  *
18  *   (3) The name of the author may not be used to endorse or promote
19  *   products derived from this software without specific prior
20  *   written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * @file aq_dbg.h
35  * Debug print macros & definitions.
36  * @date 2017.12.07  @author roman.agafonov@aquantia.com
37  */
38 #ifndef AQ_DBG_H
39 #define AQ_DBG_H
40 
41 #include <sys/systm.h>
42 #include <sys/syslog.h>
43 
44 #include "aq_device.h"
45 /*
46 Debug levels:
47 0 - no debug
48 1 - important warnings
49 2 - debug prints
50 3 - trace function calls
51 4 - dump descriptor
52 */
53 
54 #define AQ_CFG_DEBUG_LVL   0x0
55 
56 #define AQ_DBG_ERROR(string, args...) printf( "atlantic: " string "\n", ##args)
57 
58 /* Debug stuff */
59 #if AQ_CFG_DEBUG_LVL > 0
60 #define AQ_DBG_WARNING(string, args...) printf( "atlantic: " string "\n", ##args)
61 #else
62 #define AQ_DBG_WARNING(string, ...)
63 #endif
64 
65 #if AQ_CFG_DEBUG_LVL > 1
66 #define AQ_DBG_PRINT(string, args...) printf( "atlantic: " string "\n", ##args)
67 #else
68 #define AQ_DBG_PRINT(string, ...)
69 #endif
70 
71 #if AQ_CFG_DEBUG_LVL > 2
72 #define AQ_DBG_ENTER() printf( "atlantic: %s() {\n", __func__)
73 #define AQ_DBG_ENTERA(s, args...) printf( "atlantic: %s(" s ") {\n", __func__, ##args)
74 #define AQ_DBG_EXIT(err) printf( "atlantic: } %s(), err=%d\n", __func__, err)
75 #else
76 #define AQ_DBG_ENTER()
77 #define AQ_DBG_ENTERA(s, args...)
78 #define AQ_DBG_EXIT(err)
79 #endif
80 
81 #if AQ_CFG_DEBUG_LVL > 2
82 #define AQ_DBG_DUMP_DESC(desc) { \
83 	volatile uint8_t *raw = (volatile uint8_t*)(desc); \
84 	printf( "07-00 %02X%02X%02X%02X %02X%02X%02X%02X 15-08 %02X%02X%02X%02X %02X%02X%02X%02X\n", \
85 	    raw[7], raw[6], raw[5], raw[4], raw[3], raw[2], raw[1], raw[0], \
86 	    raw[15], raw[14], raw[13], raw[12], raw[11], raw[10], raw[9], raw[8]); \
87 }\
88 
89 #else
90 #define AQ_DBG_DUMP_DESC(desc)
91 #endif
92 
93 enum aq_debug_level
94 {
95 	lvl_error = LOG_ERR,
96 	lvl_warn = LOG_WARNING,
97 	lvl_trace = LOG_NOTICE,
98 	lvl_detail = LOG_INFO,
99 };
100 
101 enum aq_debug_category
102 {
103 	dbg_init    = 1,
104 	dbg_config  = 1 << 1,
105 	dbg_tx      = 1 << 2,
106 	dbg_rx      = 1 << 3,
107 	dbg_intr    = 1 << 4,
108 	dbg_fw      = 1 << 5,
109 };
110 
111 
112 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
113 
114 #define AQ_DBG_LEVEL_DEFAULT		lvl_error
115 #define AQ_DBG_CATEGORIES_DEFAULT	(dbg_init | dbg_config | dbg_tx |	\
116 					 dbg_rx | dbg_intr | dbg_fw)
117 
118 /* NULL until aq_if_attach_pre() wires it up; traces run before that. */
119 #define AQ_DBG_SOFTC(_hw)	((struct aq_dev *)(_hw)->aq_dev)
120 
121 #define aq_log_base(_hw, _lvl, _fmt, args...) do {			\
122 	const struct aq_dev *_sc = AQ_DBG_SOFTC(_hw);			\
123 									\
124 	if (_sc != NULL && _sc->dbg_level >= (_lvl))			\
125 		device_printf((_hw)->dev, _fmt "\n", ##args);		\
126 } while (0)
127 
128 #define aq_trace_base(_hw, _lvl, _cat, _fmt, args...) do {		\
129 	const struct aq_dev *_sc = AQ_DBG_SOFTC(_hw);			\
130 									\
131 	if (_sc != NULL && _sc->dbg_level >= (_lvl) &&			\
132 	    ((_cat) & _sc->dbg_categories))				\
133 		device_printf((_hw)->dev, _fmt " @%s,%d\n", ##args,	\
134 		    __FILENAME__, __LINE__);				\
135 } while (0)
136 
137 #define aq_log_warn(_hw, _fmt, args...)					\
138 	aq_log_base(_hw, lvl_warn, "/!\\ " _fmt, ##args)
139 #define aq_log(_hw, _fmt, args...)					\
140 	aq_log_base(_hw, lvl_trace, _fmt, ##args)
141 #define aq_log_detail(_hw, _fmt, args...)				\
142 	aq_log_base(_hw, lvl_detail, _fmt, ##args)
143 
144 #define trace_error(_hw, _cat, _fmt, args...)				\
145 	aq_trace_base(_hw, lvl_error, _cat, "[!] " _fmt, ##args)
146 #define trace_warn(_hw, _cat, _fmt, args...)				\
147 	aq_trace_base(_hw, lvl_warn, _cat, "/!\\ " _fmt, ##args)
148 #define trace(_hw, _cat, _fmt, args...)					\
149 	aq_trace_base(_hw, lvl_trace, _cat, _fmt, ##args)
150 #define trace_detail(_hw, _cat, _fmt, args...)				\
151 	aq_trace_base(_hw, lvl_detail, _cat, _fmt, ##args)
152 
153 #if AQ_CFG_DEBUG_LVL > 2
154 void trace_aq_tx_descr(struct aq_hw *hw, int ring_idx, unsigned int pointer,
155     volatile uint64_t descr[2]);
156 void trace_aq_rx_descr(struct aq_hw *hw, int ring_idx, unsigned int pointer,
157     volatile uint64_t descr[2]);
158 void trace_aq_tx_context_descr(struct aq_hw *hw, int ring_idx,
159     unsigned int pointer, volatile uint64_t descr[2]);
160 #else
161 #define trace_aq_tx_descr(...)		((void)0)
162 #define trace_aq_rx_descr(...)		((void)0)
163 #define trace_aq_tx_context_descr(...)	((void)0)
164 #endif
165 
166 #endif // AQ_DBG_H
167