Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/aq/aq_dbg.h
96295 views
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 [email protected]
37
*/
38
#ifndef AQ_DBG_H
39
#define AQ_DBG_H
40
41
#include <sys/systm.h>
42
#include <sys/syslog.h>
43
/*
44
Debug levels:
45
0 - no debug
46
1 - important warnings
47
2 - debug prints
48
3 - trace function calls
49
4 - dump descriptor
50
*/
51
52
#define AQ_CFG_DEBUG_LVL 0x0
53
54
#define AQ_DBG_ERROR(string, args...) printf( "atlantic: " string "\n", ##args)
55
56
/* Debug stuff */
57
#if AQ_CFG_DEBUG_LVL > 0
58
#define AQ_DBG_WARNING(string, args...) printf( "atlantic: " string "\n", ##args)
59
#else
60
#define AQ_DBG_WARNING(string, ...)
61
#endif
62
63
#if AQ_CFG_DEBUG_LVL > 1
64
#define AQ_DBG_PRINT(string, args...) printf( "atlantic: " string "\n", ##args)
65
#else
66
#define AQ_DBG_PRINT(string, ...)
67
#endif
68
69
#if AQ_CFG_DEBUG_LVL > 2
70
#define AQ_DBG_ENTER() printf( "atlantic: %s() {\n", __func__)
71
#define AQ_DBG_ENTERA(s, args...) printf( "atlantic: %s(" s ") {\n", __func__, ##args)
72
#define AQ_DBG_EXIT(err) printf( "atlantic: } %s(), err=%d\n", __func__, err)
73
#else
74
#define AQ_DBG_ENTER()
75
#define AQ_DBG_ENTERA(s, args...)
76
#define AQ_DBG_EXIT(err)
77
#endif
78
79
#if AQ_CFG_DEBUG_LVL > 2
80
#define AQ_DBG_DUMP_DESC(desc) { \
81
volatile uint8_t *raw = (volatile uint8_t*)(desc); \
82
printf( "07-00 %02X%02X%02X%02X %02X%02X%02X%02X 15-08 %02X%02X%02X%02X %02X%02X%02X%02X\n", \
83
raw[7], raw[6], raw[5], raw[4], raw[3], raw[2], raw[1], raw[0], \
84
raw[15], raw[14], raw[13], raw[12], raw[11], raw[10], raw[9], raw[8]); \
85
}\
86
87
#else
88
#define AQ_DBG_DUMP_DESC(desc)
89
#endif
90
91
typedef enum aq_debug_level
92
{
93
lvl_error = LOG_ERR,
94
lvl_warn = LOG_WARNING,
95
lvl_trace = LOG_NOTICE,
96
lvl_detail = LOG_INFO,
97
} aq_debug_level;
98
99
typedef enum aq_debug_category
100
{
101
dbg_init = 1,
102
dbg_config = 1 << 1,
103
dbg_tx = 1 << 2,
104
dbg_rx = 1 << 3,
105
dbg_intr = 1 << 4,
106
dbg_fw = 1 << 5,
107
} aq_debug_category;
108
109
110
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
111
112
extern const aq_debug_level dbg_level_;
113
extern const uint32_t dbg_categories_;
114
115
#define log_base_(_lvl, _fmt, args...) printf( "atlantic: " _fmt "\n", ##args)
116
117
#if AQ_CFG_DEBUG_LVL > 0
118
#define trace_base_(_lvl, _cat, _fmt, args...) do { if (dbg_level_ >= _lvl && (_cat & dbg_categories_)) { printf( "atlantic: " _fmt " @%s,%d\n", ##args, __FILENAME__, __LINE__); }} while (0)
119
#else
120
#define trace_base_(_lvl, _cat, _fmt, ...) do {} while (0)
121
#endif // AQ_CFG_DEBUG_LVL > 0
122
123
#define aq_log_error(_fmt, args...) log_base_(lvl_error, "[!] " _fmt, ##args)
124
#define aq_log_warn(_fmt, args...) log_base_(lvl_warn, "/!\\ " _fmt, ##args)
125
#define aq_log(_fmt, args...) log_base_(lvl_trace, _fmt, ##args)
126
#define aq_log_detail(_fmt, args...) log_base_(lvl_detail, _fmt, ##args)
127
128
#define trace_error(_cat,_fmt, args...) trace_base_(lvl_error, _cat, "[!] " _fmt, ##args)
129
#define trace_warn(_cat, _fmt, args...) trace_base_(lvl_warn, _cat, "/!\\ " _fmt, ##args)
130
#define trace(_cat, _fmt, args...) trace_base_(lvl_trace, _cat, _fmt, ##args)
131
#define trace_detail(_cat, _fmt, args...) trace_base_(lvl_detail, _cat, _fmt, ##args)
132
133
void trace_aq_tx_descr(int ring_idx, unsigned int pointer, volatile uint64_t descr[2]);
134
void trace_aq_rx_descr(int ring_idx, unsigned int pointer, volatile uint64_t descr[2]);
135
void trace_aq_tx_context_descr(int ring_idx, unsigned int pointer, volatile uint64_t descr[2]);
136
void DumpHex(const void* data, size_t size);
137
138
#endif // AQ_DBG_H
139
140