xref: /onnv-gate/usr/src/uts/common/io/bge/bge_log.c (revision 4403:77da60925cac)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51369Sdduvall  * Common Development and Distribution License (the "License").
61369Sdduvall  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211369Sdduvall 
220Sstevel@tonic-gate /*
23*4403Sgd78059  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
292675Szh199473 #include "bge_impl.h"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * Global variable for default debug flags
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate uint32_t bge_debug;
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * Global mutex used by logging routines below
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate kmutex_t bge_log_mutex[1];
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * Static data used by logging routines; protected by <bge_log_mutex>
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate static struct {
460Sstevel@tonic-gate 	const char *who;
470Sstevel@tonic-gate 	const char *fmt;
480Sstevel@tonic-gate 	int level;
490Sstevel@tonic-gate } bge_log_data;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * Backend print routine for all the routines below
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate static void
bge_vprt(const char * fmt,va_list args)560Sstevel@tonic-gate bge_vprt(const char *fmt, va_list args)
570Sstevel@tonic-gate {
580Sstevel@tonic-gate 	char buf[128];
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	ASSERT(mutex_owned(bge_log_mutex));
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
630Sstevel@tonic-gate 	cmn_err(bge_log_data.level, bge_log_data.fmt, bge_log_data.who, buf);
640Sstevel@tonic-gate }
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * Log a run-time event (CE_NOTE, log only)
680Sstevel@tonic-gate  */
690Sstevel@tonic-gate void
bge_log(bge_t * bgep,const char * fmt,...)700Sstevel@tonic-gate bge_log(bge_t *bgep, const char *fmt, ...)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate 	va_list args;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
750Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
760Sstevel@tonic-gate 	bge_log_data.fmt = "!%s: %s";
770Sstevel@tonic-gate 	bge_log_data.level = CE_NOTE;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	va_start(args, fmt);
800Sstevel@tonic-gate 	bge_vprt(fmt, args);
810Sstevel@tonic-gate 	va_end(args);
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate /*
870Sstevel@tonic-gate  * Log a run-time problem (CE_WARN, log only)
880Sstevel@tonic-gate  */
890Sstevel@tonic-gate void
bge_problem(bge_t * bgep,const char * fmt,...)900Sstevel@tonic-gate bge_problem(bge_t *bgep, const char *fmt, ...)
910Sstevel@tonic-gate {
920Sstevel@tonic-gate 	va_list args;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
950Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
960Sstevel@tonic-gate 	bge_log_data.fmt = "!%s: %s";
970Sstevel@tonic-gate 	bge_log_data.level = CE_WARN;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	va_start(args, fmt);
1000Sstevel@tonic-gate 	bge_vprt(fmt, args);
1010Sstevel@tonic-gate 	va_end(args);
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate /*
1070Sstevel@tonic-gate  * Log a programming error (CE_WARN, log only)
1080Sstevel@tonic-gate  */
1090Sstevel@tonic-gate void
bge_error(bge_t * bgep,const char * fmt,...)1100Sstevel@tonic-gate bge_error(bge_t *bgep, const char *fmt, ...)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate 	va_list args;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
1150Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
1160Sstevel@tonic-gate 	bge_log_data.fmt = "!%s: %s";
1170Sstevel@tonic-gate 	bge_log_data.level = CE_WARN;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	va_start(args, fmt);
1200Sstevel@tonic-gate 	bge_vprt(fmt, args);
1210Sstevel@tonic-gate 	va_end(args);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate 
1261865Sdilpreet void
bge_fm_ereport(bge_t * bgep,char * detail)1271865Sdilpreet bge_fm_ereport(bge_t *bgep, char *detail)
1281865Sdilpreet {
1291865Sdilpreet 	uint64_t ena;
1301865Sdilpreet 	char buf[FM_MAX_CLASS];
1311865Sdilpreet 
1321865Sdilpreet 	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
1331865Sdilpreet 	ena = fm_ena_generate(0, FM_ENA_FMT1);
1341865Sdilpreet 	if (DDI_FM_EREPORT_CAP(bgep->fm_capabilities)) {
1351865Sdilpreet 		ddi_fm_ereport_post(bgep->devinfo, buf, ena, DDI_NOSLEEP,
1361865Sdilpreet 		    FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL);
1371865Sdilpreet 	}
1381865Sdilpreet }
1391865Sdilpreet 
1400Sstevel@tonic-gate #if	BGE_DEBUGGING
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate static void
bge_prt(const char * fmt,...)1430Sstevel@tonic-gate bge_prt(const char *fmt, ...)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate 	va_list args;
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 	ASSERT(mutex_owned(bge_log_mutex));
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	va_start(args, fmt);
1500Sstevel@tonic-gate 	bge_vprt(fmt, args);
1510Sstevel@tonic-gate 	va_end(args);
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate void
bge_gdb(void)1570Sstevel@tonic-gate (*bge_gdb(void))(const char *fmt, ...)
1580Sstevel@tonic-gate {
1590Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
1600Sstevel@tonic-gate 	bge_log_data.who = "bge";
1610Sstevel@tonic-gate 	bge_log_data.fmt = "?%s: %s\n";
1620Sstevel@tonic-gate 	bge_log_data.level = CE_CONT;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	return (bge_prt);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate void
bge_db(bge_t * bgep)1680Sstevel@tonic-gate (*bge_db(bge_t *bgep))(const char *fmt, ...)
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
1710Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
1720Sstevel@tonic-gate 	bge_log_data.fmt = "?%s: %s\n";
1730Sstevel@tonic-gate 	bge_log_data.level = CE_CONT;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	return (bge_prt);
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate  * Dump a chunk of memory, 16 bytes at a time
1800Sstevel@tonic-gate  */
1810Sstevel@tonic-gate static void
minidump(bge_t * bgep,const char * caption,void * dp,uint_t len)1820Sstevel@tonic-gate minidump(bge_t *bgep, const char *caption, void *dp, uint_t len)
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate 	uint32_t buf[4];
1850Sstevel@tonic-gate 	uint32_t nbytes;
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	bge_log(bgep, "%d bytes of %s at address %p:-", len, caption, dp);
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	for (len = MIN(len, BGE_STD_BUFF_SIZE); len != 0; len -= nbytes) {
1900Sstevel@tonic-gate 		nbytes = MIN(len, sizeof (buf));
1910Sstevel@tonic-gate 		bzero(buf, sizeof (buf));
1920Sstevel@tonic-gate 		bcopy(dp, buf, nbytes);
1930Sstevel@tonic-gate 		bge_log(bgep, "%08x %08x %08x %08x",
1940Sstevel@tonic-gate 			buf[0], buf[1], buf[2], buf[3]);
1950Sstevel@tonic-gate 		dp = (caddr_t)dp + nbytes;
1960Sstevel@tonic-gate 	}
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate void
bge_pkt_dump(bge_t * bgep,bge_rbd_t * hrbdp,sw_rbd_t * srbdp,const char * msg)2000Sstevel@tonic-gate bge_pkt_dump(bge_t *bgep, bge_rbd_t *hrbdp, sw_rbd_t *srbdp, const char *msg)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate 	bge_problem(bgep, "driver-detected hardware error: %s", msg);
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	minidump(bgep, "hardware descriptor", hrbdp, sizeof (*hrbdp));
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	bge_log(bgep, "PCI address %llx packet len 0x%x token 0x%x "
2070Sstevel@tonic-gate 			"flags 0x%x index 0x%x",
2080Sstevel@tonic-gate 			hrbdp->host_buf_addr,
2090Sstevel@tonic-gate 			hrbdp->len,
2100Sstevel@tonic-gate 			hrbdp->opaque,
2110Sstevel@tonic-gate 			hrbdp->flags,
2120Sstevel@tonic-gate 			hrbdp->index);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	if (srbdp != NULL) {
2150Sstevel@tonic-gate 		minidump(bgep, "software descriptor", srbdp, sizeof (*srbdp));
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 		bge_log(bgep, "PCI address %llx buffer len 0x%x token 0x%x",
2180Sstevel@tonic-gate 			srbdp->pbuf.cookie.dmac_laddress,
2190Sstevel@tonic-gate 			srbdp->pbuf.alength,
2200Sstevel@tonic-gate 			srbdp->pbuf.token);
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 		minidump(bgep, "packet data", srbdp->pbuf.mem_va, hrbdp->len);
2230Sstevel@tonic-gate 	}
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate void
bge_dbg_enter(bge_t * bgep,const char * s)2270Sstevel@tonic-gate bge_dbg_enter(bge_t *bgep, const char *s)
2280Sstevel@tonic-gate {
2290Sstevel@tonic-gate 	uint32_t debug;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 	debug = bgep != NULL ? bgep->debug : bge_debug;
2320Sstevel@tonic-gate 	if (debug & BGE_DBG_STOP) {
2330Sstevel@tonic-gate 		cmn_err(CE_CONT, "bge_dbg_enter(%p): %s\n", (void *)bgep, s);
2340Sstevel@tonic-gate 		debug_enter("");
2350Sstevel@tonic-gate 	}
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate #endif	/* BGE_DEBUGGING */
239