xref: /titanic_50/usr/src/uts/common/io/e1000g/e1000g_debug.c (revision 532877c46d04a2d0b254f9b5797720078adcea07)
1 /*
2  * This file is provided under a CDDLv1 license.  When using or
3  * redistributing this file, you may do so under this license.
4  * In redistributing this file this license must be included
5  * and no other modification of this header file is permitted.
6  *
7  * CDDL LICENSE SUMMARY
8  *
9  * Copyright(c) 1999 - 2007 Intel Corporation. All rights reserved.
10  *
11  * The contents of this file are subject to the terms of Version
12  * 1.0 of the Common Development and Distribution License (the "License").
13  *
14  * You should have received a copy of the License with this software.
15  * You can obtain a copy of the License at
16  *	http://www.opensolaris.org/os/licensing.
17  * See the License for the specific language governing permissions
18  * and limitations under the License.
19  */
20 
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms of the CDDLv1.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * **********************************************************************
30  *									*
31  * Module Name:								*
32  *   e1000g_debug.c							*
33  *									*
34  * Abstract:								*
35  *									*
36  *   This driver runs on the following hardware:			*
37  *   - Wiseman based PCI gigabit ethernet adapters			*
38  *									*
39  * Environment:								*
40  *   Kernel Mode -							*
41  *									*
42  * **********************************************************************
43  */
44 #ifdef GCC
45 #ifdef __STDC__
46 #include <stdarg.h>
47 #else
48 #include <varargs.h>
49 #endif
50 #define	_SYS_VARARGS_H
51 #endif
52 
53 #include "e1000g_sw.h"
54 #include "e1000g_debug.h"
55 
56 void
57 e1000g_log(struct e1000g *Adapter, int level, char *fmt, ...)
58 {
59 	auto char name[NAMELEN];
60 	auto char buf[BUFSZ];
61 	va_list ap;
62 
63 	if (Adapter != NULL) {
64 		(void) sprintf(name, "%s - e1000g[%d] ",
65 		    ddi_get_name(Adapter->dip), ddi_get_instance(Adapter->dip));
66 	} else {
67 		(void) sprintf(name, "e1000g");
68 	}
69 #ifdef GCC
70 	/*
71 	 * va_start uses built in macro __builtin_va_alist from the
72 	 * compiler libs which requires compiler system to have
73 	 * __BUILTIN_VA_ARG_INCR defined.
74 	 */
75 	/*
76 	 * Many compilation systems depend upon the use of special functions
77 	 * built into the the compilation system to handle variable argument
78 	 * lists and stack allocations.  The method to obtain this in SunOS
79 	 * is to define the feature test macro "__BUILTIN_VA_ARG_INCR" which
80 	 * enables the following special built-in functions:
81 	 *	__builtin_alloca
82 	 *	__builtin_va_alist
83 	 *	__builtin_va_arg_incr
84 	 * It is intended that the compilation system define this feature test
85 	 * macro, not the user of the system.
86 	 *
87 	 * The tests on the processor type are to provide a transitional period
88 	 * for existing compilation systems, and may be removed in a future
89 	 * release.
90 	 */
91 	/*
92 	 * Using GNU gcc compiler it doesn't expand to va_start....
93 	 */
94 	va_start(ap, fmt);
95 #else
96 	va_start(ap, fmt);
97 #endif	/* GCC */
98 	(void) vsprintf(buf, fmt, ap);
99 	va_end(ap);
100 
101 	switch (level) {
102 	case CE_CONT:
103 	case CE_NOTE:
104 	case CE_WARN:
105 	case CE_PANIC:
106 		if (e1000g_display_only == 1 && e1000g_print_only == 1) {
107 			cmn_err(level, "%s: %s", name, buf);
108 			break;
109 		}
110 		if (e1000g_display_only == 1) {
111 			cmn_err(level, "^%s: %s", name, buf);
112 			break;
113 		}
114 		if (e1000g_print_only == 1) {
115 			cmn_err(level, "!%s: %s", name, buf);
116 			break;
117 		}
118 		/*
119 		 * if they are not set properly then do both
120 		 */
121 		cmn_err(level, "%s: %s", name, buf);
122 		break;
123 
124 #ifdef e1000g_DEBUG
125 	case e1000g_DDI_LEVEL:	/* 256 or 0x100 */
126 		if (e1000g_debug != e1000g_DDI_LEVEL)
127 			break;
128 
129 	case e1000g_INT_LEVEL:	/* 128 or 0x080 */
130 		if ((e1000g_debug != e1000g_INT_LEVEL) &&
131 		    (e1000g_debug < e1000g_INT_LEVEL))
132 			break;
133 
134 	case e1000g_SEND_LEVEL:	/* 64 or 0x040 */
135 		if ((e1000g_debug != e1000g_SEND_LEVEL) &&
136 		    (e1000g_debug < e1000g_SEND_LEVEL))
137 			break;
138 
139 	case e1000g_RECV_LEVEL:	/* 32 or 0x020 */
140 		if ((e1000g_debug != e1000g_RECV_LEVEL) &&
141 		    (e1000g_debug < e1000g_RECV_LEVEL))
142 			break;
143 
144 	case e1000g_CALLTRACE_LEVEL:	/* 8 or 0x008 */
145 		if ((e1000g_debug != e1000g_CALLTRACE_LEVEL) &&
146 		    (e1000g_debug < e1000g_CALLTRACE_LEVEL))
147 			break;
148 
149 	case e1000g_INFO_LEVEL:	/* 4 or 0x004 */
150 		if ((e1000g_debug != e1000g_INFO_LEVEL) &&
151 		    (e1000g_debug < e1000g_INFO_LEVEL))
152 			break;
153 
154 	case e1000g_VERBOSE_LEVEL:	/* 16 or 0x010 */
155 #endif
156 	default:
157 		if (e1000g_display_only == 1 && e1000g_print_only == 1) {
158 			cmn_err(CE_CONT, "%s:\t%s", name, buf);
159 			break;
160 		}
161 
162 		if (e1000g_display_only == 1) {
163 			cmn_err(CE_CONT, "^%s:\t%s", name, buf);
164 			break;
165 		}
166 
167 		if (e1000g_print_only == 1) {
168 			cmn_err(CE_CONT, "!%s:\t%s", name, buf);
169 			break;
170 		}
171 
172 		/*
173 		 * if they are not set properly then do both
174 		 */
175 		cmn_err(CE_CONT, "%s:\t%s", name, buf);
176 		break;
177 	}
178 }
179 
180 void
181 e1000g_log_hw(char *msg, void *cptr, int length)
182 {
183 	int i = 0, j;
184 	char buf[BUFSZ];
185 	char *cp = cptr;
186 
187 	bzero(buf, BUFSZ);
188 	for (i = 0; i < length; i++) {
189 		/*
190 		 * make sure there is room for longest %x (i.e. 8 for a
191 		 * negative number) plus space (1) plus zero (1)
192 		 */
193 		if ((j = strlen(buf)) >= (BUFSZ - 10)) {
194 			buf[BUFSZ - 2] = '>';
195 			buf[BUFSZ - 1] = 0;
196 			break;
197 		}
198 
199 		(void) sprintf(&buf[j], "%x ", cp[i]);
200 	}
201 	cmn_err(CE_CONT, "^%s: %s\n", msg, buf);
202 }
203