xref: /titanic_51/usr/src/uts/sun4/io/px/px_debug.c (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * PCI nexus driver general debug support
31  */
32 #include <sys/async.h>
33 #include <sys/sunddi.h>		/* dev_info_t */
34 #include <sys/ddi_impldefs.h>
35 #include <sys/disp.h>
36 #include "px_debug.h"
37 
38 /*LINTLIBRARY*/
39 
40 #ifdef	DEBUG
41 uint64_t px_debug_flags = (1ull << DBG_ERR_INTR | 1ull << DBG_MSG_INTR);
42 
43 static char *px_debug_sym [] = {	/* same sequence as px_debug_bit */
44 	/*  0 */ "attach",
45 	/*  1 */ "detach",
46 	/*  2 */ "map",
47 	/*  3 */ "nex-ctlops",
48 
49 	/*  4 */ "introps",
50 	/*  5 */ "intx-add",
51 	/*  6 */ "intx-rem",
52 	/*  7 */ "intx-intr",
53 
54 	/*  8 */ "msiq",
55 	/*  9 */ "msiq-intr",
56 	/* 10 */ "msg",
57 	/* 11 */ "msg-intr",
58 
59 	/* 12 */ "msix-add",
60 	/* 13 */ "msix-rem",
61 	/* 14 */ "msix-intr",
62 	/* 15 */ "err",
63 
64 	/* 16 */ "dma-alloc",
65 	/* 17 */ "dma-free",
66 	/* 18 */ "dma-bind",
67 	/* 19 */ "dma-unbind",
68 
69 	/* 20 */ "chk-dma-mode",
70 	/* 21 */ "bypass-dma",
71 	/* 22 */ "fast-dvma",
72 	/* 23 */ "init_child",
73 
74 	/* 24 */ "dma-map",
75 	/* 25 */ "dma-win",
76 	/* 26 */ "map-win",
77 	/* 27 */ "unmap-win",
78 
79 	/* 28 */ "dma-ctl",
80 	/* 29 */ "dma-sync",
81 	/* 30 */ NULL,
82 	/* 31 */ NULL,
83 
84 	/* 32 */ "ib",
85 	/* 33 */ "cb",
86 	/* 34 */ "dmc",
87 	/* 35 */ "pec",
88 
89 	/* 36 */ "ilu",
90 	/* 37 */ "tlu",
91 	/* 38 */ "lpu",
92 	/* 39 */ NULL,
93 
94 	/* 40 */ "open",
95 	/* 41 */ "close",
96 	/* 42 */ "ioctl",
97 	/* 43 */ "pwr",
98 
99 	/* 44 */ "lib-cfg",
100 	/* 45 */ "lib-intr",
101 	/* 46 */ "lib-dma",
102 	/* 47 */ "lib-msiq",
103 
104 	/* 48 */ "lib-msi",
105 	/* 49 */ "lib-msg",
106 	/* 50 */ "NULL",
107 	/* 51 */ "NULL",
108 
109 	/* 52 */ "tools",
110 	/* 53 */ "phys_acc",
111 	/* LAST */ "unknown"
112 };
113 
114 /*
115  * There are side effects of printing debug messages while servicing
116  * interrupts at PIL 14. This tunable keeps printing debug messages
117  * disabled by default.
118  *
119  * For debugging purposes set px_dbg_print != 0 to see printf messages
120  * during interrupt.
121  */
122 int px_dbg_print = 0;
123 
124 void
125 px_dbg(px_debug_bit_t bit, dev_info_t *dip, char *fmt, ...)
126 {
127 	int cont = bit >> DBG_BITS;
128 	va_list ap;
129 
130 	bit &= DBG_MASK;
131 	if (bit >= sizeof (px_debug_sym) / sizeof (char *))
132 		return;
133 	if (!(1ull << bit & px_debug_flags))
134 		return;
135 	if (cont)
136 		goto body;
137 	if (dip) {
138 		if (servicing_interrupt()) {
139 			if (px_dbg_print) {
140 				prom_printf("%s(%d): %s: ",
141 				    ddi_driver_name(dip),
142 				    ddi_get_instance(dip),
143 				    px_debug_sym[bit]);
144 			}
145 		} else {
146 			prom_printf("%s(%d): %s: ", ddi_driver_name(dip),
147 			    ddi_get_instance(dip), px_debug_sym[bit]);
148 		}
149 	} else {
150 		if (servicing_interrupt()) {
151 			if (px_dbg_print) {
152 				prom_printf("px: %s: ", px_debug_sym[bit]);
153 			}
154 		} else {
155 			prom_printf("px: %s: ", px_debug_sym[bit]);
156 		}
157 	}
158 body:
159 	va_start(ap, fmt);
160 	if (servicing_interrupt()) {
161 		if (px_dbg_print) {
162 			prom_vprintf(fmt, ap);
163 		}
164 	} else {
165 		prom_vprintf(fmt, ap);
166 	}
167 	va_end(ap);
168 }
169 #else	/* DEBUG */
170 
171 
172 /*ARGSUSED*/
173 void
174 px_log2ce(px_debug_bit_t bit, dev_info_t *dip, char *fmt, ...)
175 {
176 	va_list ap;
177 
178 	if (servicing_interrupt())
179 		return;
180 
181 	if (dip)
182 		cmn_err(CE_WARN, "%s(%d): ",
183 			ddi_driver_name(dip), ddi_get_instance(dip));
184 	else
185 		cmn_err(CE_WARN, "px: ");
186 	va_start(ap, fmt);
187 	vcmn_err(CE_CONT, fmt, ap);
188 	va_end(ap);
189 }
190 
191 #endif	/* DEBUG */
192