xref: /illumos-gate/usr/src/uts/common/io/igb/igb_log.c (revision 6e6545bfaed3bab9ce836ee82d1abd8f2edba89a)
1 /*
2  * CDDL HEADER START
3  *
4  * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at:
10  *	http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When using or redistributing this file, you may do so under the
15  * License only. No other modification of this header is permitted.
16  *
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 
24 /*
25  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms of the CDDL.
27  */
28 
29 #include "igb_sw.h"
30 
31 #define	LOG_BUF_LEN	1024
32 
33 extern int igb_debug;
34 
35 void
36 igb_log(void *arg, igb_debug_t level, const char *fmt, ...)
37 {
38 	igb_t *igbp = (igb_t *)arg;
39 	char buf[LOG_BUF_LEN];
40 	int celevel;
41 	va_list ap;
42 
43 	va_start(ap, fmt);
44 	(void) vsnprintf(buf, sizeof (buf), fmt, ap);
45 	va_end(ap);
46 
47 	DTRACE_PROBE2(igb__log, igb_t *, igbp, const char *, buf);
48 
49 	if (level > igb_debug)
50 		return;
51 
52 	switch (level) {
53 	case IGB_LOG_ERROR:
54 		celevel = CE_WARN;
55 		break;
56 	case IGB_LOG_INFO:
57 		celevel = CE_NOTE;
58 		break;
59 	case IGB_LOG_TRACE:
60 		celevel = CE_CONT;
61 		break;
62 	default:
63 		celevel = CE_IGNORE;
64 	}
65 
66 	if (igbp != NULL)
67 		dev_err(igbp->dip, celevel, "!%s", buf);
68 	else
69 		cmn_err(celevel, "!%s", buf);
70 }
71