15181Sgd78059 /*
25181Sgd78059 * CDDL HEADER START
35181Sgd78059 *
45181Sgd78059 * The contents of this file are subject to the terms of the
55181Sgd78059 * Common Development and Distribution License (the "License").
65181Sgd78059 * You may not use this file except in compliance with the License.
75181Sgd78059 *
85181Sgd78059 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95181Sgd78059 * or http://www.opensolaris.org/os/licensing.
105181Sgd78059 * See the License for the specific language governing permissions
115181Sgd78059 * and limitations under the License.
125181Sgd78059 *
135181Sgd78059 * When distributing Covered Code, include this CDDL HEADER in each
145181Sgd78059 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155181Sgd78059 * If applicable, add the following below this CDDL HEADER, with the
165181Sgd78059 * fields enclosed by brackets "[]" replaced with your own identifying
175181Sgd78059 * information: Portions Copyright [yyyy] [name of copyright owner]
185181Sgd78059 *
195181Sgd78059 * CDDL HEADER END
205181Sgd78059 */
215181Sgd78059 /*
22*9860Sgdamore@opensolaris.org * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
235181Sgd78059 * Use is subject to license terms.
245181Sgd78059 */
255181Sgd78059
265181Sgd78059 #include "dmfe_impl.h"
275181Sgd78059
285181Sgd78059 /*
295181Sgd78059 * ========== Message printing & debug routines ==========
305181Sgd78059 */
315181Sgd78059
325181Sgd78059 static struct {
335181Sgd78059 kmutex_t mutex[1];
345181Sgd78059 const char *ifname;
355181Sgd78059 const char *fmt;
365181Sgd78059 int level;
375181Sgd78059 } prtdata;
385181Sgd78059
395181Sgd78059 void
dmfe_log_init()405181Sgd78059 dmfe_log_init()
415181Sgd78059 {
425181Sgd78059 mutex_init(prtdata.mutex, NULL, MUTEX_DRIVER, NULL);
435181Sgd78059 }
445181Sgd78059
455181Sgd78059 void
dmfe_log_fini()465181Sgd78059 dmfe_log_fini()
475181Sgd78059 {
485181Sgd78059 mutex_destroy(prtdata.mutex);
495181Sgd78059 }
505181Sgd78059
515181Sgd78059 /*
525181Sgd78059 * Backend print routine for all the routines below
535181Sgd78059 */
545181Sgd78059 static void
dmfe_vprt(const char * fmt,va_list args)555181Sgd78059 dmfe_vprt(const char *fmt, va_list args)
565181Sgd78059 {
575181Sgd78059 char buf[128];
585181Sgd78059
595181Sgd78059 ASSERT(mutex_owned(prtdata.mutex));
605181Sgd78059
615181Sgd78059 (void) vsnprintf(buf, sizeof (buf), fmt, args);
625181Sgd78059 cmn_err(prtdata.level, prtdata.fmt, prtdata.ifname, buf);
635181Sgd78059 }
645181Sgd78059
655181Sgd78059 /*
665181Sgd78059 * Report a run-time error (CE_WARN, to console & log)
675181Sgd78059 * Also logs all the chip's operating registers
685181Sgd78059 */
695181Sgd78059 void
dmfe_warning(dmfe_t * dmfep,const char * fmt,...)705181Sgd78059 dmfe_warning(dmfe_t *dmfep, const char *fmt, ...)
715181Sgd78059 {
725181Sgd78059 va_list args;
735181Sgd78059 uint32_t reg;
745181Sgd78059 int i;
755181Sgd78059
765181Sgd78059 mutex_enter(prtdata.mutex);
775181Sgd78059 prtdata.ifname = dmfep->ifname;
785181Sgd78059 prtdata.fmt = "%s: %s";
795181Sgd78059 prtdata.level = CE_WARN;
805181Sgd78059
815181Sgd78059 va_start(args, fmt);
825181Sgd78059 dmfe_vprt(fmt, args);
835181Sgd78059 va_end(args);
845181Sgd78059
855181Sgd78059 /*
865181Sgd78059 * Record all the chip registers in the logfile
875181Sgd78059 */
885181Sgd78059 for (i = 0; i < 16; ++i) {
895181Sgd78059 reg = dmfe_chip_get32(dmfep, 8*i);
905181Sgd78059 cmn_err(CE_NOTE, "!%s: CR%d\t%08x", dmfep->ifname, i, reg);
915181Sgd78059 }
925181Sgd78059
935181Sgd78059 mutex_exit(prtdata.mutex);
945181Sgd78059 }
955181Sgd78059
965181Sgd78059 /*
975181Sgd78059 * Log a programming error (CE_WARN, log only)
985181Sgd78059 */
995181Sgd78059 void
dmfe_error(dmfe_t * dmfep,const char * fmt,...)1005181Sgd78059 dmfe_error(dmfe_t *dmfep, const char *fmt, ...)
1015181Sgd78059 {
1025181Sgd78059 va_list args;
1035181Sgd78059
1045181Sgd78059 mutex_enter(prtdata.mutex);
1055181Sgd78059 prtdata.ifname = dmfep->ifname;
1065181Sgd78059 prtdata.fmt = "!%s: %s";
1075181Sgd78059 prtdata.level = CE_WARN;
1085181Sgd78059
1095181Sgd78059 va_start(args, fmt);
1105181Sgd78059 dmfe_vprt(fmt, args);
1115181Sgd78059 va_end(args);
1125181Sgd78059
1135181Sgd78059 mutex_exit(prtdata.mutex);
1145181Sgd78059 }
1155181Sgd78059
1165181Sgd78059 /*
1175181Sgd78059 * Report a run-time event (CE_NOTE, to console & log)
1185181Sgd78059 */
1195181Sgd78059 void
dmfe_notice(dmfe_t * dmfep,const char * fmt,...)1205181Sgd78059 dmfe_notice(dmfe_t *dmfep, const char *fmt, ...)
1215181Sgd78059 {
1225181Sgd78059 va_list args;
1235181Sgd78059
1245181Sgd78059 mutex_enter(prtdata.mutex);
1255181Sgd78059 prtdata.ifname = dmfep->ifname;
1265181Sgd78059 prtdata.fmt = "%s: %s";
1275181Sgd78059 prtdata.level = CE_NOTE;
1285181Sgd78059
1295181Sgd78059 va_start(args, fmt);
1305181Sgd78059 dmfe_vprt(fmt, args);
1315181Sgd78059 va_end(args);
1325181Sgd78059
1335181Sgd78059 mutex_exit(prtdata.mutex);
1345181Sgd78059 }
1355181Sgd78059
1365181Sgd78059 /*
1375181Sgd78059 * Log a run-time event (CE_NOTE, log only)
1385181Sgd78059 */
1395181Sgd78059 void
dmfe_log(dmfe_t * dmfep,const char * fmt,...)1405181Sgd78059 dmfe_log(dmfe_t *dmfep, const char *fmt, ...)
1415181Sgd78059 {
1425181Sgd78059 va_list args;
1435181Sgd78059
1445181Sgd78059 mutex_enter(prtdata.mutex);
1455181Sgd78059 prtdata.ifname = dmfep->ifname;
1465181Sgd78059 prtdata.fmt = "!%s: %s";
1475181Sgd78059 prtdata.level = CE_NOTE;
1485181Sgd78059
1495181Sgd78059 va_start(args, fmt);
1505181Sgd78059 dmfe_vprt(fmt, args);
1515181Sgd78059 va_end(args);
1525181Sgd78059
1535181Sgd78059 mutex_exit(prtdata.mutex);
1545181Sgd78059 }
155