xref: /titanic_50/usr/src/uts/common/io/nge/nge_log.c (revision b3700b074e637f8c6991b70754c88a2cfffb246b)
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 /*
23  * Copyright 2007 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 #include "nge.h"
30 
31 
32 /*
33  * Global variable for default debug flags
34  */
35 uint32_t nge_debug;
36 
37 /*
38  * Global mutex used by logging routines below
39  */
40 kmutex_t nge_log_mutex[1];
41 
42 /*
43  * Static data used by logging routines; protected by <nge_log_mutex>
44  */
45 static struct {
46 	const char *who;
47 	const char *fmt;
48 	int level;
49 } nge_log_data;
50 
51 
52 /*
53  * Backend print routine for all the routines below
54  */
55 static void
56 nge_vprt(const char *fmt, va_list args)
57 {
58 	char buf[128];
59 
60 	ASSERT(mutex_owned(nge_log_mutex));
61 
62 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
63 	cmn_err(nge_log_data.level, nge_log_data.fmt, nge_log_data.who, buf);
64 }
65 
66 
67 /*
68  * Log a run-time event (CE_NOTE, log only)
69  */
70 void
71 nge_log(nge_t *ngep, const char *fmt, ...)
72 {
73 	va_list args;
74 
75 	mutex_enter(nge_log_mutex);
76 	nge_log_data.who = ngep->ifname;
77 	nge_log_data.fmt = "!%s: %s";
78 	nge_log_data.level = CE_NOTE;
79 
80 	va_start(args, fmt);
81 	nge_vprt(fmt, args);
82 	va_end(args);
83 
84 	mutex_exit(nge_log_mutex);
85 }
86 
87 /*
88  * Log a run-time problem (CE_WARN, log only)
89  */
90 void
91 nge_problem(nge_t *ngep, const char *fmt, ...)
92 {
93 	va_list args;
94 
95 	mutex_enter(nge_log_mutex);
96 	nge_log_data.who = ngep->ifname;
97 	nge_log_data.fmt = "!%s: %s";
98 	nge_log_data.level = CE_WARN;
99 
100 	va_start(args, fmt);
101 	nge_vprt(fmt, args);
102 	va_end(args);
103 
104 	mutex_exit(nge_log_mutex);
105 }
106 
107 /*
108  * Log a programming error (CE_WARN, log only)
109  */
110 void
111 nge_error(nge_t *ngep, const char *fmt, ...)
112 {
113 	va_list args;
114 
115 	mutex_enter(nge_log_mutex);
116 	nge_log_data.who = ngep->ifname;
117 	nge_log_data.fmt = "!%s: %s";
118 	nge_log_data.level = CE_WARN;
119 
120 	va_start(args, fmt);
121 	nge_vprt(fmt, args);
122 	va_end(args);
123 
124 	mutex_exit(nge_log_mutex);
125 }
126 
127 static const char *
128 nge_class_string(uint8_t class_id)
129 {
130 	const char *msg;
131 	switch (class_id) {
132 	default:
133 		msg = "none";
134 	break;
135 
136 	case NGE_HW_ERR:
137 		msg = "Hardware fatal error. Hardware will be reset";
138 	break;
139 
140 	case NGE_HW_LINK:
141 		msg = "the link is broken, please check the connection";
142 	break;
143 
144 	case NGE_HW_BM:
145 		msg = "Reset the hardware buffer management fails,"
146 		    "need to power off/power on system. It is hardware bug";
147 		break;
148 
149 	case NGE_HW_RCHAN:
150 		msg = "Reset rx's channel fails. Need to power off/power"
151 		    "on system";
152 		break;
153 
154 	case NGE_HW_TCHAN:
155 		msg = "Reset rx's channel fails. Need to power off/power"
156 		    "on system";
157 		break;
158 
159 	case NGE_HW_ROM:
160 		msg = "Unlock eeprom lock fails.";
161 		break;
162 
163 	case NGE_SW_PROBLEM_ID:
164 		msg = "Refill rx's bd fails";
165 	break;
166 	}
167 	return (msg);
168 }
169 
170 void
171 nge_report(nge_t *ngep, uint8_t error_id)
172 {
173 	const char *err_msg;
174 
175 	err_msg = nge_class_string(error_id);
176 	nge_error(ngep, err_msg);
177 
178 }
179 static void
180 nge_prt(const char *fmt, ...)
181 {
182 	va_list args;
183 
184 	ASSERT(mutex_owned(nge_log_mutex));
185 
186 	va_start(args, fmt);
187 	nge_vprt(fmt, args);
188 	va_end(args);
189 
190 	mutex_exit(nge_log_mutex);
191 }
192 
193 void
194 (*nge_gdb(void))(const char *fmt, ...)
195 {
196 	mutex_enter(nge_log_mutex);
197 
198 	nge_log_data.who = "nge";
199 	nge_log_data.fmt = "?%s: %s\n";
200 	nge_log_data.level = CE_CONT;
201 
202 	return (nge_prt);
203 }
204 
205 void
206 (*nge_db(nge_t *ngep))(const char *fmt, ...)
207 {
208 	mutex_enter(nge_log_mutex);
209 
210 	nge_log_data.who = ngep->ifname;
211 	nge_log_data.fmt = "?%s: %s\n";
212 	nge_log_data.level = CE_CONT;
213 
214 	return (nge_prt);
215 }
216