xref: /freebsd/sys/dev/iavf/iavf_debug.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, Intel Corporation
3  *  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 are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @file iavf_debug.h
34  * @brief Debug macros
35  *
36  * Contains definitions for useful debug macros which can be enabled by
37  * building with IAVF_DEBUG defined.
38  */
39 #ifndef _IAVF_DEBUG_H_
40 #define _IAVF_DEBUG_H_
41 
42 #define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x"
43 #define MAC_FORMAT_ARGS(mac_addr) \
44 	(mac_addr)[0], (mac_addr)[1], (mac_addr)[2], (mac_addr)[3], \
45 	(mac_addr)[4], (mac_addr)[5]
46 
47 #ifdef IAVF_DEBUG
48 
49 #define _DBG_PRINTF(S, ...)		printf("%s: " S "\n", __func__, ##__VA_ARGS__)
50 #define _DEV_DBG_PRINTF(dev, S, ...)	device_printf(dev, "%s: " S "\n", __func__, ##__VA_ARGS__)
51 #define _IF_DBG_PRINTF(ifp, S, ...)	if_printf(ifp, "%s: " S "\n", __func__, ##__VA_ARGS__)
52 
53 /* Defines for printing generic debug information */
54 #define DPRINTF(...)			_DBG_PRINTF(__VA_ARGS__)
55 #define DDPRINTF(...)			_DEV_DBG_PRINTF(__VA_ARGS__)
56 #define IDPRINTF(...)			_IF_DBG_PRINTF(__VA_ARGS__)
57 
58 /* Defines for printing specific debug information */
59 #define DEBUG_INIT  1
60 #define DEBUG_IOCTL 1
61 #define DEBUG_HW    1
62 
63 #define INIT_DEBUGOUT(...)		if (DEBUG_INIT) _DBG_PRINTF(__VA_ARGS__)
64 #define INIT_DBG_DEV(...)		if (DEBUG_INIT) _DEV_DBG_PRINTF(__VA_ARGS__)
65 #define INIT_DBG_IF(...)		if (DEBUG_INIT) _IF_DBG_PRINTF(__VA_ARGS__)
66 
67 #define IOCTL_DEBUGOUT(...)		if (DEBUG_IOCTL) _DBG_PRINTF(__VA_ARGS__)
68 #define IOCTL_DBG_IF2(ifp, S, ...)	if (DEBUG_IOCTL) \
69 					    if_printf(ifp, S "\n", ##__VA_ARGS__)
70 #define IOCTL_DBG_IF(...)		if (DEBUG_IOCTL) _IF_DBG_PRINTF(__VA_ARGS__)
71 
72 #define HW_DEBUGOUT(...)		if (DEBUG_HW) _DBG_PRINTF(__VA_ARGS__)
73 
74 #else /* no IAVF_DEBUG */
75 #define DEBUG_INIT  0
76 #define DEBUG_IOCTL 0
77 #define DEBUG_HW    0
78 
79 #define DPRINTF(...)
80 #define DDPRINTF(...)
81 #define IDPRINTF(...)
82 
83 #define INIT_DEBUGOUT(...)
84 #define INIT_DBG_DEV(...)
85 #define INIT_DBG_IF(...)
86 #define IOCTL_DEBUGOUT(...)
87 #define IOCTL_DBG_IF2(...)
88 #define IOCTL_DBG_IF(...)
89 #define HW_DEBUGOUT(...)
90 #endif /* IAVF_DEBUG */
91 
92 /**
93  * @enum iavf_dbg_mask
94  * @brief Bitmask values for various debug messages
95  *
96  * Enumeration of possible debug message categories, represented as a bitmask.
97  *
98  * Bits are set in the softc dbg_mask field indicating which messages are
99  * enabled.
100  *
101  * Used by debug print macros in order to compare the message type with the
102  * enabled bits in the dbg_mask to decide whether to print the message or not.
103  */
104 enum iavf_dbg_mask {
105 	IAVF_DBG_INFO			= 0x00000001,
106 	IAVF_DBG_EN_DIS			= 0x00000002,
107 	IAVF_DBG_AQ			= 0x00000004,
108 	IAVF_DBG_INIT			= 0x00000008,
109 	IAVF_DBG_FILTER			= 0x00000010,
110 
111 	IAVF_DBG_RSS			= 0x00000100,
112 
113 	IAVF_DBG_VC			= 0x00001000,
114 
115 	IAVF_DBG_SWITCH_INFO		= 0x00010000,
116 
117 	IAVF_DBG_ALL			= 0xFFFFFFFF
118 };
119 
120 /* Debug printing */
121 void iavf_debug_core(device_t dev, uint32_t enabled_mask, uint32_t mask, char *fmt, ...) __printflike(4,5);
122 
123 #define iavf_dbg(sc, m, s, ...)		iavf_debug_core(sc->dev, sc->dbg_mask, m, s, ##__VA_ARGS__)
124 #define iavf_dbg_init(sc, s, ...)	iavf_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_INIT, s, ##__VA_ARGS__)
125 #define iavf_dbg_info(sc, s, ...)	iavf_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_INFO, s, ##__VA_ARGS__)
126 #define iavf_dbg_vc(sc, s, ...)		iavf_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_VC, s, ##__VA_ARGS__)
127 #define iavf_dbg_filter(sc, s, ...)	iavf_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_FILTER, s, ##__VA_ARGS__)
128 #define iavf_dbg_rss(sc, s, ...)	iavf_debug_core(sc->dev, sc->dbg_mask, IAVF_DBG_RSS, s, ##__VA_ARGS__)
129 
130 #endif /* _IAVF_DEBUG_H_ */
131