1 /*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include "dmfe_impl.h"
27
28 /*
29 * ========== Message printing & debug routines ==========
30 */
31
32 static struct {
33 kmutex_t mutex[1];
34 const char *ifname;
35 const char *fmt;
36 int level;
37 } prtdata;
38
39 void
dmfe_log_init()40 dmfe_log_init()
41 {
42 mutex_init(prtdata.mutex, NULL, MUTEX_DRIVER, NULL);
43 }
44
45 void
dmfe_log_fini()46 dmfe_log_fini()
47 {
48 mutex_destroy(prtdata.mutex);
49 }
50
51 /*
52 * Backend print routine for all the routines below
53 */
54 static void
dmfe_vprt(const char * fmt,va_list args)55 dmfe_vprt(const char *fmt, va_list args)
56 {
57 char buf[128];
58
59 ASSERT(mutex_owned(prtdata.mutex));
60
61 (void) vsnprintf(buf, sizeof (buf), fmt, args);
62 cmn_err(prtdata.level, prtdata.fmt, prtdata.ifname, buf);
63 }
64
65 /*
66 * Report a run-time error (CE_WARN, to console & log)
67 * Also logs all the chip's operating registers
68 */
69 void
dmfe_warning(dmfe_t * dmfep,const char * fmt,...)70 dmfe_warning(dmfe_t *dmfep, const char *fmt, ...)
71 {
72 va_list args;
73 uint32_t reg;
74 int i;
75
76 mutex_enter(prtdata.mutex);
77 prtdata.ifname = dmfep->ifname;
78 prtdata.fmt = "%s: %s";
79 prtdata.level = CE_WARN;
80
81 va_start(args, fmt);
82 dmfe_vprt(fmt, args);
83 va_end(args);
84
85 /*
86 * Record all the chip registers in the logfile
87 */
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);
91 }
92
93 mutex_exit(prtdata.mutex);
94 }
95
96 /*
97 * Log a programming error (CE_WARN, log only)
98 */
99 void
dmfe_error(dmfe_t * dmfep,const char * fmt,...)100 dmfe_error(dmfe_t *dmfep, const char *fmt, ...)
101 {
102 va_list args;
103
104 mutex_enter(prtdata.mutex);
105 prtdata.ifname = dmfep->ifname;
106 prtdata.fmt = "!%s: %s";
107 prtdata.level = CE_WARN;
108
109 va_start(args, fmt);
110 dmfe_vprt(fmt, args);
111 va_end(args);
112
113 mutex_exit(prtdata.mutex);
114 }
115
116 /*
117 * Report a run-time event (CE_NOTE, to console & log)
118 */
119 void
dmfe_notice(dmfe_t * dmfep,const char * fmt,...)120 dmfe_notice(dmfe_t *dmfep, const char *fmt, ...)
121 {
122 va_list args;
123
124 mutex_enter(prtdata.mutex);
125 prtdata.ifname = dmfep->ifname;
126 prtdata.fmt = "%s: %s";
127 prtdata.level = CE_NOTE;
128
129 va_start(args, fmt);
130 dmfe_vprt(fmt, args);
131 va_end(args);
132
133 mutex_exit(prtdata.mutex);
134 }
135
136 /*
137 * Log a run-time event (CE_NOTE, log only)
138 */
139 void
dmfe_log(dmfe_t * dmfep,const char * fmt,...)140 dmfe_log(dmfe_t *dmfep, const char *fmt, ...)
141 {
142 va_list args;
143
144 mutex_enter(prtdata.mutex);
145 prtdata.ifname = dmfep->ifname;
146 prtdata.fmt = "!%s: %s";
147 prtdata.level = CE_NOTE;
148
149 va_start(args, fmt);
150 dmfe_vprt(fmt, args);
151 va_end(args);
152
153 mutex_exit(prtdata.mutex);
154 }
155