xref: /onnv-gate/usr/src/uts/common/io/e1000g/e1000g_debug.c (revision 4919:b6b235c6e23b)
13526Sxy150489 /*
23526Sxy150489  * This file is provided under a CDDLv1 license.  When using or
33526Sxy150489  * redistributing this file, you may do so under this license.
43526Sxy150489  * In redistributing this file this license must be included
53526Sxy150489  * and no other modification of this header file is permitted.
63526Sxy150489  *
73526Sxy150489  * CDDL LICENSE SUMMARY
83526Sxy150489  *
93526Sxy150489  * Copyright(c) 1999 - 2007 Intel Corporation. All rights reserved.
103526Sxy150489  *
113526Sxy150489  * The contents of this file are subject to the terms of Version
123526Sxy150489  * 1.0 of the Common Development and Distribution License (the "License").
133526Sxy150489  *
143526Sxy150489  * You should have received a copy of the License with this software.
153526Sxy150489  * You can obtain a copy of the License at
163526Sxy150489  *	http://www.opensolaris.org/os/licensing.
173526Sxy150489  * See the License for the specific language governing permissions
183526Sxy150489  * and limitations under the License.
193526Sxy150489  */
203526Sxy150489 
213526Sxy150489 /*
223526Sxy150489  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
233526Sxy150489  * Use is subject to license terms of the CDDLv1.
243526Sxy150489  */
253526Sxy150489 
263526Sxy150489 #pragma ident	"%Z%%M%	%I%	%E% SMI"
273526Sxy150489 
283526Sxy150489 /*
293526Sxy150489  * **********************************************************************
303526Sxy150489  *									*
313526Sxy150489  * Module Name:								*
32*4919Sxy150489  * 	e1000g_debug.c							*
333526Sxy150489  *									*
343526Sxy150489  * Abstract:								*
35*4919Sxy150489  *	This module includes the debug routines				*
363526Sxy150489  *									*
373526Sxy150489  * **********************************************************************
383526Sxy150489  */
393526Sxy150489 #ifdef GCC
403526Sxy150489 #ifdef __STDC__
413526Sxy150489 #include <stdarg.h>
423526Sxy150489 #else
433526Sxy150489 #include <varargs.h>
443526Sxy150489 #endif
453526Sxy150489 #define	_SYS_VARARGS_H
463526Sxy150489 #endif
473526Sxy150489 
48*4919Sxy150489 #include "e1000g_debug.h"
493526Sxy150489 #include "e1000g_sw.h"
50*4919Sxy150489 
51*4919Sxy150489 #ifdef E1000G_DEBUG
52*4919Sxy150489 int e1000g_debug = E1000G_WARN_LEVEL;
53*4919Sxy150489 #endif
54*4919Sxy150489 int e1000g_log_mode = E1000G_LOG_PRINT;
553526Sxy150489 
563526Sxy150489 void
57*4919Sxy150489 e1000g_log(void *instance, int level, char *fmt, ...)
583526Sxy150489 {
59*4919Sxy150489 	struct e1000g *Adapter = (struct e1000g *)instance;
603526Sxy150489 	auto char name[NAMELEN];
613526Sxy150489 	auto char buf[BUFSZ];
623526Sxy150489 	va_list ap;
633526Sxy150489 
64*4919Sxy150489 	switch (level) {
65*4919Sxy150489 #ifdef E1000G_DEBUG
66*4919Sxy150489 	case E1000G_VERBOSE_LEVEL:	/* 16 or 0x010 */
67*4919Sxy150489 		if (e1000g_debug < E1000G_VERBOSE_LEVEL)
68*4919Sxy150489 			return;
69*4919Sxy150489 		level = CE_CONT;
70*4919Sxy150489 		break;
71*4919Sxy150489 
72*4919Sxy150489 	case E1000G_TRACE_LEVEL:	/* 8 or 0x008 */
73*4919Sxy150489 		if (e1000g_debug < E1000G_TRACE_LEVEL)
74*4919Sxy150489 			return;
75*4919Sxy150489 		level = CE_CONT;
76*4919Sxy150489 		break;
77*4919Sxy150489 
78*4919Sxy150489 	case E1000G_INFO_LEVEL:		/* 4 or 0x004 */
79*4919Sxy150489 		if (e1000g_debug < E1000G_INFO_LEVEL)
80*4919Sxy150489 			return;
81*4919Sxy150489 		level = CE_CONT;
82*4919Sxy150489 		break;
83*4919Sxy150489 
84*4919Sxy150489 	case E1000G_WARN_LEVEL:		/* 2 or 0x002 */
85*4919Sxy150489 		if (e1000g_debug < E1000G_WARN_LEVEL)
86*4919Sxy150489 			return;
87*4919Sxy150489 		level = CE_CONT;
88*4919Sxy150489 		break;
89*4919Sxy150489 
90*4919Sxy150489 	case E1000G_ERRS_LEVEL:		/* 1 or 0x001 */
91*4919Sxy150489 		level = CE_CONT;
92*4919Sxy150489 		break;
93*4919Sxy150489 #else
94*4919Sxy150489 	case CE_CONT:
95*4919Sxy150489 	case CE_NOTE:
96*4919Sxy150489 	case CE_WARN:
97*4919Sxy150489 	case CE_PANIC:
98*4919Sxy150489 		break;
99*4919Sxy150489 #endif
100*4919Sxy150489 	default:
101*4919Sxy150489 		level = CE_CONT;
102*4919Sxy150489 		break;
103*4919Sxy150489 	}
104*4919Sxy150489 
1053526Sxy150489 	if (Adapter != NULL) {
1063526Sxy150489 		(void) sprintf(name, "%s - e1000g[%d] ",
1073526Sxy150489 		    ddi_get_name(Adapter->dip), ddi_get_instance(Adapter->dip));
1083526Sxy150489 	} else {
1093526Sxy150489 		(void) sprintf(name, "e1000g");
1103526Sxy150489 	}
1113526Sxy150489 	/*
1123526Sxy150489 	 * va_start uses built in macro __builtin_va_alist from the
1133526Sxy150489 	 * compiler libs which requires compiler system to have
1143526Sxy150489 	 * __BUILTIN_VA_ARG_INCR defined.
1153526Sxy150489 	 */
1163526Sxy150489 	/*
1173526Sxy150489 	 * Many compilation systems depend upon the use of special functions
1183526Sxy150489 	 * built into the the compilation system to handle variable argument
1193526Sxy150489 	 * lists and stack allocations.  The method to obtain this in SunOS
1203526Sxy150489 	 * is to define the feature test macro "__BUILTIN_VA_ARG_INCR" which
1213526Sxy150489 	 * enables the following special built-in functions:
1223526Sxy150489 	 *	__builtin_alloca
1233526Sxy150489 	 *	__builtin_va_alist
1243526Sxy150489 	 *	__builtin_va_arg_incr
1253526Sxy150489 	 * It is intended that the compilation system define this feature test
1263526Sxy150489 	 * macro, not the user of the system.
1273526Sxy150489 	 *
1283526Sxy150489 	 * The tests on the processor type are to provide a transitional period
1293526Sxy150489 	 * for existing compilation systems, and may be removed in a future
1303526Sxy150489 	 * release.
1313526Sxy150489 	 */
1323526Sxy150489 	/*
1333526Sxy150489 	 * Using GNU gcc compiler it doesn't expand to va_start....
1343526Sxy150489 	 */
1353526Sxy150489 	va_start(ap, fmt);
1363526Sxy150489 	(void) vsprintf(buf, fmt, ap);
1373526Sxy150489 	va_end(ap);
1383526Sxy150489 
139*4919Sxy150489 	if ((e1000g_log_mode & E1000G_LOG_ALL) == E1000G_LOG_ALL)
1403526Sxy150489 		cmn_err(level, "%s: %s", name, buf);
141*4919Sxy150489 	else if (e1000g_log_mode & E1000G_LOG_DISPLAY)
142*4919Sxy150489 		cmn_err(level, "^%s: %s", name, buf);
143*4919Sxy150489 	else if (e1000g_log_mode & E1000G_LOG_PRINT)
144*4919Sxy150489 		cmn_err(level, "!%s: %s", name, buf);
145*4919Sxy150489 	else /* if they are not set properly then do both */
146*4919Sxy150489 		cmn_err(level, "%s: %s", name, buf);
1473526Sxy150489 }
148