xref: /titanic_44/usr/src/uts/common/io/bge/bge_log.c (revision 0d2a8e5eea8ac6ea0f5c517f0c481329b57d5459)
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 "bge_impl.h"
30 
31 
32 /*
33  * Global variable for default debug flags
34  */
35 uint32_t bge_debug;
36 
37 /*
38  * Global mutex used by logging routines below
39  */
40 kmutex_t bge_log_mutex[1];
41 
42 /*
43  * Static data used by logging routines; protected by <bge_log_mutex>
44  */
45 static struct {
46 	const char *who;
47 	const char *fmt;
48 	int level;
49 } bge_log_data;
50 
51 
52 /*
53  * Backend print routine for all the routines below
54  */
55 static void
bge_vprt(const char * fmt,va_list args)56 bge_vprt(const char *fmt, va_list args)
57 {
58 	char buf[128];
59 
60 	ASSERT(mutex_owned(bge_log_mutex));
61 
62 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
63 	cmn_err(bge_log_data.level, bge_log_data.fmt, bge_log_data.who, buf);
64 }
65 
66 /*
67  * Log a run-time event (CE_NOTE, log only)
68  */
69 void
bge_log(bge_t * bgep,const char * fmt,...)70 bge_log(bge_t *bgep, const char *fmt, ...)
71 {
72 	va_list args;
73 
74 	mutex_enter(bge_log_mutex);
75 	bge_log_data.who = bgep->ifname;
76 	bge_log_data.fmt = "!%s: %s";
77 	bge_log_data.level = CE_NOTE;
78 
79 	va_start(args, fmt);
80 	bge_vprt(fmt, args);
81 	va_end(args);
82 
83 	mutex_exit(bge_log_mutex);
84 }
85 
86 /*
87  * Log a run-time problem (CE_WARN, log only)
88  */
89 void
bge_problem(bge_t * bgep,const char * fmt,...)90 bge_problem(bge_t *bgep, const char *fmt, ...)
91 {
92 	va_list args;
93 
94 	mutex_enter(bge_log_mutex);
95 	bge_log_data.who = bgep->ifname;
96 	bge_log_data.fmt = "!%s: %s";
97 	bge_log_data.level = CE_WARN;
98 
99 	va_start(args, fmt);
100 	bge_vprt(fmt, args);
101 	va_end(args);
102 
103 	mutex_exit(bge_log_mutex);
104 }
105 
106 /*
107  * Log a programming error (CE_WARN, log only)
108  */
109 void
bge_error(bge_t * bgep,const char * fmt,...)110 bge_error(bge_t *bgep, const char *fmt, ...)
111 {
112 	va_list args;
113 
114 	mutex_enter(bge_log_mutex);
115 	bge_log_data.who = bgep->ifname;
116 	bge_log_data.fmt = "!%s: %s";
117 	bge_log_data.level = CE_WARN;
118 
119 	va_start(args, fmt);
120 	bge_vprt(fmt, args);
121 	va_end(args);
122 
123 	mutex_exit(bge_log_mutex);
124 }
125 
126 void
bge_fm_ereport(bge_t * bgep,char * detail)127 bge_fm_ereport(bge_t *bgep, char *detail)
128 {
129 	uint64_t ena;
130 	char buf[FM_MAX_CLASS];
131 
132 	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
133 	ena = fm_ena_generate(0, FM_ENA_FMT1);
134 	if (DDI_FM_EREPORT_CAP(bgep->fm_capabilities)) {
135 		ddi_fm_ereport_post(bgep->devinfo, buf, ena, DDI_NOSLEEP,
136 		    FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL);
137 	}
138 }
139 
140 #if	BGE_DEBUGGING
141 
142 static void
bge_prt(const char * fmt,...)143 bge_prt(const char *fmt, ...)
144 {
145 	va_list args;
146 
147 	ASSERT(mutex_owned(bge_log_mutex));
148 
149 	va_start(args, fmt);
150 	bge_vprt(fmt, args);
151 	va_end(args);
152 
153 	mutex_exit(bge_log_mutex);
154 }
155 
156 void
bge_gdb(void)157 (*bge_gdb(void))(const char *fmt, ...)
158 {
159 	mutex_enter(bge_log_mutex);
160 	bge_log_data.who = "bge";
161 	bge_log_data.fmt = "?%s: %s\n";
162 	bge_log_data.level = CE_CONT;
163 
164 	return (bge_prt);
165 }
166 
167 void
bge_db(bge_t * bgep)168 (*bge_db(bge_t *bgep))(const char *fmt, ...)
169 {
170 	mutex_enter(bge_log_mutex);
171 	bge_log_data.who = bgep->ifname;
172 	bge_log_data.fmt = "?%s: %s\n";
173 	bge_log_data.level = CE_CONT;
174 
175 	return (bge_prt);
176 }
177 
178 /*
179  * Dump a chunk of memory, 16 bytes at a time
180  */
181 static void
minidump(bge_t * bgep,const char * caption,void * dp,uint_t len)182 minidump(bge_t *bgep, const char *caption, void *dp, uint_t len)
183 {
184 	uint32_t buf[4];
185 	uint32_t nbytes;
186 
187 	bge_log(bgep, "%d bytes of %s at address %p:-", len, caption, dp);
188 
189 	for (len = MIN(len, BGE_STD_BUFF_SIZE); len != 0; len -= nbytes) {
190 		nbytes = MIN(len, sizeof (buf));
191 		bzero(buf, sizeof (buf));
192 		bcopy(dp, buf, nbytes);
193 		bge_log(bgep, "%08x %08x %08x %08x",
194 			buf[0], buf[1], buf[2], buf[3]);
195 		dp = (caddr_t)dp + nbytes;
196 	}
197 }
198 
199 void
bge_pkt_dump(bge_t * bgep,bge_rbd_t * hrbdp,sw_rbd_t * srbdp,const char * msg)200 bge_pkt_dump(bge_t *bgep, bge_rbd_t *hrbdp, sw_rbd_t *srbdp, const char *msg)
201 {
202 	bge_problem(bgep, "driver-detected hardware error: %s", msg);
203 
204 	minidump(bgep, "hardware descriptor", hrbdp, sizeof (*hrbdp));
205 
206 	bge_log(bgep, "PCI address %llx packet len 0x%x token 0x%x "
207 			"flags 0x%x index 0x%x",
208 			hrbdp->host_buf_addr,
209 			hrbdp->len,
210 			hrbdp->opaque,
211 			hrbdp->flags,
212 			hrbdp->index);
213 
214 	if (srbdp != NULL) {
215 		minidump(bgep, "software descriptor", srbdp, sizeof (*srbdp));
216 
217 		bge_log(bgep, "PCI address %llx buffer len 0x%x token 0x%x",
218 			srbdp->pbuf.cookie.dmac_laddress,
219 			srbdp->pbuf.alength,
220 			srbdp->pbuf.token);
221 
222 		minidump(bgep, "packet data", srbdp->pbuf.mem_va, hrbdp->len);
223 	}
224 }
225 
226 void
bge_dbg_enter(bge_t * bgep,const char * s)227 bge_dbg_enter(bge_t *bgep, const char *s)
228 {
229 	uint32_t debug;
230 
231 	debug = bgep != NULL ? bgep->debug : bge_debug;
232 	if (debug & BGE_DBG_STOP) {
233 		cmn_err(CE_CONT, "bge_dbg_enter(%p): %s\n", (void *)bgep, s);
234 		debug_enter("");
235 	}
236 }
237 
238 #endif	/* BGE_DEBUGGING */
239