xref: /illumos-gate/usr/src/uts/common/io/dmfe/dmfe_log.c (revision bdb9230a)
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
55c1d0199Sgd  * Common Development and Distribution License (the "License").
65c1d0199Sgd  * 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  */
217c478bd9Sstevel@tonic-gate /*
22*bdb9230aSGarrett D'Amore  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
265c1d0199Sgd #include "dmfe_impl.h"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  *	========== Message printing & debug routines ==========
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate static struct {
337c478bd9Sstevel@tonic-gate 	kmutex_t mutex[1];
347c478bd9Sstevel@tonic-gate 	const char *ifname;
357c478bd9Sstevel@tonic-gate 	const char *fmt;
367c478bd9Sstevel@tonic-gate 	int level;
377c478bd9Sstevel@tonic-gate } prtdata;
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate void
dmfe_log_init()407c478bd9Sstevel@tonic-gate dmfe_log_init()
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate 	mutex_init(prtdata.mutex, NULL, MUTEX_DRIVER, NULL);
437c478bd9Sstevel@tonic-gate }
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate void
dmfe_log_fini()467c478bd9Sstevel@tonic-gate dmfe_log_fini()
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate 	mutex_destroy(prtdata.mutex);
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Backend print routine for all the routines below
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate static void
dmfe_vprt(const char * fmt,va_list args)557c478bd9Sstevel@tonic-gate dmfe_vprt(const char *fmt, va_list args)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate 	char buf[128];
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(prtdata.mutex));
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
627c478bd9Sstevel@tonic-gate 	cmn_err(prtdata.level, prtdata.fmt, prtdata.ifname, buf);
637c478bd9Sstevel@tonic-gate }
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Report a run-time error (CE_WARN, to console & log)
677c478bd9Sstevel@tonic-gate  * Also logs all the chip's operating registers
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate void
dmfe_warning(dmfe_t * dmfep,const char * fmt,...)707c478bd9Sstevel@tonic-gate dmfe_warning(dmfe_t *dmfep, const char *fmt, ...)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate 	va_list args;
737c478bd9Sstevel@tonic-gate 	uint32_t reg;
747c478bd9Sstevel@tonic-gate 	int i;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	mutex_enter(prtdata.mutex);
777c478bd9Sstevel@tonic-gate 	prtdata.ifname = dmfep->ifname;
787c478bd9Sstevel@tonic-gate 	prtdata.fmt = "%s: %s";
797c478bd9Sstevel@tonic-gate 	prtdata.level = CE_WARN;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
827c478bd9Sstevel@tonic-gate 	dmfe_vprt(fmt, args);
837c478bd9Sstevel@tonic-gate 	va_end(args);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	/*
867c478bd9Sstevel@tonic-gate 	 * Record all the chip registers in the logfile
877c478bd9Sstevel@tonic-gate 	 */
887c478bd9Sstevel@tonic-gate 	for (i = 0; i < 16; ++i) {
897c478bd9Sstevel@tonic-gate 		reg = dmfe_chip_get32(dmfep, 8*i);
907c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!%s: CR%d\t%08x", dmfep->ifname, i, reg);
917c478bd9Sstevel@tonic-gate 	}
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	mutex_exit(prtdata.mutex);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Log a programming error (CE_WARN, log only)
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate void
dmfe_error(dmfe_t * dmfep,const char * fmt,...)1007c478bd9Sstevel@tonic-gate dmfe_error(dmfe_t *dmfep, const char *fmt, ...)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate 	va_list args;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	mutex_enter(prtdata.mutex);
1057c478bd9Sstevel@tonic-gate 	prtdata.ifname = dmfep->ifname;
1067c478bd9Sstevel@tonic-gate 	prtdata.fmt = "!%s: %s";
1077c478bd9Sstevel@tonic-gate 	prtdata.level = CE_WARN;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
1107c478bd9Sstevel@tonic-gate 	dmfe_vprt(fmt, args);
1117c478bd9Sstevel@tonic-gate 	va_end(args);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	mutex_exit(prtdata.mutex);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Report a run-time event (CE_NOTE, to console & log)
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate void
dmfe_notice(dmfe_t * dmfep,const char * fmt,...)1207c478bd9Sstevel@tonic-gate dmfe_notice(dmfe_t *dmfep, const char *fmt, ...)
1217c478bd9Sstevel@tonic-gate {
1227c478bd9Sstevel@tonic-gate 	va_list args;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	mutex_enter(prtdata.mutex);
1257c478bd9Sstevel@tonic-gate 	prtdata.ifname = dmfep->ifname;
1267c478bd9Sstevel@tonic-gate 	prtdata.fmt = "%s: %s";
1277c478bd9Sstevel@tonic-gate 	prtdata.level = CE_NOTE;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
1307c478bd9Sstevel@tonic-gate 	dmfe_vprt(fmt, args);
1317c478bd9Sstevel@tonic-gate 	va_end(args);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	mutex_exit(prtdata.mutex);
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Log a run-time event (CE_NOTE, log only)
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate void
dmfe_log(dmfe_t * dmfep,const char * fmt,...)1407c478bd9Sstevel@tonic-gate dmfe_log(dmfe_t *dmfep, const char *fmt, ...)
1417c478bd9Sstevel@tonic-gate {
1427c478bd9Sstevel@tonic-gate 	va_list args;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	mutex_enter(prtdata.mutex);
1457c478bd9Sstevel@tonic-gate 	prtdata.ifname = dmfep->ifname;
1467c478bd9Sstevel@tonic-gate 	prtdata.fmt = "!%s: %s";
1477c478bd9Sstevel@tonic-gate 	prtdata.level = CE_NOTE;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
1507c478bd9Sstevel@tonic-gate 	dmfe_vprt(fmt, args);
1517c478bd9Sstevel@tonic-gate 	va_end(args);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	mutex_exit(prtdata.mutex);
1547c478bd9Sstevel@tonic-gate }
155