xref: /titanic_52/usr/src/uts/common/io/dmfe/dmfe_log.c (revision b6c3f7863936abeae522e48a13887dddeb691a45)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include "dmfe_impl.h"
29 
30 
31 /*
32  * Debug flags
33  */
34 
35 #if	DMFEDEBUG
36 uint32_t dmfe_debug = 0;
37 #endif	/* DMFEDEBUG */
38 
39 
40 /*
41  *	========== Message printing & debug routines ==========
42  */
43 
44 static struct {
45 	kmutex_t mutex[1];
46 	const char *ifname;
47 	const char *fmt;
48 	int level;
49 } prtdata;
50 
51 void
52 dmfe_log_init()
53 {
54 	mutex_init(prtdata.mutex, NULL, MUTEX_DRIVER, NULL);
55 }
56 
57 void
58 dmfe_log_fini()
59 {
60 	mutex_destroy(prtdata.mutex);
61 }
62 
63 /*
64  * Backend print routine for all the routines below
65  */
66 static void
67 dmfe_vprt(const char *fmt, va_list args)
68 {
69 	char buf[128];
70 
71 	ASSERT(mutex_owned(prtdata.mutex));
72 
73 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
74 	cmn_err(prtdata.level, prtdata.fmt, prtdata.ifname, buf);
75 }
76 
77 #if	DMFEDEBUG
78 
79 static void
80 dmfe_prt(const char *fmt, ...)
81 {
82 	va_list args;
83 
84 	ASSERT(mutex_owned(prtdata.mutex));
85 
86 	va_start(args, fmt);
87 	dmfe_vprt(fmt, args);
88 	va_end(args);
89 
90 	mutex_exit(prtdata.mutex);
91 }
92 
93 void
94 (*dmfe_db(dmfe_t *dmfep))(const char *fmt, ...)
95 {
96 	mutex_enter(prtdata.mutex);
97 	prtdata.ifname = dmfep->ifname;
98 	prtdata.fmt = "^%s: %s\n";
99 	prtdata.level = CE_CONT;
100 
101 	return (dmfe_prt);
102 }
103 
104 void
105 (*dmfe_gdb())(const char *fmt, ...)
106 {
107 	mutex_enter(prtdata.mutex);
108 	prtdata.ifname = "dmfe";
109 	prtdata.fmt = "^%s: %s\n";
110 	prtdata.level = CE_CONT;
111 
112 	return (dmfe_prt);
113 }
114 
115 #endif	/* DMFEDEBUG */
116 
117 /*
118  * Report a run-time error (CE_WARN, to console & log)
119  * Also logs all the chip's operating registers
120  */
121 void
122 dmfe_warning(dmfe_t *dmfep, const char *fmt, ...)
123 {
124 	va_list args;
125 	uint32_t reg;
126 	int i;
127 
128 	mutex_enter(prtdata.mutex);
129 	prtdata.ifname = dmfep->ifname;
130 	prtdata.fmt = "%s: %s";
131 	prtdata.level = CE_WARN;
132 
133 	va_start(args, fmt);
134 	dmfe_vprt(fmt, args);
135 	va_end(args);
136 
137 	/*
138 	 * Record all the chip registers in the logfile
139 	 */
140 	for (i = 0; i < 16; ++i) {
141 		reg = dmfe_chip_get32(dmfep, 8*i);
142 		cmn_err(CE_NOTE, "!%s: CR%d\t%08x", dmfep->ifname, i, reg);
143 	}
144 
145 	mutex_exit(prtdata.mutex);
146 }
147 
148 /*
149  * Log a programming error (CE_WARN, log only)
150  */
151 void
152 dmfe_error(dmfe_t *dmfep, const char *fmt, ...)
153 {
154 	va_list args;
155 
156 	mutex_enter(prtdata.mutex);
157 	prtdata.ifname = dmfep->ifname;
158 	prtdata.fmt = "!%s: %s";
159 	prtdata.level = CE_WARN;
160 
161 	va_start(args, fmt);
162 	dmfe_vprt(fmt, args);
163 	va_end(args);
164 
165 	mutex_exit(prtdata.mutex);
166 }
167 
168 /*
169  * Report a run-time event (CE_NOTE, to console & log)
170  */
171 void
172 dmfe_notice(dmfe_t *dmfep, const char *fmt, ...)
173 {
174 	va_list args;
175 
176 	mutex_enter(prtdata.mutex);
177 	prtdata.ifname = dmfep->ifname;
178 	prtdata.fmt = "%s: %s";
179 	prtdata.level = CE_NOTE;
180 
181 	va_start(args, fmt);
182 	dmfe_vprt(fmt, args);
183 	va_end(args);
184 
185 	mutex_exit(prtdata.mutex);
186 }
187 
188 /*
189  * Log a run-time event (CE_NOTE, log only)
190  */
191 void
192 dmfe_log(dmfe_t *dmfep, const char *fmt, ...)
193 {
194 	va_list args;
195 
196 	mutex_enter(prtdata.mutex);
197 	prtdata.ifname = dmfep->ifname;
198 	prtdata.fmt = "!%s: %s";
199 	prtdata.level = CE_NOTE;
200 
201 	va_start(args, fmt);
202 	dmfe_vprt(fmt, args);
203 	va_end(args);
204 
205 	mutex_exit(prtdata.mutex);
206 }
207