Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / dmfe / dmfe_log.c
blob4cf9e1be08616d374d7c47f05366db8742b5ceb1
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include "dmfe_impl.h"
29 * ========== Message printing & debug routines ==========
32 static struct {
33 kmutex_t mutex[1];
34 const char *ifname;
35 const char *fmt;
36 int level;
37 } prtdata;
39 void
40 dmfe_log_init()
42 mutex_init(prtdata.mutex, NULL, MUTEX_DRIVER, NULL);
45 void
46 dmfe_log_fini()
48 mutex_destroy(prtdata.mutex);
52 * Backend print routine for all the routines below
54 static void
55 dmfe_vprt(const char *fmt, va_list args)
57 char buf[128];
59 ASSERT(mutex_owned(prtdata.mutex));
61 (void) vsnprintf(buf, sizeof (buf), fmt, args);
62 cmn_err(prtdata.level, prtdata.fmt, prtdata.ifname, buf);
66 * Report a run-time error (CE_WARN, to console & log)
67 * Also logs all the chip's operating registers
69 void
70 dmfe_warning(dmfe_t *dmfep, const char *fmt, ...)
72 va_list args;
73 uint32_t reg;
74 int i;
76 mutex_enter(prtdata.mutex);
77 prtdata.ifname = dmfep->ifname;
78 prtdata.fmt = "%s: %s";
79 prtdata.level = CE_WARN;
81 va_start(args, fmt);
82 dmfe_vprt(fmt, args);
83 va_end(args);
86 * Record all the chip registers in the logfile
88 for (i = 0; i < 16; ++i) {
89 reg = dmfe_chip_get32(dmfep, 8*i);
90 cmn_err(CE_NOTE, "!%s: CR%d\t%08x", dmfep->ifname, i, reg);
93 mutex_exit(prtdata.mutex);
97 * Log a programming error (CE_WARN, log only)
99 void
100 dmfe_error(dmfe_t *dmfep, const char *fmt, ...)
102 va_list args;
104 mutex_enter(prtdata.mutex);
105 prtdata.ifname = dmfep->ifname;
106 prtdata.fmt = "!%s: %s";
107 prtdata.level = CE_WARN;
109 va_start(args, fmt);
110 dmfe_vprt(fmt, args);
111 va_end(args);
113 mutex_exit(prtdata.mutex);
117 * Report a run-time event (CE_NOTE, to console & log)
119 void
120 dmfe_notice(dmfe_t *dmfep, const char *fmt, ...)
122 va_list args;
124 mutex_enter(prtdata.mutex);
125 prtdata.ifname = dmfep->ifname;
126 prtdata.fmt = "%s: %s";
127 prtdata.level = CE_NOTE;
129 va_start(args, fmt);
130 dmfe_vprt(fmt, args);
131 va_end(args);
133 mutex_exit(prtdata.mutex);
137 * Log a run-time event (CE_NOTE, log only)
139 void
140 dmfe_log(dmfe_t *dmfep, const char *fmt, ...)
142 va_list args;
144 mutex_enter(prtdata.mutex);
145 prtdata.ifname = dmfep->ifname;
146 prtdata.fmt = "!%s: %s";
147 prtdata.level = CE_NOTE;
149 va_start(args, fmt);
150 dmfe_vprt(fmt, args);
151 va_end(args);
153 mutex_exit(prtdata.mutex);