1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *	Copyright IBM Corp. 2001, 2007
4  *	Authors:	Peter Tiedemann (ptiedem@de.ibm.com)
5  *
6  */
7 
8 #ifndef _CTCM_DBUG_H_
9 #define _CTCM_DBUG_H_
10 
11 /*
12  * Debug Facility stuff
13  */
14 
15 #include <asm/debug.h>
16 
17 #ifdef DEBUG
18  #define do_debug 1
19 #else
20  #define do_debug 0
21 #endif
22 #ifdef DEBUGCCW
23  #define do_debug_ccw 1
24  #define DEBUGDATA 1
25 #else
26  #define do_debug_ccw 0
27 #endif
28 #ifdef DEBUGDATA
29  #define do_debug_data 1
30 #else
31  #define do_debug_data 0
32 #endif
33 
34 /* define dbf debug levels similar to kernel msg levels */
35 #define	CTC_DBF_ALWAYS	0	/* always print this 			*/
36 #define	CTC_DBF_EMERG	0	/* system is unusable			*/
37 #define	CTC_DBF_ALERT	1	/* action must be taken immediately	*/
38 #define	CTC_DBF_CRIT	2	/* critical conditions			*/
39 #define	CTC_DBF_ERROR	3	/* error conditions			*/
40 #define	CTC_DBF_WARN	4	/* warning conditions			*/
41 #define	CTC_DBF_NOTICE	5	/* normal but significant condition	*/
42 #define	CTC_DBF_INFO	5	/* informational			*/
43 #define	CTC_DBF_DEBUG	6	/* debug-level messages			*/
44 
45 enum ctcm_dbf_names {
46 	CTCM_DBF_SETUP,
47 	CTCM_DBF_ERROR,
48 	CTCM_DBF_TRACE,
49 	CTCM_DBF_MPC_SETUP,
50 	CTCM_DBF_MPC_ERROR,
51 	CTCM_DBF_MPC_TRACE,
52 	CTCM_DBF_INFOS	/* must be last element */
53 };
54 
55 struct ctcm_dbf_info {
56 	char name[DEBUG_MAX_NAME_LEN];
57 	int pages;
58 	int areas;
59 	int len;
60 	int level;
61 	debug_info_t *id;
62 };
63 
64 extern struct ctcm_dbf_info ctcm_dbf[CTCM_DBF_INFOS];
65 
66 int ctcm_register_dbf_views(void);
67 void ctcm_unregister_dbf_views(void);
68 void ctcm_dbf_longtext(enum ctcm_dbf_names dbf_nix, int level, char *text, ...);
69 
strtail(const char * s,int n)70 static inline const char *strtail(const char *s, int n)
71 {
72 	int l = strlen(s);
73 	return (l > n) ? s + (l - n) : s;
74 }
75 
76 #define CTCM_FUNTAIL strtail((char *)__func__, 16)
77 
78 #define CTCM_DBF_TEXT(name, level, text) \
79 	do { \
80 		debug_text_event(ctcm_dbf[CTCM_DBF_##name].id, level, text); \
81 	} while (0)
82 
83 #define CTCM_DBF_HEX(name, level, addr, len) \
84 	do { \
85 		debug_event(ctcm_dbf[CTCM_DBF_##name].id, \
86 					level, (void *)(addr), len); \
87 	} while (0)
88 
89 #define CTCM_DBF_TEXT_(name, level, text...) \
90 	ctcm_dbf_longtext(CTCM_DBF_##name, level, text)
91 
92 /*
93  * cat : one of {setup, mpc_setup, trace, mpc_trace, error, mpc_error}.
94  * dev : netdevice with valid name field.
95  * text: any text string.
96  */
97 #define CTCM_DBF_DEV_NAME(cat, dev, text) \
98 	do { \
99 		CTCM_DBF_TEXT_(cat, CTC_DBF_INFO, "%s(%s) :- %s", \
100 			CTCM_FUNTAIL, dev->name, text); \
101 	} while (0)
102 
103 #define MPC_DBF_DEV_NAME(cat, dev, text) \
104 	do { \
105 		CTCM_DBF_TEXT_(MPC_##cat, CTC_DBF_INFO, "%s(%s) := %s", \
106 			CTCM_FUNTAIL, dev->name, text); \
107 	} while (0)
108 
109 #define CTCMY_DBF_DEV_NAME(cat, dev, text) \
110 	do { \
111 		if (IS_MPCDEV(dev)) \
112 			MPC_DBF_DEV_NAME(cat, dev, text); \
113 		else \
114 			CTCM_DBF_DEV_NAME(cat, dev, text); \
115 	} while (0)
116 
117 /*
118  * cat : one of {setup, mpc_setup, trace, mpc_trace, error, mpc_error}.
119  * dev : netdevice.
120  * text: any text string.
121  */
122 #define CTCM_DBF_DEV(cat, dev, text) \
123 	do { \
124 		CTCM_DBF_TEXT_(cat, CTC_DBF_INFO, "%s(%p) :-: %s", \
125 			CTCM_FUNTAIL, dev, text); \
126 	} while (0)
127 
128 #define MPC_DBF_DEV(cat, dev, text) \
129 	do { \
130 		CTCM_DBF_TEXT_(MPC_##cat, CTC_DBF_INFO, "%s(%p) :=: %s", \
131 			CTCM_FUNTAIL, dev, text); \
132 	} while (0)
133 
134 #define CTCMY_DBF_DEV(cat, dev, text) \
135 	do { \
136 		if (IS_MPCDEV(dev)) \
137 			MPC_DBF_DEV(cat, dev, text); \
138 		else \
139 			CTCM_DBF_DEV(cat, dev, text); \
140 	} while (0)
141 
142 #endif
143