xref: /titanic_51/usr/src/uts/common/io/dmfe/dmfe_log.c (revision bdb9230ac765cb7af3fc1f4119caf2c5720dceb3)
15c1d0199Sgd78059 /*
25c1d0199Sgd78059  * CDDL HEADER START
35c1d0199Sgd78059  *
45c1d0199Sgd78059  * The contents of this file are subject to the terms of the
55c1d0199Sgd78059  * Common Development and Distribution License (the "License").
65c1d0199Sgd78059  * You may not use this file except in compliance with the License.
75c1d0199Sgd78059  *
85c1d0199Sgd78059  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c1d0199Sgd78059  * or http://www.opensolaris.org/os/licensing.
105c1d0199Sgd78059  * See the License for the specific language governing permissions
115c1d0199Sgd78059  * and limitations under the License.
125c1d0199Sgd78059  *
135c1d0199Sgd78059  * When distributing Covered Code, include this CDDL HEADER in each
145c1d0199Sgd78059  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c1d0199Sgd78059  * If applicable, add the following below this CDDL HEADER, with the
165c1d0199Sgd78059  * fields enclosed by brackets "[]" replaced with your own identifying
175c1d0199Sgd78059  * information: Portions Copyright [yyyy] [name of copyright owner]
185c1d0199Sgd78059  *
195c1d0199Sgd78059  * CDDL HEADER END
205c1d0199Sgd78059  */
215c1d0199Sgd78059 /*
22*bdb9230aSGarrett D'Amore  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
235c1d0199Sgd78059  * Use is subject to license terms.
245c1d0199Sgd78059  */
255c1d0199Sgd78059 
265c1d0199Sgd78059 #include "dmfe_impl.h"
275c1d0199Sgd78059 
285c1d0199Sgd78059 /*
295c1d0199Sgd78059  *	========== Message printing & debug routines ==========
305c1d0199Sgd78059  */
315c1d0199Sgd78059 
325c1d0199Sgd78059 static struct {
335c1d0199Sgd78059 	kmutex_t mutex[1];
345c1d0199Sgd78059 	const char *ifname;
355c1d0199Sgd78059 	const char *fmt;
365c1d0199Sgd78059 	int level;
375c1d0199Sgd78059 } prtdata;
385c1d0199Sgd78059 
395c1d0199Sgd78059 void
405c1d0199Sgd78059 dmfe_log_init()
415c1d0199Sgd78059 {
425c1d0199Sgd78059 	mutex_init(prtdata.mutex, NULL, MUTEX_DRIVER, NULL);
435c1d0199Sgd78059 }
445c1d0199Sgd78059 
455c1d0199Sgd78059 void
465c1d0199Sgd78059 dmfe_log_fini()
475c1d0199Sgd78059 {
485c1d0199Sgd78059 	mutex_destroy(prtdata.mutex);
495c1d0199Sgd78059 }
505c1d0199Sgd78059 
515c1d0199Sgd78059 /*
525c1d0199Sgd78059  * Backend print routine for all the routines below
535c1d0199Sgd78059  */
545c1d0199Sgd78059 static void
555c1d0199Sgd78059 dmfe_vprt(const char *fmt, va_list args)
565c1d0199Sgd78059 {
575c1d0199Sgd78059 	char buf[128];
585c1d0199Sgd78059 
595c1d0199Sgd78059 	ASSERT(mutex_owned(prtdata.mutex));
605c1d0199Sgd78059 
615c1d0199Sgd78059 	(void) vsnprintf(buf, sizeof (buf), fmt, args);
625c1d0199Sgd78059 	cmn_err(prtdata.level, prtdata.fmt, prtdata.ifname, buf);
635c1d0199Sgd78059 }
645c1d0199Sgd78059 
655c1d0199Sgd78059 /*
665c1d0199Sgd78059  * Report a run-time error (CE_WARN, to console & log)
675c1d0199Sgd78059  * Also logs all the chip's operating registers
685c1d0199Sgd78059  */
695c1d0199Sgd78059 void
705c1d0199Sgd78059 dmfe_warning(dmfe_t *dmfep, const char *fmt, ...)
715c1d0199Sgd78059 {
725c1d0199Sgd78059 	va_list args;
735c1d0199Sgd78059 	uint32_t reg;
745c1d0199Sgd78059 	int i;
755c1d0199Sgd78059 
765c1d0199Sgd78059 	mutex_enter(prtdata.mutex);
775c1d0199Sgd78059 	prtdata.ifname = dmfep->ifname;
785c1d0199Sgd78059 	prtdata.fmt = "%s: %s";
795c1d0199Sgd78059 	prtdata.level = CE_WARN;
805c1d0199Sgd78059 
815c1d0199Sgd78059 	va_start(args, fmt);
825c1d0199Sgd78059 	dmfe_vprt(fmt, args);
835c1d0199Sgd78059 	va_end(args);
845c1d0199Sgd78059 
855c1d0199Sgd78059 	/*
865c1d0199Sgd78059 	 * Record all the chip registers in the logfile
875c1d0199Sgd78059 	 */
885c1d0199Sgd78059 	for (i = 0; i < 16; ++i) {
895c1d0199Sgd78059 		reg = dmfe_chip_get32(dmfep, 8*i);
905c1d0199Sgd78059 		cmn_err(CE_NOTE, "!%s: CR%d\t%08x", dmfep->ifname, i, reg);
915c1d0199Sgd78059 	}
925c1d0199Sgd78059 
935c1d0199Sgd78059 	mutex_exit(prtdata.mutex);
945c1d0199Sgd78059 }
955c1d0199Sgd78059 
965c1d0199Sgd78059 /*
975c1d0199Sgd78059  * Log a programming error (CE_WARN, log only)
985c1d0199Sgd78059  */
995c1d0199Sgd78059 void
1005c1d0199Sgd78059 dmfe_error(dmfe_t *dmfep, const char *fmt, ...)
1015c1d0199Sgd78059 {
1025c1d0199Sgd78059 	va_list args;
1035c1d0199Sgd78059 
1045c1d0199Sgd78059 	mutex_enter(prtdata.mutex);
1055c1d0199Sgd78059 	prtdata.ifname = dmfep->ifname;
1065c1d0199Sgd78059 	prtdata.fmt = "!%s: %s";
1075c1d0199Sgd78059 	prtdata.level = CE_WARN;
1085c1d0199Sgd78059 
1095c1d0199Sgd78059 	va_start(args, fmt);
1105c1d0199Sgd78059 	dmfe_vprt(fmt, args);
1115c1d0199Sgd78059 	va_end(args);
1125c1d0199Sgd78059 
1135c1d0199Sgd78059 	mutex_exit(prtdata.mutex);
1145c1d0199Sgd78059 }
1155c1d0199Sgd78059 
1165c1d0199Sgd78059 /*
1175c1d0199Sgd78059  * Report a run-time event (CE_NOTE, to console & log)
1185c1d0199Sgd78059  */
1195c1d0199Sgd78059 void
1205c1d0199Sgd78059 dmfe_notice(dmfe_t *dmfep, const char *fmt, ...)
1215c1d0199Sgd78059 {
1225c1d0199Sgd78059 	va_list args;
1235c1d0199Sgd78059 
1245c1d0199Sgd78059 	mutex_enter(prtdata.mutex);
1255c1d0199Sgd78059 	prtdata.ifname = dmfep->ifname;
1265c1d0199Sgd78059 	prtdata.fmt = "%s: %s";
1275c1d0199Sgd78059 	prtdata.level = CE_NOTE;
1285c1d0199Sgd78059 
1295c1d0199Sgd78059 	va_start(args, fmt);
1305c1d0199Sgd78059 	dmfe_vprt(fmt, args);
1315c1d0199Sgd78059 	va_end(args);
1325c1d0199Sgd78059 
1335c1d0199Sgd78059 	mutex_exit(prtdata.mutex);
1345c1d0199Sgd78059 }
1355c1d0199Sgd78059 
1365c1d0199Sgd78059 /*
1375c1d0199Sgd78059  * Log a run-time event (CE_NOTE, log only)
1385c1d0199Sgd78059  */
1395c1d0199Sgd78059 void
1405c1d0199Sgd78059 dmfe_log(dmfe_t *dmfep, const char *fmt, ...)
1415c1d0199Sgd78059 {
1425c1d0199Sgd78059 	va_list args;
1435c1d0199Sgd78059 
1445c1d0199Sgd78059 	mutex_enter(prtdata.mutex);
1455c1d0199Sgd78059 	prtdata.ifname = dmfep->ifname;
1465c1d0199Sgd78059 	prtdata.fmt = "!%s: %s";
1475c1d0199Sgd78059 	prtdata.level = CE_NOTE;
1485c1d0199Sgd78059 
1495c1d0199Sgd78059 	va_start(args, fmt);
1505c1d0199Sgd78059 	dmfe_vprt(fmt, args);
1515c1d0199Sgd78059 	va_end(args);
1525c1d0199Sgd78059 
1535c1d0199Sgd78059 	mutex_exit(prtdata.mutex);
1545c1d0199Sgd78059 }
155