Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / rge / rge_log.c
blobeb923d628d02e0bf7cea9ad15ed98f5015485a36
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "rge.h"
33 * Global variable for default debug flags
35 uint32_t rge_debug;
38 * Global mutex used by logging routines below
40 kmutex_t rge_log_mutex[1];
43 * Static data used by logging routines; protected by <rge_log_mutex>
45 static struct {
46 const char *who;
47 const char *fmt;
48 int level;
49 } rge_log_data;
53 * Backend print routine for all the routines below
55 static void
56 rge_vprt(const char *fmt, va_list args)
58 char buf[128];
60 ASSERT(mutex_owned(rge_log_mutex));
62 (void) vsnprintf(buf, sizeof (buf), fmt, args);
63 cmn_err(rge_log_data.level, rge_log_data.fmt, rge_log_data.who, buf);
67 * Report a run-time event (CE_NOTE, to console & log)
69 void
70 rge_notice(rge_t *rgep, const char *fmt, ...)
72 va_list args;
74 mutex_enter(rge_log_mutex);
75 rge_log_data.who = rgep->ifname;
76 rge_log_data.fmt = "%s: %s";
77 rge_log_data.level = CE_NOTE;
79 va_start(args, fmt);
80 rge_vprt(fmt, args);
81 va_end(args);
83 mutex_exit(rge_log_mutex);
87 * Log a run-time event (CE_NOTE, log only)
89 void
90 rge_log(rge_t *rgep, const char *fmt, ...)
92 va_list args;
94 mutex_enter(rge_log_mutex);
95 rge_log_data.who = rgep->ifname;
96 rge_log_data.fmt = "!%s: %s";
97 rge_log_data.level = CE_NOTE;
99 va_start(args, fmt);
100 rge_vprt(fmt, args);
101 va_end(args);
103 mutex_exit(rge_log_mutex);
107 * Log a run-time problem (CE_WARN, log only)
109 void
110 rge_problem(rge_t *rgep, const char *fmt, ...)
112 va_list args;
114 mutex_enter(rge_log_mutex);
115 rge_log_data.who = rgep->ifname;
116 rge_log_data.fmt = "!%s: %s";
117 rge_log_data.level = CE_WARN;
119 va_start(args, fmt);
120 rge_vprt(fmt, args);
121 va_end(args);
123 mutex_exit(rge_log_mutex);
127 * Log a programming error (CE_WARN, log only)
129 void
130 rge_error(rge_t *rgep, const char *fmt, ...)
132 va_list args;
134 mutex_enter(rge_log_mutex);
135 rge_log_data.who = rgep->ifname;
136 rge_log_data.fmt = "!%s: %s";
137 rge_log_data.level = CE_WARN;
139 va_start(args, fmt);
140 rge_vprt(fmt, args);
141 va_end(args);
143 mutex_exit(rge_log_mutex);
146 #if RGE_DEBUGGING
148 static void
149 rge_prt(const char *fmt, ...)
151 va_list args;
153 ASSERT(mutex_owned(rge_log_mutex));
155 va_start(args, fmt);
156 rge_vprt(fmt, args);
157 va_end(args);
159 mutex_exit(rge_log_mutex);
162 void
163 (*rge_gdb(void))(const char *fmt, ...)
165 mutex_enter(rge_log_mutex);
166 rge_log_data.who = "rge";
167 rge_log_data.fmt = "?%s: %s\n";
168 rge_log_data.level = CE_CONT;
170 return (rge_prt);
173 void
174 (*rge_db(rge_t *rgep))(const char *fmt, ...)
176 mutex_enter(rge_log_mutex);
177 rge_log_data.who = rgep->ifname;
178 rge_log_data.fmt = "?%s: %s\n";
179 rge_log_data.level = CE_CONT;
181 return (rge_prt);
185 * Dump a chunk of memory, 16 bytes at a time
187 static void
188 minidump(rge_t *rgep, const char *caption, void *dp, uint_t len)
190 uint32_t buf[4];
191 uint32_t nbytes;
193 rge_log(rgep, "%d bytes of %s at address %p:-", len, caption, dp);
195 for (len = MIN(len, rgep->rxbuf_size); len != 0; len -= nbytes) {
196 nbytes = MIN(len, sizeof (buf));
197 bzero(buf, sizeof (buf));
198 bcopy(dp, buf, nbytes);
199 rge_log(rgep, "%08x %08x %08x %08x",
200 buf[0], buf[1], buf[2], buf[3]);
201 dp = (caddr_t)dp + nbytes;
205 void
206 rge_pkt_dump(rge_t *rgep, rge_bd_t *hrbdp, sw_rbd_t *srbdp, const char *msg)
208 rge_problem(rgep, "driver-detected hardware error: %s", msg);
210 minidump(rgep, "hardware descriptor", hrbdp, sizeof (*hrbdp));
212 rge_log(rgep, "PCI address %lx flags_len 0x%x"
213 "vlan_tag 0x%x",
214 hrbdp->host_buf_addr,
215 hrbdp->flags_len,
216 hrbdp->vlan_tag);
218 if (srbdp != NULL) {
219 minidump(rgep, "software descriptor", srbdp, sizeof (*srbdp));
221 rge_log(rgep, "PCI address %llx buffer len 0x%x token 0x%x",
222 srbdp->rx_buf->pbuf.cookie.dmac_laddress,
223 srbdp->rx_buf->pbuf.alength,
224 srbdp->rx_buf->pbuf.token);
226 minidump(rgep, "packet data", srbdp->rx_buf->pbuf.mem_va,
227 hrbdp->flags_len & RBD_LEN_MASK);
231 void
232 rge_dbg_enter(rge_t *rgep, const char *s)
234 uint32_t debug;
236 debug = rgep != NULL ? rgep->debug : rge_debug;
237 if (debug & RGE_DBG_STOP) {
238 cmn_err(CE_CONT, "rge_dbg_enter(%p): %s\n", (void *)rgep, s);
239 debug_enter("");
243 #endif /* RGE_DEBUGGING */