10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*8659SBill.Taylor@Sun.COM * Common Development and Distribution License (the "License").
6*8659SBill.Taylor@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*8659SBill.Taylor@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate * ibtf_util.c
280Sstevel@tonic-gate *
290Sstevel@tonic-gate * This file contains the IBTF module's helper/utility functions.
300Sstevel@tonic-gate * - IBTF logging support
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate static char ibtf_util[] = "ibtl_util";
360Sstevel@tonic-gate
370Sstevel@tonic-gate /* Function Prototypes */
380Sstevel@tonic-gate static void ibtf_clear_print_buf();
390Sstevel@tonic-gate
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate * Print Buffer protected by mutex for debug stuff. The mutex also
420Sstevel@tonic-gate * ensures serializing debug messages.
430Sstevel@tonic-gate */
440Sstevel@tonic-gate static kmutex_t ibtf_print_mutex;
450Sstevel@tonic-gate static char ibtf_print_buf[IBTL_PRINT_BUF_LEN];
460Sstevel@tonic-gate
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate * Debug Stuff.
490Sstevel@tonic-gate */
500Sstevel@tonic-gate uint_t ibtf_errlevel = IBTF_LOG_L5;
510Sstevel@tonic-gate uint_t ibgen_errlevel = IBTF_LOG_L2;
520Sstevel@tonic-gate uint_t ibtl_errlevel = IBTF_LOG_L2;
530Sstevel@tonic-gate uint_t ibcm_errlevel = IBTF_LOG_L2;
540Sstevel@tonic-gate uint_t ibdm_errlevel = IBTF_LOG_L2;
550Sstevel@tonic-gate uint_t ibnex_errlevel = IBTF_LOG_L2;
560Sstevel@tonic-gate
570Sstevel@tonic-gate #define IBTF_DEBUG_SIZE_EXTRA_ALLOC 8
580Sstevel@tonic-gate #define IBTF_MIN_DEBUG_BUF_SIZE 0x1000
590Sstevel@tonic-gate #ifdef DEBUG
600Sstevel@tonic-gate #define IBTF_DEBUG_BUF_SIZE 0x10000
610Sstevel@tonic-gate #else
620Sstevel@tonic-gate #define IBTF_DEBUG_BUF_SIZE 0x2000
630Sstevel@tonic-gate #endif /* DEBUG */
640Sstevel@tonic-gate
650Sstevel@tonic-gate int ibtf_suppress_dprintf; /* Suppress debug printing */
660Sstevel@tonic-gate int ibtf_buffer_dprintf = 1; /* Use a debug print buffer */
670Sstevel@tonic-gate int ibtf_debug_buf_size = IBTF_DEBUG_BUF_SIZE; /* Sz of Debug buf */
680Sstevel@tonic-gate int ibtf_allow_intr_msgs = 0; /* log "intr" messages */
690Sstevel@tonic-gate char *ibtf_debug_buf = NULL; /* The Debug Buf */
700Sstevel@tonic-gate char *ibtf_buf_sptr, *ibtf_buf_eptr; /* debug buffer temp pointer */
710Sstevel@tonic-gate int ibtf_clear_debug_buf_flag = 0; /* Clear debug buffer */
720Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("inconsistency OK", ibtf_debug_buf_size))
730Sstevel@tonic-gate
740Sstevel@tonic-gate longlong_t ibtl_ib2usec_tbl[64]; /* time conversion table */
750Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("inconsistency OK", ibtl_ib2usec_tbl))
760Sstevel@tonic-gate
_NOTE(MUTEX_PROTECTS_DATA (ibtf_print_mutex,ibtf_buf_sptr ibtf_buf_eptr))770Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibtf_print_mutex, ibtf_buf_sptr ibtf_buf_eptr))
780Sstevel@tonic-gate
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate * Function:
810Sstevel@tonic-gate * ibtl_ib2usec_init
820Sstevel@tonic-gate * Input:
830Sstevel@tonic-gate * none
840Sstevel@tonic-gate * Output:
850Sstevel@tonic-gate * none
860Sstevel@tonic-gate * Returns:
870Sstevel@tonic-gate * none
880Sstevel@tonic-gate * Description:
890Sstevel@tonic-gate * Initialize ibtl_ib2usec_tbl[64] for use by ibt_usec2ib and ibt_ib2usec.
900Sstevel@tonic-gate */
910Sstevel@tonic-gate void
920Sstevel@tonic-gate ibtl_ib2usec_init(void)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate int i;
950Sstevel@tonic-gate
960Sstevel@tonic-gate for (i = 0; i < 64; i++) {
970Sstevel@tonic-gate if (i < 51) { /* shift first to avoid underflow */
980Sstevel@tonic-gate ibtl_ib2usec_tbl[i] = ((1LL << i) << 12LL) / 1000LL;
990Sstevel@tonic-gate } else if (i < 61) { /* divide first to avoid overflow */
1000Sstevel@tonic-gate ibtl_ib2usec_tbl[i] = ((1LL << i) / 1000LL) << 12LL;
1010Sstevel@tonic-gate } else { /* max'ed out, so use MAX LONGLONG */
1020Sstevel@tonic-gate ibtl_ib2usec_tbl[i] = 0x7FFFFFFFFFFFFFFFLL;
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate #if !defined(_LP64)
1050Sstevel@tonic-gate if (ibtl_ib2usec_tbl[i] > LONG_MAX)
1060Sstevel@tonic-gate ibtl_ib2usec_tbl[i] = LONG_MAX;
1070Sstevel@tonic-gate #endif
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate /*
1120Sstevel@tonic-gate * Function:
1130Sstevel@tonic-gate * ibt_usec2ib
1140Sstevel@tonic-gate * Input:
1150Sstevel@tonic-gate * time_val - Time in microsecs.
1160Sstevel@tonic-gate * Output:
1170Sstevel@tonic-gate * none
1180Sstevel@tonic-gate * Returns:
1190Sstevel@tonic-gate * Nearest IB Timeout Exponent value.
1200Sstevel@tonic-gate * Description:
1210Sstevel@tonic-gate * This function converts the standard input time in microseconds to
1220Sstevel@tonic-gate * IB's 6 bits of timeout exponent, calculated based on
1230Sstevel@tonic-gate * time = 4.096us * 2 ^ exp. This is done by searching through
1240Sstevel@tonic-gate * the ibtl_ib2usec_tbl for the closest value >= time_val.
1250Sstevel@tonic-gate */
1260Sstevel@tonic-gate ib_time_t
ibt_usec2ib(clock_t time_val)1270Sstevel@tonic-gate ibt_usec2ib(clock_t time_val)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate int i;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_util, "ibt_usec2ib(%ld)", time_val);
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate /* First, leap through the table by 4 entries at a time */
134*8659SBill.Taylor@Sun.COM for (i = 0; (i + 4) < 64 && ibtl_ib2usec_tbl[i + 4] < time_val; i += 4)
135*8659SBill.Taylor@Sun.COM ;
1360Sstevel@tonic-gate /* Find the return value; it's now between i and i + 4, inclusive */
1370Sstevel@tonic-gate while (ibtl_ib2usec_tbl[i] < time_val)
1380Sstevel@tonic-gate i++;
1390Sstevel@tonic-gate return (i);
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate /*
1440Sstevel@tonic-gate * Function:
1450Sstevel@tonic-gate * ibt_ib2usec
1460Sstevel@tonic-gate * Input:
1470Sstevel@tonic-gate * ib_time - IB Timeout Exponent value.
1480Sstevel@tonic-gate * Output:
1490Sstevel@tonic-gate * none
1500Sstevel@tonic-gate * Returns:
1510Sstevel@tonic-gate * Standard Time is microseconds.
1520Sstevel@tonic-gate * Description:
1530Sstevel@tonic-gate * This function converts the input IB timeout exponent (6 bits) to
1540Sstevel@tonic-gate * standard time in microseconds, calculated based on
1550Sstevel@tonic-gate * time = 4.096us * 2 ^ exp.
1560Sstevel@tonic-gate * This is implemented as a simple index into ibtl_ib2usec_tbl[].
1570Sstevel@tonic-gate */
1580Sstevel@tonic-gate clock_t
ibt_ib2usec(ib_time_t ib_time)1590Sstevel@tonic-gate ibt_ib2usec(ib_time_t ib_time)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_util, "ibt_ib2usec(%d)", ib_time);
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate return ((clock_t)ibtl_ib2usec_tbl[ib_time & IB_TIME_EXP_MASK]);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate /* IBTF logging init */
1680Sstevel@tonic-gate void
ibtl_logging_initialization()1690Sstevel@tonic-gate ibtl_logging_initialization()
1700Sstevel@tonic-gate {
1710Sstevel@tonic-gate boolean_t flag = B_FALSE;
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_util, "ibtl_logging_initialization:");
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate mutex_init(&ibtf_print_mutex, NULL, MUTEX_DRIVER, NULL);
1760Sstevel@tonic-gate mutex_enter(&ibtf_print_mutex);
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate if (ibtf_debug_buf_size <= IBTF_DEBUG_SIZE_EXTRA_ALLOC) {
1790Sstevel@tonic-gate ibtf_debug_buf_size = IBTF_MIN_DEBUG_BUF_SIZE;
1800Sstevel@tonic-gate flag = B_TRUE;
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate /* if it is less that IBTF_MIN_DEBUG_BUF_SIZE, adjust it */
1840Sstevel@tonic-gate ibtf_debug_buf_size = max(IBTF_MIN_DEBUG_BUF_SIZE,
1850Sstevel@tonic-gate ibtf_debug_buf_size);
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate ibtf_debug_buf = (char *)kmem_alloc(ibtf_debug_buf_size, KM_SLEEP);
1880Sstevel@tonic-gate ibtf_clear_print_buf();
1890Sstevel@tonic-gate mutex_exit(&ibtf_print_mutex);
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate if (flag == B_TRUE) {
1920Sstevel@tonic-gate IBTF_DPRINTF_L2(ibtf_util, "ibtf_debug_buf_size was too small "
1930Sstevel@tonic-gate "%x, adjusted to %x", ibtf_debug_buf_size,
1940Sstevel@tonic-gate IBTF_MIN_DEBUG_BUF_SIZE);
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate /* IBTF logging destroy */
2000Sstevel@tonic-gate void
ibtl_logging_destroy()2010Sstevel@tonic-gate ibtl_logging_destroy()
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_util, "ibtl_logging_destroy");
2040Sstevel@tonic-gate
2050Sstevel@tonic-gate mutex_enter(&ibtf_print_mutex);
2060Sstevel@tonic-gate if (ibtf_debug_buf) {
2070Sstevel@tonic-gate kmem_free(ibtf_debug_buf, ibtf_debug_buf_size);
2080Sstevel@tonic-gate ibtf_debug_buf = NULL;
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate mutex_exit(&ibtf_print_mutex);
2110Sstevel@tonic-gate mutex_destroy(&ibtf_print_mutex);
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate
2140Sstevel@tonic-gate
2150Sstevel@tonic-gate /*
2160Sstevel@tonic-gate * debug, log, and console message handling
2170Sstevel@tonic-gate */
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate * clear the IBTF trace buffer
2210Sstevel@tonic-gate */
2220Sstevel@tonic-gate static void
ibtf_clear_print_buf()2230Sstevel@tonic-gate ibtf_clear_print_buf()
2240Sstevel@tonic-gate {
2250Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibtf_print_mutex));
2260Sstevel@tonic-gate if (ibtf_debug_buf) {
2270Sstevel@tonic-gate ibtf_buf_sptr = ibtf_debug_buf;
2280Sstevel@tonic-gate ibtf_buf_eptr = ibtf_debug_buf + ibtf_debug_buf_size -
2290Sstevel@tonic-gate IBTF_DEBUG_SIZE_EXTRA_ALLOC;
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate bzero(ibtf_debug_buf, ibtf_debug_buf_size);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate static void
ibtf_vlog(char * name,uint_t level,char * fmt,va_list ap)2370Sstevel@tonic-gate ibtf_vlog(char *name, uint_t level, char *fmt, va_list ap)
2380Sstevel@tonic-gate {
2390Sstevel@tonic-gate char *label = (name == NULL) ? "ibtl" : name;
2400Sstevel@tonic-gate char *msg_ptr;
2410Sstevel@tonic-gate size_t len;
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate mutex_enter(&ibtf_print_mutex);
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate /* if not using logging scheme; quit */
2460Sstevel@tonic-gate if (ibtf_suppress_dprintf || (ibtf_debug_buf == NULL)) {
2470Sstevel@tonic-gate mutex_exit(&ibtf_print_mutex);
2480Sstevel@tonic-gate return;
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate /* if level doesn't match, we are done */
2520Sstevel@tonic-gate if ((level < IBTF_LOG_L0) || (level > IBTF_LOG_LINTR)) {
2530Sstevel@tonic-gate mutex_exit(&ibtf_print_mutex);
2540Sstevel@tonic-gate return;
2550Sstevel@tonic-gate }
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate /* If user requests to clear debug buffer, go ahead */
2580Sstevel@tonic-gate if (ibtf_clear_debug_buf_flag != 0) {
2590Sstevel@tonic-gate ibtf_clear_print_buf();
2600Sstevel@tonic-gate ibtf_clear_debug_buf_flag = 0;
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate /*
2640Sstevel@tonic-gate * Check if we have a valid buf size?
2650Sstevel@tonic-gate * Suppress logging to ibtf_buffer if so.
2660Sstevel@tonic-gate */
2670Sstevel@tonic-gate if (ibtf_debug_buf_size <= 0) {
2680Sstevel@tonic-gate ibtf_buffer_dprintf = 0;
2690Sstevel@tonic-gate }
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate /*
2720Sstevel@tonic-gate * put "label" into the buffer
2730Sstevel@tonic-gate */
2740Sstevel@tonic-gate len = snprintf(ibtf_print_buf, IBTL_DRVNAME_LEN, "%s:\t", label);
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate msg_ptr = ibtf_print_buf + len;
2770Sstevel@tonic-gate len += vsnprintf(msg_ptr, IBTL_PRINT_BUF_LEN - len - 2, fmt, ap);
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate len = min(len, IBTL_PRINT_BUF_LEN - 2);
2800Sstevel@tonic-gate ASSERT(len == strlen(ibtf_print_buf));
2810Sstevel@tonic-gate ibtf_print_buf[len++] = '\n';
2820Sstevel@tonic-gate ibtf_print_buf[len] = '\0';
2830Sstevel@tonic-gate
2840Sstevel@tonic-gate /*
2850Sstevel@tonic-gate * stuff the message in the debug buf
2860Sstevel@tonic-gate */
2870Sstevel@tonic-gate if (ibtf_buffer_dprintf) {
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate /*
2900Sstevel@tonic-gate * overwrite >>>> that might be over the end of the
2910Sstevel@tonic-gate * the buffer
2920Sstevel@tonic-gate */
2930Sstevel@tonic-gate *ibtf_buf_sptr = '\0';
2940Sstevel@tonic-gate
2950Sstevel@tonic-gate if (ibtf_buf_sptr + len > ibtf_buf_eptr) {
2960Sstevel@tonic-gate size_t left = ibtf_buf_eptr - ibtf_buf_sptr;
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate bcopy((caddr_t)ibtf_print_buf,
299*8659SBill.Taylor@Sun.COM (caddr_t)ibtf_buf_sptr, left);
3000Sstevel@tonic-gate bcopy((caddr_t)ibtf_print_buf + left,
301*8659SBill.Taylor@Sun.COM (caddr_t)ibtf_debug_buf, len - left);
3020Sstevel@tonic-gate ibtf_buf_sptr = ibtf_debug_buf + len - left;
3030Sstevel@tonic-gate } else {
3040Sstevel@tonic-gate bcopy((caddr_t)ibtf_print_buf, ibtf_buf_sptr, len);
3050Sstevel@tonic-gate ibtf_buf_sptr += len;
3060Sstevel@tonic-gate }
3070Sstevel@tonic-gate
3080Sstevel@tonic-gate /* add marker */
3090Sstevel@tonic-gate (void) sprintf(ibtf_buf_sptr, ">>>>");
3100Sstevel@tonic-gate }
3110Sstevel@tonic-gate
3120Sstevel@tonic-gate /*
3130Sstevel@tonic-gate * LINTR, L5-L2 message may go to the ibtf_debug_buf
3140Sstevel@tonic-gate * L1 messages will go to the log buf in non-debug kernels and
3150Sstevel@tonic-gate * to console and log buf in debug kernels
3160Sstevel@tonic-gate * L0 messages are warnings and will go to console and log buf
3170Sstevel@tonic-gate */
3180Sstevel@tonic-gate switch (level) {
3190Sstevel@tonic-gate case IBTF_LOG_LINTR:
3200Sstevel@tonic-gate case IBTF_LOG_L5:
3210Sstevel@tonic-gate case IBTF_LOG_L4:
3220Sstevel@tonic-gate case IBTF_LOG_L3:
3230Sstevel@tonic-gate case IBTF_LOG_L2:
3240Sstevel@tonic-gate if (!ibtf_buffer_dprintf) {
3250Sstevel@tonic-gate cmn_err(CE_CONT, "^%s", ibtf_print_buf);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate break;
3280Sstevel@tonic-gate case IBTF_LOG_L1:
3290Sstevel@tonic-gate #ifdef DEBUG
3300Sstevel@tonic-gate cmn_err(CE_CONT, "%s", ibtf_print_buf);
3310Sstevel@tonic-gate #else
3320Sstevel@tonic-gate if (!ibtf_buffer_dprintf) {
3330Sstevel@tonic-gate cmn_err(CE_CONT, "^%s", ibtf_print_buf);
3340Sstevel@tonic-gate }
3350Sstevel@tonic-gate #endif
3360Sstevel@tonic-gate break;
3370Sstevel@tonic-gate case IBTF_LOG_L0:
3380Sstevel@tonic-gate /* Strip the "\n" added earlier */
3390Sstevel@tonic-gate if (ibtf_print_buf[len - 1] == '\n') {
3400Sstevel@tonic-gate ibtf_print_buf[len - 1] = '\0';
3410Sstevel@tonic-gate }
3420Sstevel@tonic-gate if (msg_ptr[len - 1] == '\n') {
3430Sstevel@tonic-gate msg_ptr[len - 1] = '\0';
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate cmn_err(CE_WARN, ibtf_print_buf);
3460Sstevel@tonic-gate break;
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate mutex_exit(&ibtf_print_mutex);
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate
3530Sstevel@tonic-gate void
ibtl_dprintf_intr(char * name,char * fmt,...)3540Sstevel@tonic-gate ibtl_dprintf_intr(char *name, char *fmt, ...)
3550Sstevel@tonic-gate {
3560Sstevel@tonic-gate va_list ap;
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate /* only log messages if "ibtf_allow_intr_msgs" is set */
3590Sstevel@tonic-gate if (!ibtf_allow_intr_msgs)
3600Sstevel@tonic-gate return;
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate va_start(ap, fmt);
3630Sstevel@tonic-gate ibtf_vlog(name, IBTF_LOG_LINTR, fmt, ap);
3640Sstevel@tonic-gate va_end(ap);
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate /*
3690Sstevel@tonic-gate * Check individual subsystem err levels
3700Sstevel@tonic-gate */
3710Sstevel@tonic-gate #define IBTL_CHECK_ERR_LEVEL(level) \
3720Sstevel@tonic-gate if (strncmp(name, "ibgen", 5) == 0) { \
3730Sstevel@tonic-gate if (ibgen_errlevel < level) \
3740Sstevel@tonic-gate return; \
3750Sstevel@tonic-gate } else if (strncmp(name, "ibtl", 4) == 0) { \
3760Sstevel@tonic-gate if (ibtl_errlevel < level) \
3770Sstevel@tonic-gate return; \
3780Sstevel@tonic-gate } else if (strncmp(name, "ibcm", 4) == 0) { \
3790Sstevel@tonic-gate if (ibcm_errlevel < level) \
3800Sstevel@tonic-gate return; \
3810Sstevel@tonic-gate } else if (strncmp(name, "ibdm", 4) == 0) { \
3820Sstevel@tonic-gate if (ibdm_errlevel < level) \
3830Sstevel@tonic-gate return; \
3840Sstevel@tonic-gate } else if (strncmp(name, "ibnex", 5) == 0) { \
3850Sstevel@tonic-gate if (ibnex_errlevel < level) \
3860Sstevel@tonic-gate return; \
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate void
ibtl_dprintf5(char * name,char * fmt,...)3900Sstevel@tonic-gate ibtl_dprintf5(char *name, char *fmt, ...)
3910Sstevel@tonic-gate {
3920Sstevel@tonic-gate va_list ap;
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate /* check if global errlevel matches or not */
3950Sstevel@tonic-gate if (ibtf_errlevel < IBTF_LOG_L5)
3960Sstevel@tonic-gate return;
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L5);
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate va_start(ap, fmt);
4010Sstevel@tonic-gate ibtf_vlog(name, IBTF_LOG_L5, fmt, ap);
4020Sstevel@tonic-gate va_end(ap);
4030Sstevel@tonic-gate }
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate void
ibtl_dprintf4(char * name,char * fmt,...)4060Sstevel@tonic-gate ibtl_dprintf4(char *name, char *fmt, ...)
4070Sstevel@tonic-gate {
4080Sstevel@tonic-gate va_list ap;
4090Sstevel@tonic-gate
4100Sstevel@tonic-gate /* check if global errlevel matches or not */
4110Sstevel@tonic-gate if (ibtf_errlevel < IBTF_LOG_L4)
4120Sstevel@tonic-gate return;
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L4);
4150Sstevel@tonic-gate
4160Sstevel@tonic-gate va_start(ap, fmt);
4170Sstevel@tonic-gate ibtf_vlog(name, IBTF_LOG_L4, fmt, ap);
4180Sstevel@tonic-gate va_end(ap);
4190Sstevel@tonic-gate }
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate void
ibtl_dprintf3(char * name,char * fmt,...)4230Sstevel@tonic-gate ibtl_dprintf3(char *name, char *fmt, ...)
4240Sstevel@tonic-gate {
4250Sstevel@tonic-gate va_list ap;
4260Sstevel@tonic-gate
4270Sstevel@tonic-gate /* check if global errlevel matches or not */
4280Sstevel@tonic-gate if (ibtf_errlevel < IBTF_LOG_L3)
4290Sstevel@tonic-gate return;
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L3);
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate va_start(ap, fmt);
4340Sstevel@tonic-gate ibtf_vlog(name, IBTF_LOG_L3, fmt, ap);
4350Sstevel@tonic-gate va_end(ap);
4360Sstevel@tonic-gate }
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate
4390Sstevel@tonic-gate void
ibtl_dprintf2(char * name,char * fmt,...)4400Sstevel@tonic-gate ibtl_dprintf2(char *name, char *fmt, ...)
4410Sstevel@tonic-gate {
4420Sstevel@tonic-gate va_list ap;
4430Sstevel@tonic-gate
4440Sstevel@tonic-gate /* check if global errlevel matches or not */
4450Sstevel@tonic-gate if (ibtf_errlevel < IBTF_LOG_L2)
4460Sstevel@tonic-gate return;
4470Sstevel@tonic-gate
4480Sstevel@tonic-gate IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L2);
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate va_start(ap, fmt);
4510Sstevel@tonic-gate ibtf_vlog(name, IBTF_LOG_L2, fmt, ap);
4520Sstevel@tonic-gate va_end(ap);
4530Sstevel@tonic-gate }
4540Sstevel@tonic-gate
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate void
ibtl_dprintf1(char * name,char * fmt,...)4570Sstevel@tonic-gate ibtl_dprintf1(char *name, char *fmt, ...)
4580Sstevel@tonic-gate {
4590Sstevel@tonic-gate va_list ap;
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate /* check if global errlevel matches or not */
4620Sstevel@tonic-gate if (ibtf_errlevel < IBTF_LOG_L1)
4630Sstevel@tonic-gate return;
4640Sstevel@tonic-gate
4650Sstevel@tonic-gate va_start(ap, fmt);
4660Sstevel@tonic-gate ibtf_vlog(name, IBTF_LOG_L1, fmt, ap);
4670Sstevel@tonic-gate va_end(ap);
4680Sstevel@tonic-gate }
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate /*
4720Sstevel@tonic-gate * Function:
4730Sstevel@tonic-gate * ibtf_dprintf0
4740Sstevel@tonic-gate * Input:
4750Sstevel@tonic-gate * name - Name of the subsystem generating the debug message
4760Sstevel@tonic-gate * fmt - The message to be displayed.
4770Sstevel@tonic-gate * Output:
4780Sstevel@tonic-gate * none
4790Sstevel@tonic-gate * Returns:
4800Sstevel@tonic-gate * none
4810Sstevel@tonic-gate * Description:
4820Sstevel@tonic-gate * A generic log function to display IBTF debug messages.
4830Sstevel@tonic-gate */
4840Sstevel@tonic-gate void
ibtl_dprintf0(char * name,char * fmt,...)4850Sstevel@tonic-gate ibtl_dprintf0(char *name, char *fmt, ...)
4860Sstevel@tonic-gate {
4870Sstevel@tonic-gate va_list ap;
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate /* check if global errlevel matches or not */
4900Sstevel@tonic-gate if (ibtf_errlevel < IBTF_LOG_L0)
4910Sstevel@tonic-gate return;
4920Sstevel@tonic-gate
4930Sstevel@tonic-gate va_start(ap, fmt);
4940Sstevel@tonic-gate ibtf_vlog(name, IBTF_LOG_L0, fmt, ap);
4950Sstevel@tonic-gate va_end(ap);
4960Sstevel@tonic-gate }
497