fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld * You can obtain a copy of the license at
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld * http://www.opensource.org/licenses/cddl1.txt.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld * Copyright (c) 2004-2012 Emulex. All rights reserved.
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan * Use is subject to license terms.
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan#define DEF_MSG_STRUCT /* Needed for emlxs_messages.h in emlxs_msg.h */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathanuint32_t emlxs_log_warnings = 0xFFFFFFFF;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathanstatic uint32_t emlxs_msg_log_check(emlxs_port_t *port, emlxs_msg_t *msg);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathanstatic uint32_t emlxs_msg_print_check(emlxs_port_t *port, emlxs_msg_t *msg);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathanstatic void emlxs_msg_sprintf(char *buffer, emlxs_msg_entry_t *entry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t size = sizeof (emlxs_msg_entry_t) * emlxs_log_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if log is already created */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "?%s%d: message log already created. log=%p",
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan DRIVER_NAME, hba->ddiinst, (void *)log);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clear the log */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the memory needed for the log file */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan log->entry = (emlxs_msg_entry_t *)kmem_zalloc(size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the current interrupt block cookie */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_get_iblock_cookie(hba->dip, (uint_t)EMLXS_INUMBER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create the log mutex lock */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld mutex_init(&log->lock, NULL, MUTEX_DRIVER, (void *)iblock);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Create the temporary log mutex lock */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld mutex_init(&log->lock, NULL, MUTEX_DRIVER, NULL);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore} /* emlxs_msg_log_create() */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Check if log is already destroyed */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore "?%s%d: message log already destroyed. log=%p",
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Destroy the temporary lock */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Re-create the log mutex lock */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld mutex_init(&log->lock, NULL, MUTEX_DRIVER, DDI_INTR_PRI(hba->intr_arg));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore} /* emlxs_msg_lock_reinit() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if log is already destroyed */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "?%s%d: message log already destroyed. log=%p",
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan DRIVER_NAME, hba->ddiinst, (void *)log);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Destroy the lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free the log buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clear the log */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_msg_log_destroy() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_msg_log(emlxs_port_t *port, const uint32_t fileno, const uint32_t line,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the log file for this instance */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if log is initialized */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the pointer to the last log entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if this matches the last message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If the same message is being logged then increment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the pointer to the next log entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Increment and check the next entry index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Save the additional info buffer */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) snprintf(entry2->buffer, MAX_LOG_INFO_LENGTH,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Last message repeated %d time(s).",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set the entry time stamp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the pointer to the next log entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Increment and check the next entry index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Save the additional info buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(entry->buffer, buffer, (MAX_LOG_INFO_LENGTH - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set the entry time stamp */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_msg_log() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_msg_log_check(emlxs_port_t *port, emlxs_msg_t *msg)
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_msg_log_check() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_msg_print_check(emlxs_port_t *port, emlxs_msg_t *msg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (msg->mask & cfg[CFG_CONSOLE_DEBUGS].current) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (msg->mask & cfg[CFG_CONSOLE_NOTICES].current) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (msg->mask & cfg[CFG_CONSOLE_WARNINGS].current) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (msg->mask & cfg[CFG_CONSOLE_ERRORS].current) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_msg_print_check() */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathanemlxs_msg_printf(emlxs_port_t *port, const uint32_t fileno,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan const char *fmt, ...)
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) vsnprintf(va_str, sizeof (va_str), fmt, valist);
bb63f56ebeb244bd34f5e8d50900e3420f01b394Sukumar Swaminathan emlxs_fm_ereport(hba, msg->fm_ereport_code);
bb63f56ebeb244bd34f5e8d50900e3420f01b394Sukumar Swaminathan emlxs_fm_service_impact(hba, msg->fm_impact_code);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan#endif /* FMA_SUPPORT */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if msg should be logged */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Log the message */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (emlxs_msg_log(port, fileno, line, msg, va_str)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if msg should be printed */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) snprintf(driver, sizeof (driver), "%s%d",
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) snprintf(driver, sizeof (driver), "%s%d.%d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Generate the message string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (va_str[0] != 0) {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "[%2X.%04X]%s:%7s:%4d: %s (%s)\n", fileno,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan line, driver, level, msg->id, msg->buffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "[%2X.%04X]%s:%7s:%4d: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (va_str[0] != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "[%2X.%04X]%s:%7s:%4d\n",
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Message log & console, if system booted in */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* verbose mode (CE_CONT only) */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_msg_printf() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_msg_log_get(emlxs_hba_t *hba, emlxs_log_req_t *req,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if buffer is empty */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If so, exit now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get current log entry ranges */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get last entry id saved */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if request is out of current range */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if so, exit now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get oldest entry id and its index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if buffer has already been filled once */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* Buffer not yet filled */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Check if requested first message is greater than actual. */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* If so, adjust for it. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Adjust entry index to first requested message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the total number of messages available for return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if requested count is less than actual. If so, adjust it. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Fill in the response header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Fill the response buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp_buf = (char *)resp + sizeof (emlxs_log_resp_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < count; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Increment the response buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Increment index */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_msg_log_get() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_msg_sprintf(char *buffer, emlxs_msg_entry_t *entry)
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) snprintf(driver, sizeof (driver), "%s%d", DRIVER_NAME,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) snprintf(driver, sizeof (driver), "%s%d.%d", DRIVER_NAME,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Generate the message string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: %s (%s)\n",
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan entry->line, driver, level, msg->id, msg->buffer,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: %s\n", secs,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan hsecs, entry->id, entry->fileno, entry->line,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: (%s)\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(buffer, buf, (MAX_LOG_MSG_LENGTH - 2));
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_msg_sprintf() */