emlxs_msg.c (a9800beb) emlxs_msg.c (8f23e9fa)
1/*
2 * CDDL HEADER START
3 *
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.
7 *
1/*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
8 * You can obtain a copy of the license at
9 * http://www.opensource.org/licenses/cddl1.txt.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2010 Emulex. All rights reserved.
23 * Copyright (c) 2004-2012 Emulex. All rights reserved.
24 * Use is subject to license terms.
25 */
26
24 * Use is subject to license terms.
25 */
26
27
28#define DEF_MSG_STRUCT /* Needed for emlxs_messages.h in emlxs_msg.h */
29#include <emlxs.h>
30
31uint32_t emlxs_log_size = 2048;
32uint32_t emlxs_log_debugs = 0x7FFFFFFF;
33uint32_t emlxs_log_notices = 0xFFFFFFFF;
34uint32_t emlxs_log_warnings = 0xFFFFFFFF;
35uint32_t emlxs_log_errors = 0xFFFFFFFF;
36
37static uint32_t emlxs_msg_log_check(emlxs_port_t *port, emlxs_msg_t *msg);
38static uint32_t emlxs_msg_print_check(emlxs_port_t *port, emlxs_msg_t *msg);
39static void emlxs_msg_sprintf(char *buffer, emlxs_msg_entry_t *entry);
40
41
42uint32_t
43emlxs_msg_log_create(emlxs_hba_t *hba)
44{
45 emlxs_msg_log_t *log = &LOG;
46 uint32_t size = sizeof (emlxs_msg_entry_t) * emlxs_log_size;
27#define DEF_MSG_STRUCT /* Needed for emlxs_messages.h in emlxs_msg.h */
28#include <emlxs.h>
29
30uint32_t emlxs_log_size = 2048;
31uint32_t emlxs_log_debugs = 0x7FFFFFFF;
32uint32_t emlxs_log_notices = 0xFFFFFFFF;
33uint32_t emlxs_log_warnings = 0xFFFFFFFF;
34uint32_t emlxs_log_errors = 0xFFFFFFFF;
35
36static uint32_t emlxs_msg_log_check(emlxs_port_t *port, emlxs_msg_t *msg);
37static uint32_t emlxs_msg_print_check(emlxs_port_t *port, emlxs_msg_t *msg);
38static void emlxs_msg_sprintf(char *buffer, emlxs_msg_entry_t *entry);
39
40
41uint32_t
42emlxs_msg_log_create(emlxs_hba_t *hba)
43{
44 emlxs_msg_log_t *log = &LOG;
45 uint32_t size = sizeof (emlxs_msg_entry_t) * emlxs_log_size;
47 char buf[40];
48 ddi_iblock_cookie_t iblock;
49
50 /* Check if log is already created */
51 if (log->entry) {
52 cmn_err(CE_WARN, "?%s%d: message log already created. log=%p",
53 DRIVER_NAME, hba->ddiinst, (void *)log);
54 return (0);
55 }

--- 4 unchanged lines hidden (view full) ---

60 /* Allocate the memory needed for the log file */
61 log->entry = (emlxs_msg_entry_t *)kmem_zalloc(size, KM_SLEEP);
62
63 /* Initialize */
64 log->size = emlxs_log_size;
65 log->instance = hba->ddiinst;
66 log->start_time = emlxs_device.log_timestamp;
67
46 ddi_iblock_cookie_t iblock;
47
48 /* Check if log is already created */
49 if (log->entry) {
50 cmn_err(CE_WARN, "?%s%d: message log already created. log=%p",
51 DRIVER_NAME, hba->ddiinst, (void *)log);
52 return (0);
53 }

--- 4 unchanged lines hidden (view full) ---

58 /* Allocate the memory needed for the log file */
59 log->entry = (emlxs_msg_entry_t *)kmem_zalloc(size, KM_SLEEP);
60
61 /* Initialize */
62 log->size = emlxs_log_size;
63 log->instance = hba->ddiinst;
64 log->start_time = emlxs_device.log_timestamp;
65
68 (void) sprintf(buf, "?%s%d_log_lock mutex", DRIVER_NAME, hba->ddiinst);
69
70 if (!(hba->intr_flags & EMLXS_MSI_ENABLED)) {
71 /* Get the current interrupt block cookie */
72 (void) ddi_get_iblock_cookie(hba->dip, (uint_t)EMLXS_INUMBER,
73 &iblock);
74
75 /* Create the log mutex lock */
66 if (!(hba->intr_flags & EMLXS_MSI_ENABLED)) {
67 /* Get the current interrupt block cookie */
68 (void) ddi_get_iblock_cookie(hba->dip, (uint_t)EMLXS_INUMBER,
69 &iblock);
70
71 /* Create the log mutex lock */
76 mutex_init(&log->lock, buf, MUTEX_DRIVER, (void *)iblock);
72 mutex_init(&log->lock, NULL, MUTEX_DRIVER, (void *)iblock);
77 }
78#ifdef MSI_SUPPORT
79 else {
80 /* Create the temporary log mutex lock */
73 }
74#ifdef MSI_SUPPORT
75 else {
76 /* Create the temporary log mutex lock */
81 mutex_init(&log->lock, buf, MUTEX_DRIVER, NULL);
77 mutex_init(&log->lock, NULL, MUTEX_DRIVER, NULL);
82 }
83#endif
84
85 return (1);
86
87} /* emlxs_msg_log_create() */
88
89
90void
91emlxs_msg_lock_reinit(emlxs_hba_t *hba)
92{
93 emlxs_msg_log_t *log = &LOG;
78 }
79#endif
80
81 return (1);
82
83} /* emlxs_msg_log_create() */
84
85
86void
87emlxs_msg_lock_reinit(emlxs_hba_t *hba)
88{
89 emlxs_msg_log_t *log = &LOG;
94 char buf[40];
95
96 /* Check if log is already destroyed */
97 if (!log->entry) {
98 cmn_err(CE_WARN,
99 "?%s%d: message log already destroyed. log=%p",
100 DRIVER_NAME, hba->ddiinst, (void *)log);
101
102 return;
103 }
104
105 /* Destroy the temporary lock */
106 mutex_destroy(&log->lock);
107
108 /* Re-create the log mutex lock */
90
91 /* Check if log is already destroyed */
92 if (!log->entry) {
93 cmn_err(CE_WARN,
94 "?%s%d: message log already destroyed. log=%p",
95 DRIVER_NAME, hba->ddiinst, (void *)log);
96
97 return;
98 }
99
100 /* Destroy the temporary lock */
101 mutex_destroy(&log->lock);
102
103 /* Re-create the log mutex lock */
109 (void) sprintf(buf, "?%s%d_log_lock mutex", DRIVER_NAME, hba->ddiinst);
110 mutex_init(&log->lock, buf, MUTEX_DRIVER, DDI_INTR_PRI(hba->intr_arg));
104 mutex_init(&log->lock, NULL, MUTEX_DRIVER, DDI_INTR_PRI(hba->intr_arg));
111
112 return;
113
114} /* emlxs_msg_lock_reinit() */
115
116void
117emlxs_msg_log_destroy(emlxs_hba_t *hba)
118{

--- 36 unchanged lines hidden (view full) ---

155 uint32_t last;
156 emlxs_msg_t *msg2;
157
158 /* Get the log file for this instance */
159 log = &LOG;
160
161 /* Check if log is initialized */
162 if (log->entry == NULL) {
105
106 return;
107
108} /* emlxs_msg_lock_reinit() */
109
110void
111emlxs_msg_log_destroy(emlxs_hba_t *hba)
112{

--- 36 unchanged lines hidden (view full) ---

149 uint32_t last;
150 emlxs_msg_t *msg2;
151
152 /* Get the log file for this instance */
153 log = &LOG;
154
155 /* Check if log is initialized */
156 if (log->entry == NULL) {
163
164 if (port->vpi == 0) {
165 cmn_err(CE_WARN,
166 "?%s%d: message log not created. log=%p",
167 DRIVER_NAME, hba->ddiinst, (void *)log);
168 } else {
169 cmn_err(CE_WARN,
170 "?%s%d.%d: message log not created. log=%p",
171 DRIVER_NAME, hba->ddiinst, port->vpi,
172 (void *)log);
173 }
174
175 return (1);
157 return (0);
176 }
177
178 mutex_enter(&log->lock);
179
180 /* Get the pointer to the last log entry */
181 if (log->next == 0) {
182 last = log->size - 1;
183 } else {

--- 19 unchanged lines hidden (view full) ---

203 entry2 = &log->entry[log->next];
204
205 /* Increment and check the next entry index */
206 if (++(log->next) >= log->size) {
207 log->next = 0;
208 }
209
210 switch (entry->msg->level) {
158 }
159
160 mutex_enter(&log->lock);
161
162 /* Get the pointer to the last log entry */
163 if (log->next == 0) {
164 last = log->size - 1;
165 } else {

--- 19 unchanged lines hidden (view full) ---

185 entry2 = &log->entry[log->next];
186
187 /* Increment and check the next entry index */
188 if (++(log->next) >= log->size) {
189 log->next = 0;
190 }
191
192 switch (entry->msg->level) {
211 case EMLXS_DEBUG:
212 msg2 = &emlxs_debug_msg;
213 break;
214
215 case EMLXS_NOTICE:
216 msg2 = &emlxs_notice_msg;
217 break;
218
219 case EMLXS_WARNING:
220 msg2 = &emlxs_warning_msg;
221 break;
222
223 case EMLXS_ERROR:
224 msg2 = &emlxs_error_msg;
225 break;
226
227 case EMLXS_PANIC:
228 msg2 = &emlxs_panic_msg;
229 break;
193 case EMLXS_NOTICE:
194 msg2 = &emlxs_notice_msg;
195 break;
196
197 case EMLXS_WARNING:
198 msg2 = &emlxs_warning_msg;
199 break;
200
201 case EMLXS_ERROR:
202 msg2 = &emlxs_error_msg;
203 break;
204
205 case EMLXS_PANIC:
206 msg2 = &emlxs_panic_msg;
207 break;
208
209 case EMLXS_DEBUG:
210 default:
211 msg2 = &emlxs_debug_msg;
212 break;
230 }
231
232 /* Initialize */
233 entry2->id = log->count++;
234 entry2->fileno = entry->fileno;
235 entry2->line = entry->line;
236 entry2->msg = msg2;
237 entry2->instance = log->instance;
238 entry2->vpi = port->vpi;
239
240 /* Save the additional info buffer */
213 }
214
215 /* Initialize */
216 entry2->id = log->count++;
217 entry2->fileno = entry->fileno;
218 entry2->line = entry->line;
219 entry2->msg = msg2;
220 entry2->instance = log->instance;
221 entry2->vpi = port->vpi;
222
223 /* Save the additional info buffer */
241 (void) sprintf(entry2->buffer,
224 (void) snprintf(entry2->buffer, MAX_LOG_INFO_LENGTH,
242 "Last message repeated %d time(s).",
243 log->repeat);
244
245 /* Set the entry time stamp */
246 (void) drv_getparm(LBOLT, &time);
247 entry2->time = time - log->start_time;
248
249 gethrestime(&entry2->id_time);

--- 150 unchanged lines hidden (view full) ---

400 int32_t cmn_level;
401 uint32_t rval;
402 char driver[32];
403
404 va_str[0] = 0;
405
406 if (fmt) {
407 va_start(valist, fmt);
225 "Last message repeated %d time(s).",
226 log->repeat);
227
228 /* Set the entry time stamp */
229 (void) drv_getparm(LBOLT, &time);
230 entry2->time = time - log->start_time;
231
232 gethrestime(&entry2->id_time);

--- 150 unchanged lines hidden (view full) ---

383 int32_t cmn_level;
384 uint32_t rval;
385 char driver[32];
386
387 va_str[0] = 0;
388
389 if (fmt) {
390 va_start(valist, fmt);
408 (void) vsprintf(va_str, fmt, valist);
391 (void) vsnprintf(va_str, sizeof (va_str), fmt, valist);
409 va_end(valist);
410 }
411
412#ifdef FMA_SUPPORT
413 if (msg->fm_ereport_code) {
414 emlxs_fm_ereport(hba, msg->fm_ereport_code);
415 }
416

--- 37 unchanged lines hidden (view full) ---

454 break;
455
456 default:
457 level = "UNKNOWN";
458 break;
459 }
460
461 if (port->vpi == 0) {
392 va_end(valist);
393 }
394
395#ifdef FMA_SUPPORT
396 if (msg->fm_ereport_code) {
397 emlxs_fm_ereport(hba, msg->fm_ereport_code);
398 }
399

--- 37 unchanged lines hidden (view full) ---

437 break;
438
439 default:
440 level = "UNKNOWN";
441 break;
442 }
443
444 if (port->vpi == 0) {
462 (void) sprintf(driver, "%s%d", DRIVER_NAME,
463 hba->ddiinst);
445 (void) snprintf(driver, sizeof (driver), "%s%d",
446 DRIVER_NAME, hba->ddiinst);
464 } else {
447 } else {
465 (void) sprintf(driver, "%s%d.%d", DRIVER_NAME,
466 hba->ddiinst, port->vpi);
448 (void) snprintf(driver, sizeof (driver), "%s%d.%d",
449 DRIVER_NAME, hba->ddiinst, port->vpi);
467 }
468
469 /* Generate the message string */
470 if (msg->buffer[0] != 0) {
471 if (va_str[0] != 0) {
450 }
451
452 /* Generate the message string */
453 if (msg->buffer[0] != 0) {
454 if (va_str[0] != 0) {
472 (void) sprintf(msg_str,
455 (void) snprintf(msg_str, sizeof (msg_str),
473 "[%2X.%04X]%s:%7s:%4d: %s (%s)\n", fileno,
474 line, driver, level, msg->id, msg->buffer,
475 va_str);
476 } else {
456 "[%2X.%04X]%s:%7s:%4d: %s (%s)\n", fileno,
457 line, driver, level, msg->id, msg->buffer,
458 va_str);
459 } else {
477 (void) sprintf(msg_str,
460 (void) snprintf(msg_str, sizeof (msg_str),
478 "[%2X.%04X]%s:%7s:%4d: %s\n",
479 fileno, line, driver, level, msg->id,
480 msg->buffer);
481 }
482 } else {
483 if (va_str[0] != 0) {
461 "[%2X.%04X]%s:%7s:%4d: %s\n",
462 fileno, line, driver, level, msg->id,
463 msg->buffer);
464 }
465 } else {
466 if (va_str[0] != 0) {
484 (void) sprintf(msg_str,
467 (void) snprintf(msg_str, sizeof (msg_str),
485 "[%2X.%04X]%s:%7s:%4d: (%s)\n", fileno,
486 line, driver, level, msg->id, va_str);
487 } else {
468 "[%2X.%04X]%s:%7s:%4d: (%s)\n", fileno,
469 line, driver, level, msg->id, va_str);
470 } else {
488 (void) sprintf(msg_str,
471 (void) snprintf(msg_str, sizeof (msg_str),
489 "[%2X.%04X]%s:%7s:%4d\n",
490 fileno, line, driver, level, msg->id);
491 }
492 }
493
494 switch (rval) {
495 case 1: /* MESSAGE LOG ONLY */
496 /* Message log & console, if system booted in */

--- 158 unchanged lines hidden (view full) ---

655 break;
656
657 default:
658 level = "UNKNOWN";
659 break;
660 }
661
662 if (entry->vpi == 0) {
472 "[%2X.%04X]%s:%7s:%4d\n",
473 fileno, line, driver, level, msg->id);
474 }
475 }
476
477 switch (rval) {
478 case 1: /* MESSAGE LOG ONLY */
479 /* Message log & console, if system booted in */

--- 158 unchanged lines hidden (view full) ---

638 break;
639
640 default:
641 level = "UNKNOWN";
642 break;
643 }
644
645 if (entry->vpi == 0) {
663 (void) sprintf(driver, "%s%d", DRIVER_NAME, entry->instance);
646 (void) snprintf(driver, sizeof (driver), "%s%d", DRIVER_NAME,
647 entry->instance);
664 } else {
648 } else {
665 (void) sprintf(driver, "%s%d.%d", DRIVER_NAME, entry->instance,
666 entry->vpi);
649 (void) snprintf(driver, sizeof (driver), "%s%d.%d", DRIVER_NAME,
650 entry->instance, entry->vpi);
667 }
668
669 /* Generate the message string */
670 if (msg->buffer[0] != 0) {
671 if (entry->buffer[0] != 0) {
651 }
652
653 /* Generate the message string */
654 if (msg->buffer[0] != 0) {
655 if (entry->buffer[0] != 0) {
672 (void) sprintf(buf,
656 (void) snprintf(buf, sizeof (buf),
673 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: %s (%s)\n",
674 secs, hsecs, entry->id, entry->fileno,
675 entry->line, driver, level, msg->id, msg->buffer,
676 entry->buffer);
677
678 } else {
657 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: %s (%s)\n",
658 secs, hsecs, entry->id, entry->fileno,
659 entry->line, driver, level, msg->id, msg->buffer,
660 entry->buffer);
661
662 } else {
679 (void) sprintf(buf,
663 (void) snprintf(buf, sizeof (buf),
680 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: %s\n", secs,
681 hsecs, entry->id, entry->fileno, entry->line,
682 driver, level, msg->id, msg->buffer);
683 }
684 } else {
685 if (entry->buffer[0] != 0) {
664 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: %s\n", secs,
665 hsecs, entry->id, entry->fileno, entry->line,
666 driver, level, msg->id, msg->buffer);
667 }
668 } else {
669 if (entry->buffer[0] != 0) {
686 (void) sprintf(buf,
670 (void) snprintf(buf, sizeof (buf),
687 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: (%s)\n",
688 secs, hsecs, entry->id, entry->fileno,
689 entry->line, driver, level, msg->id,
690 entry->buffer);
691 } else {
671 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d: (%s)\n",
672 secs, hsecs, entry->id, entry->fileno,
673 entry->line, driver, level, msg->id,
674 entry->buffer);
675 } else {
692 (void) sprintf(buf,
676 (void) snprintf(buf, sizeof (buf),
693 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d\n",
694 secs, hsecs, entry->id, entry->fileno,
695 entry->line, driver, level, msg->id);
696 }
697 }
698
699 bzero(buffer, MAX_LOG_MSG_LENGTH);
700 buflen = strlen(buf);
701
702 if (buflen > (MAX_LOG_MSG_LENGTH - 1)) {
703 (void) strncpy(buffer, buf, (MAX_LOG_MSG_LENGTH - 2));
704 buffer[MAX_LOG_MSG_LENGTH - 2] = '\n';
705 } else {
706 (void) strncpy(buffer, buf, buflen);
707 }
708
709 return;
710
711} /* emlxs_msg_sprintf() */
677 "%8d.%02d: %6d:[%2X.%04X]%s:%7s:%4d\n",
678 secs, hsecs, entry->id, entry->fileno,
679 entry->line, driver, level, msg->id);
680 }
681 }
682
683 bzero(buffer, MAX_LOG_MSG_LENGTH);
684 buflen = strlen(buf);
685
686 if (buflen > (MAX_LOG_MSG_LENGTH - 1)) {
687 (void) strncpy(buffer, buf, (MAX_LOG_MSG_LENGTH - 2));
688 buffer[MAX_LOG_MSG_LENGTH - 2] = '\n';
689 } else {
690 (void) strncpy(buffer, buf, buflen);
691 }
692
693 return;
694
695} /* emlxs_msg_sprintf() */