xref: /onnv-gate/usr/src/uts/common/io/rge/rge_log.c (revision 744:a5be23ccdb68)
1*744Sgs150176 /*
2*744Sgs150176  * CDDL HEADER START
3*744Sgs150176  *
4*744Sgs150176  * The contents of this file are subject to the terms of the
5*744Sgs150176  * Common Development and Distribution License, Version 1.0 only
6*744Sgs150176  * (the "License").  You may not use this file except in compliance
7*744Sgs150176  * with the License.
8*744Sgs150176  *
9*744Sgs150176  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*744Sgs150176  * or http://www.opensolaris.org/os/licensing.
11*744Sgs150176  * See the License for the specific language governing permissions
12*744Sgs150176  * and limitations under the License.
13*744Sgs150176  *
14*744Sgs150176  * When distributing Covered Code, include this CDDL HEADER in each
15*744Sgs150176  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*744Sgs150176  * If applicable, add the following below this CDDL HEADER, with the
17*744Sgs150176  * fields enclosed by brackets "[]" replaced with your own identifying
18*744Sgs150176  * information: Portions Copyright [yyyy] [name of copyright owner]
19*744Sgs150176  *
20*744Sgs150176  * CDDL HEADER END
21*744Sgs150176  */
22*744Sgs150176 /*
23*744Sgs150176  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*744Sgs150176  * Use is subject to license terms.
25*744Sgs150176  */
26*744Sgs150176 
27*744Sgs150176 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*744Sgs150176 
29*744Sgs150176 #include "rge.h"
30*744Sgs150176 
31*744Sgs150176 
32*744Sgs150176 /*
33*744Sgs150176  * Global variable for default debug flags
34*744Sgs150176  */
35*744Sgs150176 uint32_t rge_debug;
36*744Sgs150176 
37*744Sgs150176 /*
38*744Sgs150176  * Global mutex used by logging routines below
39*744Sgs150176  */
40*744Sgs150176 kmutex_t rge_log_mutex[1];
41*744Sgs150176 
42*744Sgs150176 /*
43*744Sgs150176  * Static data used by logging routines; protected by <rge_log_mutex>
44*744Sgs150176  */
45*744Sgs150176 static struct {
46*744Sgs150176 	const char *who;
47*744Sgs150176 	const char *fmt;
48*744Sgs150176 	int level;
49*744Sgs150176 } rge_log_data;
50*744Sgs150176 
51*744Sgs150176 
52*744Sgs150176 /*
53*744Sgs150176  * Backend print routine for all the routines below
54*744Sgs150176  */
55*744Sgs150176 static void
rge_vprt(const char * fmt,va_list args)56*744Sgs150176 rge_vprt(const char *fmt, va_list args)
57*744Sgs150176 {
58*744Sgs150176 	char buf[128];
59*744Sgs150176 
60*744Sgs150176 	ASSERT(mutex_owned(rge_log_mutex));
61*744Sgs150176 
62*744Sgs150176 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
63*744Sgs150176 	cmn_err(rge_log_data.level, rge_log_data.fmt, rge_log_data.who, buf);
64*744Sgs150176 }
65*744Sgs150176 
66*744Sgs150176 /*
67*744Sgs150176  * Report a run-time event (CE_NOTE, to console & log)
68*744Sgs150176  */
69*744Sgs150176 void
rge_notice(rge_t * rgep,const char * fmt,...)70*744Sgs150176 rge_notice(rge_t *rgep, const char *fmt, ...)
71*744Sgs150176 {
72*744Sgs150176 	va_list args;
73*744Sgs150176 
74*744Sgs150176 	mutex_enter(rge_log_mutex);
75*744Sgs150176 	rge_log_data.who = rgep->ifname;
76*744Sgs150176 	rge_log_data.fmt = "%s: %s";
77*744Sgs150176 	rge_log_data.level = CE_NOTE;
78*744Sgs150176 
79*744Sgs150176 	va_start(args, fmt);
80*744Sgs150176 	rge_vprt(fmt, args);
81*744Sgs150176 	va_end(args);
82*744Sgs150176 
83*744Sgs150176 	mutex_exit(rge_log_mutex);
84*744Sgs150176 }
85*744Sgs150176 
86*744Sgs150176 /*
87*744Sgs150176  * Log a run-time event (CE_NOTE, log only)
88*744Sgs150176  */
89*744Sgs150176 void
rge_log(rge_t * rgep,const char * fmt,...)90*744Sgs150176 rge_log(rge_t *rgep, const char *fmt, ...)
91*744Sgs150176 {
92*744Sgs150176 	va_list args;
93*744Sgs150176 
94*744Sgs150176 	mutex_enter(rge_log_mutex);
95*744Sgs150176 	rge_log_data.who = rgep->ifname;
96*744Sgs150176 	rge_log_data.fmt = "!%s: %s";
97*744Sgs150176 	rge_log_data.level = CE_NOTE;
98*744Sgs150176 
99*744Sgs150176 	va_start(args, fmt);
100*744Sgs150176 	rge_vprt(fmt, args);
101*744Sgs150176 	va_end(args);
102*744Sgs150176 
103*744Sgs150176 	mutex_exit(rge_log_mutex);
104*744Sgs150176 }
105*744Sgs150176 
106*744Sgs150176 /*
107*744Sgs150176  * Log a run-time problem (CE_WARN, log only)
108*744Sgs150176  */
109*744Sgs150176 void
rge_problem(rge_t * rgep,const char * fmt,...)110*744Sgs150176 rge_problem(rge_t *rgep, const char *fmt, ...)
111*744Sgs150176 {
112*744Sgs150176 	va_list args;
113*744Sgs150176 
114*744Sgs150176 	mutex_enter(rge_log_mutex);
115*744Sgs150176 	rge_log_data.who = rgep->ifname;
116*744Sgs150176 	rge_log_data.fmt = "!%s: %s";
117*744Sgs150176 	rge_log_data.level = CE_WARN;
118*744Sgs150176 
119*744Sgs150176 	va_start(args, fmt);
120*744Sgs150176 	rge_vprt(fmt, args);
121*744Sgs150176 	va_end(args);
122*744Sgs150176 
123*744Sgs150176 	mutex_exit(rge_log_mutex);
124*744Sgs150176 }
125*744Sgs150176 
126*744Sgs150176 /*
127*744Sgs150176  * Log a programming error (CE_WARN, log only)
128*744Sgs150176  */
129*744Sgs150176 void
rge_error(rge_t * rgep,const char * fmt,...)130*744Sgs150176 rge_error(rge_t *rgep, const char *fmt, ...)
131*744Sgs150176 {
132*744Sgs150176 	va_list args;
133*744Sgs150176 
134*744Sgs150176 	mutex_enter(rge_log_mutex);
135*744Sgs150176 	rge_log_data.who = rgep->ifname;
136*744Sgs150176 	rge_log_data.fmt = "!%s: %s";
137*744Sgs150176 	rge_log_data.level = CE_WARN;
138*744Sgs150176 
139*744Sgs150176 	va_start(args, fmt);
140*744Sgs150176 	rge_vprt(fmt, args);
141*744Sgs150176 	va_end(args);
142*744Sgs150176 
143*744Sgs150176 	mutex_exit(rge_log_mutex);
144*744Sgs150176 }
145*744Sgs150176 
146*744Sgs150176 #if	RGE_DEBUGGING
147*744Sgs150176 
148*744Sgs150176 static void
rge_prt(const char * fmt,...)149*744Sgs150176 rge_prt(const char *fmt, ...)
150*744Sgs150176 {
151*744Sgs150176 	va_list args;
152*744Sgs150176 
153*744Sgs150176 	ASSERT(mutex_owned(rge_log_mutex));
154*744Sgs150176 
155*744Sgs150176 	va_start(args, fmt);
156*744Sgs150176 	rge_vprt(fmt, args);
157*744Sgs150176 	va_end(args);
158*744Sgs150176 
159*744Sgs150176 	mutex_exit(rge_log_mutex);
160*744Sgs150176 }
161*744Sgs150176 
162*744Sgs150176 void
rge_gdb(void)163*744Sgs150176 (*rge_gdb(void))(const char *fmt, ...)
164*744Sgs150176 {
165*744Sgs150176 	mutex_enter(rge_log_mutex);
166*744Sgs150176 	rge_log_data.who = "rge";
167*744Sgs150176 	rge_log_data.fmt = "?%s: %s\n";
168*744Sgs150176 	rge_log_data.level = CE_CONT;
169*744Sgs150176 
170*744Sgs150176 	return (rge_prt);
171*744Sgs150176 }
172*744Sgs150176 
173*744Sgs150176 void
rge_db(rge_t * rgep)174*744Sgs150176 (*rge_db(rge_t *rgep))(const char *fmt, ...)
175*744Sgs150176 {
176*744Sgs150176 	mutex_enter(rge_log_mutex);
177*744Sgs150176 	rge_log_data.who = rgep->ifname;
178*744Sgs150176 	rge_log_data.fmt = "?%s: %s\n";
179*744Sgs150176 	rge_log_data.level = CE_CONT;
180*744Sgs150176 
181*744Sgs150176 	return (rge_prt);
182*744Sgs150176 }
183*744Sgs150176 
184*744Sgs150176 /*
185*744Sgs150176  * Dump a chunk of memory, 16 bytes at a time
186*744Sgs150176  */
187*744Sgs150176 static void
minidump(rge_t * rgep,const char * caption,void * dp,uint_t len)188*744Sgs150176 minidump(rge_t *rgep, const char *caption, void *dp, uint_t len)
189*744Sgs150176 {
190*744Sgs150176 	uint32_t buf[4];
191*744Sgs150176 	uint32_t nbytes;
192*744Sgs150176 
193*744Sgs150176 	rge_log(rgep, "%d bytes of %s at address %p:-", len, caption, dp);
194*744Sgs150176 
195*744Sgs150176 	for (len = MIN(len, rgep->rxbuf_size); len != 0; len -= nbytes) {
196*744Sgs150176 		nbytes = MIN(len, sizeof (buf));
197*744Sgs150176 		bzero(buf, sizeof (buf));
198*744Sgs150176 		bcopy(dp, buf, nbytes);
199*744Sgs150176 		rge_log(rgep, "%08x %08x %08x %08x",
200*744Sgs150176 			buf[0], buf[1], buf[2], buf[3]);
201*744Sgs150176 		dp = (caddr_t)dp + nbytes;
202*744Sgs150176 	}
203*744Sgs150176 }
204*744Sgs150176 
205*744Sgs150176 void
rge_pkt_dump(rge_t * rgep,rge_bd_t * hrbdp,sw_rbd_t * srbdp,const char * msg)206*744Sgs150176 rge_pkt_dump(rge_t *rgep, rge_bd_t *hrbdp, sw_rbd_t *srbdp, const char *msg)
207*744Sgs150176 {
208*744Sgs150176 	rge_problem(rgep, "driver-detected hardware error: %s", msg);
209*744Sgs150176 
210*744Sgs150176 	minidump(rgep, "hardware descriptor", hrbdp, sizeof (*hrbdp));
211*744Sgs150176 
212*744Sgs150176 	rge_log(rgep, "PCI address %lx flags_len 0x%x"
213*744Sgs150176 			"vlan_tag 0x%x",
214*744Sgs150176 			hrbdp->host_buf_addr,
215*744Sgs150176 			hrbdp->flags_len,
216*744Sgs150176 			hrbdp->vlan_tag);
217*744Sgs150176 
218*744Sgs150176 	if (srbdp != NULL) {
219*744Sgs150176 		minidump(rgep, "software descriptor", srbdp, sizeof (*srbdp));
220*744Sgs150176 
221*744Sgs150176 		rge_log(rgep, "PCI address %llx buffer len 0x%x token 0x%x",
222*744Sgs150176 			srbdp->rx_buf->pbuf.cookie.dmac_laddress,
223*744Sgs150176 			srbdp->rx_buf->pbuf.alength,
224*744Sgs150176 			srbdp->rx_buf->pbuf.token);
225*744Sgs150176 
226*744Sgs150176 		minidump(rgep, "packet data", srbdp->rx_buf->pbuf.mem_va,
227*744Sgs150176 			hrbdp->flags_len & RBD_LEN_MASK);
228*744Sgs150176 	}
229*744Sgs150176 }
230*744Sgs150176 
231*744Sgs150176 void
rge_dbg_enter(rge_t * rgep,const char * s)232*744Sgs150176 rge_dbg_enter(rge_t *rgep, const char *s)
233*744Sgs150176 {
234*744Sgs150176 	uint32_t debug;
235*744Sgs150176 
236*744Sgs150176 	debug = rgep != NULL ? rgep->debug : rge_debug;
237*744Sgs150176 	if (debug & RGE_DBG_STOP) {
238*744Sgs150176 		cmn_err(CE_CONT, "rge_dbg_enter(%p): %s\n", (void *)rgep, s);
239*744Sgs150176 		debug_enter("");
240*744Sgs150176 	}
241*744Sgs150176 }
242*744Sgs150176 
243*744Sgs150176 #endif	/* RGE_DEBUGGING */
244