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