c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CDDL HEADER START
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The contents of this file are subject to the terms of the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Common Development and Distribution License (the "License").
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * You may not use this file except in compliance with the License.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * See the License for the specific language governing permissions
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * and limitations under the License.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * When distributing Covered Code, include this CDDL HEADER in each
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If applicable, add the following below this CDDL HEADER, with the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fields enclosed by brackets "[]" replaced with your own identifying
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * information: Portions Copyright [yyyy] [name of copyright owner]
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CDDL HEADER END
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This file contains the debug defines and routines.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Debugging information is collected in a circular kernel buffer. Debug
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * messages with level lower than rdsv3dbglvl are ignored. The size of the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * of the debug buffer can be changed by setting 'rdsv3_debug_buf_size' in
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * bytes in /etc/system.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The debug buffer can be cleared by setting 'rdsv3_clear_debug_buf_flag = 1'
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * on a running system.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#endif /* DEBUG */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* Max length of a debug statement */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic int rdsv3_suppress_dprintf; /* Suppress debug printing */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic int rdsv3_buffer_dprintf = 1; /* Use debug buffer (0 == console) */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic int rdsv3_debug_buf_size = RDSV3_DEBUG_BUF_SIZE; /* Sz of Debug buf */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic int rdsv3_allow_intr_msgs = 0; /* log "intr" messages */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otachar *rdsv3_buf_sptr, *rdsv3_buf_eptr; /* debug buffer temp pointer */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otaint rdsv3_clear_debug_buf_flag = 0; /* Clear debug buffer */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Print Buffer protected by mutex for debug stuff. The mutex also
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * ensures serializing debug messages.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* Function Prototypes */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* RDS logging init */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota mutex_init(&rdsv3_debug_mutex, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rdsv3_debug_buf_size <= RDSV3_DEBUG_SIZE_EXTRA_ALLOC) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* if it is less that RDSV3_MIN_DEBUG_BUF_SIZE, adjust it */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_debug_buf_size = max(RDSV3_MIN_DEBUG_BUF_SIZE,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_debug_buf = (char *)kmem_alloc(rdsv3_debug_buf_size, KM_SLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF2("RDS", "rdsv3_debug_buf_size was too small, "
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* RDS logging destroy */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * debug, log, and console message handling
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * clear the RDS debug buffer
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rdsv3_buf_eptr = rdsv3_debug_buf + rdsv3_debug_buf_size -
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_vlog(char *name, uint_t level, char *fmt, va_list ap)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* if not using logging scheme; quit */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (rdsv3_suppress_dprintf || (rdsv3_debug_buf == NULL)) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* If user requests to clear debug buffer, go ahead */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * put "label" into the buffer
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota len = snprintf(rdsv3_print_buf, RDSV3_FUNCNAME_LEN, "%s:\t", label);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota len += vsnprintf(msg_ptr, RDSV3_PRINT_BUF_LEN - len - 2, fmt, ap);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * stuff the message in the debug buf
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * overwrite >>>> that might be over the end of the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * the buffer
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota bcopy((caddr_t)rdsv3_print_buf, rdsv3_buf_sptr, len);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* add marker */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * LINTR, L5-L2 message may go to the rdsv3_debug_buf
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * L1 messages will go to the /var/adm/messages (debug & non-debug).
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * L0 messages will go to console (debug & non-debug).
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* go to messages file */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Strip the "\n" added earlier */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* go to console */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Check individual subsystem err levels
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Function:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * rdsv3_dprintf0
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * name - Name of the function generating the debug message
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fmt - The message to be displayed.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Description:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * A generic log function to display RDS debug messages.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* For ofed rdstrace */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_trace(char *name, uint8_t lvl, char *fmt, ...)
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota#define DEFINE_RATELIMIT_STATE(name, interval, burst) \
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota static struct ratelimit_state name = {interval, burst, }
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji OtaDEFINE_RATELIMIT_STATE(rdsv3_printk_ratelimit_state,
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota struct ratelimit_state *rs = &rdsv3_printk_ratelimit_state;
cadbfdc3bdb156e92d7a88978bc98ea87f6e037fEiji Ota return (1);