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]
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <sys/types.h>
28 #include <sys/cmn_err.h>
31 #include <sys/sunddi.h>
32 #include <sys/ksynch.h>
33 #include <sys/varargs.h>
35 #include <sys/ib/clients/eoib/eib_impl.h>
40 uint_t eib_log_size
= EIB_LOGSZ_DEFAULT
;
41 int eib_log_level
= EIB_MSGS_DEFAULT
| EIB_MSGS_DEBUG
;
42 int eib_log_timestamps
= 0;
45 * Debug variables, should not be tunables so allocated debug buffer
46 * and its size remain consistent.
48 static kmutex_t eib_debug_buf_lock
;
49 static uint8_t *eib_debug_buf
;
50 static uint32_t eib_debug_buf_ndx
;
51 static uint_t eib_debug_buf_sz
= 0;
56 static void eib_log(char *);
61 eib_debug_buf_ndx
= 0;
62 eib_debug_buf_sz
= eib_log_size
;
63 eib_debug_buf
= kmem_zalloc(eib_debug_buf_sz
, KM_SLEEP
);
65 mutex_init(&eib_debug_buf_lock
, NULL
, MUTEX_DRIVER
, NULL
);
71 mutex_destroy(&eib_debug_buf_lock
);
73 if (eib_debug_buf
&& eib_debug_buf_sz
) {
74 kmem_free(eib_debug_buf
, eib_debug_buf_sz
);
78 eib_debug_buf_ndx
= 0;
86 char msgbuf
[EIB_MAX_LINE
];
88 if (eib_debug_buf
== NULL
)
91 if (eib_log_timestamps
) {
92 msglen
= snprintf(msgbuf
, EIB_MAX_LINE
, "%llx: %s",
93 (unsigned long long)ddi_get_lbolt64(), msg
);
95 msglen
= snprintf(msgbuf
, EIB_MAX_LINE
, "%s", msg
);
100 else if (msglen
>= EIB_MAX_LINE
)
101 msglen
= EIB_MAX_LINE
- 1;
103 mutex_enter(&eib_debug_buf_lock
);
104 if ((eib_debug_buf_ndx
== 0) ||
105 (eib_debug_buf
[eib_debug_buf_ndx
-1] != '\n')) {
106 eib_debug_buf
[eib_debug_buf_ndx
] = '\n';
110 off
= eib_debug_buf_ndx
; /* current msg should go here */
112 eib_debug_buf_ndx
+= msglen
; /* next msg should start here */
113 eib_debug_buf
[eib_debug_buf_ndx
] = 0; /* terminate current msg */
115 if (eib_debug_buf_ndx
>= (eib_debug_buf_sz
- 2 * EIB_MAX_LINE
))
116 eib_debug_buf_ndx
= 0;
118 mutex_exit(&eib_debug_buf_lock
);
120 bcopy(msgbuf
, eib_debug_buf
+off
, msglen
); /* no lock needed */
125 eib_dprintf_verbose(int inst
, const char *fmt
, ...)
129 char msgbuf
[EIB_MAX_LINE
];
130 char newfmt
[EIB_MAX_LINE
];
132 if ((eib_log_level
& EIB_MSGS_VERBOSE
) != EIB_MSGS_VERBOSE
)
135 (void) snprintf(newfmt
, EIB_MAX_LINE
, "eoib%d__%s", inst
, fmt
);
138 msglen
= vsnprintf(msgbuf
, EIB_MAX_LINE
, newfmt
, ap
);
147 eib_dprintf_pkt(int inst
, uint8_t *pkt
, uint_t sz
)
149 char msgbuf
[EIB_MAX_LINE
];
155 if ((eib_log_level
& EIB_MSGS_PKT
) != EIB_MSGS_PKT
)
159 (void) snprintf(msgbuf
, EIB_MAX_LINE
,
160 "eoib%02d__%02x %02x %02x %02x %02x %02x %02x %02x "
161 "%02x %02x %02x %02x %02x %02x %02x %02x\n", inst
,
162 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6], p
[7],
163 p
[8], p
[9], p
[10], p
[11], p
[12], p
[13], p
[14], p
[15]);
173 for (i
= 0; i
< sz
; i
++) {
175 (void) snprintf(bufp
, len
, "eoib%02d__%02x ",
179 } else if (i
< (sz
- 1)) {
180 (void) snprintf(bufp
, len
, "%02x ", p
[i
]);
184 (void) snprintf(bufp
, len
, "%02x\n", p
[i
]);
194 eib_dprintf_args(int inst
, const char *fmt
, ...)
198 char msgbuf
[EIB_MAX_LINE
];
199 char newfmt
[EIB_MAX_LINE
];
201 if ((eib_log_level
& EIB_MSGS_ARGS
) != EIB_MSGS_ARGS
)
204 (void) snprintf(newfmt
, EIB_MAX_LINE
, "eoib%d__%s", inst
, fmt
);
207 msglen
= vsnprintf(msgbuf
, EIB_MAX_LINE
, newfmt
, ap
);
216 eib_dprintf_debug(int inst
, const char *fmt
, ...)
220 char msgbuf
[EIB_MAX_LINE
];
221 char newfmt
[EIB_MAX_LINE
];
223 if ((eib_log_level
& EIB_MSGS_DEBUG
) != EIB_MSGS_DEBUG
)
226 (void) snprintf(newfmt
, EIB_MAX_LINE
, "eoib%d__%s", inst
, fmt
);
229 msglen
= vsnprintf(msgbuf
, EIB_MAX_LINE
, newfmt
, ap
);
239 eib_dprintf_warn(int inst
, const char *fmt
, ...)
243 char msgbuf
[EIB_MAX_LINE
];
244 char newfmt
[EIB_MAX_LINE
];
246 if ((eib_log_level
& EIB_MSGS_WARN
) != EIB_MSGS_WARN
)
249 (void) snprintf(newfmt
, EIB_MAX_LINE
, "eoib%d__%s", inst
, fmt
);
252 msglen
= vsnprintf(msgbuf
, EIB_MAX_LINE
, newfmt
, ap
);
261 eib_dprintf_err(int inst
, const char *fmt
, ...)
265 char msgbuf
[EIB_MAX_LINE
];
266 char newfmt
[EIB_MAX_LINE
];
268 if ((eib_log_level
& EIB_MSGS_ERR
) != EIB_MSGS_ERR
)
271 (void) snprintf(newfmt
, EIB_MAX_LINE
, "eoib%d__%s", inst
, fmt
);
274 msglen
= vsnprintf(msgbuf
, EIB_MAX_LINE
, newfmt
, ap
);
279 cmn_err(CE_WARN
, "!%s\n", msgbuf
);
284 eib_dprintf_crit(int inst
, const char *fmt
, ...)
288 char msgbuf
[EIB_MAX_LINE
];
289 char newfmt
[EIB_MAX_LINE
];
291 if ((eib_log_level
& EIB_MSGS_CRIT
) != EIB_MSGS_CRIT
)
294 (void) snprintf(newfmt
, EIB_MAX_LINE
, "eoib%d__%s", inst
, fmt
);
297 msglen
= vsnprintf(msgbuf
, EIB_MAX_LINE
, newfmt
, ap
);
302 cmn_err(CE_PANIC
, "!%s\n", msgbuf
);