xref: /illumos-gate/usr/src/uts/common/io/bge/bge_log.c (revision 2d6eb4a5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
562387023Sdduvall  * Common Development and Distribution License (the "License").
662387023Sdduvall  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2162387023Sdduvall 
227c478bd9Sstevel@tonic-gate /*
23*0d2a8e5eSgd78059  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27f724721bSzh199473 #include "bge_impl.h"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Global variable for default debug flags
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate uint32_t bge_debug;
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Global mutex used by logging routines below
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate kmutex_t bge_log_mutex[1];
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Static data used by logging routines; protected by <bge_log_mutex>
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate static struct {
447c478bd9Sstevel@tonic-gate 	const char *who;
457c478bd9Sstevel@tonic-gate 	const char *fmt;
467c478bd9Sstevel@tonic-gate 	int level;
477c478bd9Sstevel@tonic-gate } bge_log_data;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Backend print routine for all the routines below
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate static void
bge_vprt(const char * fmt,va_list args)547c478bd9Sstevel@tonic-gate bge_vprt(const char *fmt, va_list args)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate 	char buf[128];
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(bge_log_mutex));
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
617c478bd9Sstevel@tonic-gate 	cmn_err(bge_log_data.level, bge_log_data.fmt, bge_log_data.who, buf);
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Log a run-time event (CE_NOTE, log only)
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate void
bge_log(bge_t * bgep,const char * fmt,...)687c478bd9Sstevel@tonic-gate bge_log(bge_t *bgep, const char *fmt, ...)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	va_list args;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
737c478bd9Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
747c478bd9Sstevel@tonic-gate 	bge_log_data.fmt = "!%s: %s";
757c478bd9Sstevel@tonic-gate 	bge_log_data.level = CE_NOTE;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
787c478bd9Sstevel@tonic-gate 	bge_vprt(fmt, args);
797c478bd9Sstevel@tonic-gate 	va_end(args);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * Log a run-time problem (CE_WARN, log only)
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate void
bge_problem(bge_t * bgep,const char * fmt,...)887c478bd9Sstevel@tonic-gate bge_problem(bge_t *bgep, const char *fmt, ...)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate 	va_list args;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
937c478bd9Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
947c478bd9Sstevel@tonic-gate 	bge_log_data.fmt = "!%s: %s";
957c478bd9Sstevel@tonic-gate 	bge_log_data.level = CE_WARN;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
987c478bd9Sstevel@tonic-gate 	bge_vprt(fmt, args);
997c478bd9Sstevel@tonic-gate 	va_end(args);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * Log a programming error (CE_WARN, log only)
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate void
bge_error(bge_t * bgep,const char * fmt,...)1087c478bd9Sstevel@tonic-gate bge_error(bge_t *bgep, const char *fmt, ...)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate 	va_list args;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
1137c478bd9Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
1147c478bd9Sstevel@tonic-gate 	bge_log_data.fmt = "!%s: %s";
1157c478bd9Sstevel@tonic-gate 	bge_log_data.level = CE_WARN;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
1187c478bd9Sstevel@tonic-gate 	bge_vprt(fmt, args);
1197c478bd9Sstevel@tonic-gate 	va_end(args);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
12400d0963fSdilpreet void
bge_fm_ereport(bge_t * bgep,char * detail)12500d0963fSdilpreet bge_fm_ereport(bge_t *bgep, char *detail)
12600d0963fSdilpreet {
12700d0963fSdilpreet 	uint64_t ena;
12800d0963fSdilpreet 	char buf[FM_MAX_CLASS];
12900d0963fSdilpreet 
13000d0963fSdilpreet 	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
13100d0963fSdilpreet 	ena = fm_ena_generate(0, FM_ENA_FMT1);
13200d0963fSdilpreet 	if (DDI_FM_EREPORT_CAP(bgep->fm_capabilities)) {
13300d0963fSdilpreet 		ddi_fm_ereport_post(bgep->devinfo, buf, ena, DDI_NOSLEEP,
13400d0963fSdilpreet 		    FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL);
13500d0963fSdilpreet 	}
13600d0963fSdilpreet }
13700d0963fSdilpreet 
1387c478bd9Sstevel@tonic-gate #if	BGE_DEBUGGING
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate static void
bge_prt(const char * fmt,...)1417c478bd9Sstevel@tonic-gate bge_prt(const char *fmt, ...)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate 	va_list args;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(bge_log_mutex));
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
1487c478bd9Sstevel@tonic-gate 	bge_vprt(fmt, args);
1497c478bd9Sstevel@tonic-gate 	va_end(args);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	mutex_exit(bge_log_mutex);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate void
bge_gdb(void)1557c478bd9Sstevel@tonic-gate (*bge_gdb(void))(const char *fmt, ...)
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
1587c478bd9Sstevel@tonic-gate 	bge_log_data.who = "bge";
1597c478bd9Sstevel@tonic-gate 	bge_log_data.fmt = "?%s: %s\n";
1607c478bd9Sstevel@tonic-gate 	bge_log_data.level = CE_CONT;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	return (bge_prt);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate void
bge_db(bge_t * bgep)1667c478bd9Sstevel@tonic-gate (*bge_db(bge_t *bgep))(const char *fmt, ...)
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate 	mutex_enter(bge_log_mutex);
1697c478bd9Sstevel@tonic-gate 	bge_log_data.who = bgep->ifname;
1707c478bd9Sstevel@tonic-gate 	bge_log_data.fmt = "?%s: %s\n";
1717c478bd9Sstevel@tonic-gate 	bge_log_data.level = CE_CONT;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	return (bge_prt);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * Dump a chunk of memory, 16 bytes at a time
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate static void
minidump(bge_t * bgep,const char * caption,void * dp,uint_t len)1807c478bd9Sstevel@tonic-gate minidump(bge_t *bgep, const char *caption, void *dp, uint_t len)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate 	uint32_t buf[4];
1837c478bd9Sstevel@tonic-gate 	uint32_t nbytes;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	bge_log(bgep, "%d bytes of %s at address %p:-", len, caption, dp);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	for (len = MIN(len, BGE_STD_BUFF_SIZE); len != 0; len -= nbytes) {
1887c478bd9Sstevel@tonic-gate 		nbytes = MIN(len, sizeof (buf));
1897c478bd9Sstevel@tonic-gate 		bzero(buf, sizeof (buf));
1907c478bd9Sstevel@tonic-gate 		bcopy(dp, buf, nbytes);
1917c478bd9Sstevel@tonic-gate 		bge_log(bgep, "%08x %08x %08x %08x",
1927c478bd9Sstevel@tonic-gate 			buf[0], buf[1], buf[2], buf[3]);
1937c478bd9Sstevel@tonic-gate 		dp = (caddr_t)dp + nbytes;
1947c478bd9Sstevel@tonic-gate 	}
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate void
bge_pkt_dump(bge_t * bgep,bge_rbd_t * hrbdp,sw_rbd_t * srbdp,const char * msg)1987c478bd9Sstevel@tonic-gate bge_pkt_dump(bge_t *bgep, bge_rbd_t *hrbdp, sw_rbd_t *srbdp, const char *msg)
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate 	bge_problem(bgep, "driver-detected hardware error: %s", msg);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	minidump(bgep, "hardware descriptor", hrbdp, sizeof (*hrbdp));
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	bge_log(bgep, "PCI address %llx packet len 0x%x token 0x%x "
2057c478bd9Sstevel@tonic-gate 			"flags 0x%x index 0x%x",
2067c478bd9Sstevel@tonic-gate 			hrbdp->host_buf_addr,
2077c478bd9Sstevel@tonic-gate 			hrbdp->len,
2087c478bd9Sstevel@tonic-gate 			hrbdp->opaque,
2097c478bd9Sstevel@tonic-gate 			hrbdp->flags,
2107c478bd9Sstevel@tonic-gate 			hrbdp->index);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	if (srbdp != NULL) {
2137c478bd9Sstevel@tonic-gate 		minidump(bgep, "software descriptor", srbdp, sizeof (*srbdp));
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 		bge_log(bgep, "PCI address %llx buffer len 0x%x token 0x%x",
2167c478bd9Sstevel@tonic-gate 			srbdp->pbuf.cookie.dmac_laddress,
2177c478bd9Sstevel@tonic-gate 			srbdp->pbuf.alength,
2187c478bd9Sstevel@tonic-gate 			srbdp->pbuf.token);
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 		minidump(bgep, "packet data", srbdp->pbuf.mem_va, hrbdp->len);
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate void
bge_dbg_enter(bge_t * bgep,const char * s)2257c478bd9Sstevel@tonic-gate bge_dbg_enter(bge_t *bgep, const char *s)
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate 	uint32_t debug;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	debug = bgep != NULL ? bgep->debug : bge_debug;
2307c478bd9Sstevel@tonic-gate 	if (debug & BGE_DBG_STOP) {
2317c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "bge_dbg_enter(%p): %s\n", (void *)bgep, s);
2327c478bd9Sstevel@tonic-gate 		debug_enter("");
2337c478bd9Sstevel@tonic-gate 	}
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate #endif	/* BGE_DEBUGGING */
237