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 * This module includes the debug routines * 36 * * 37 * ********************************************************************** 38 */ 39 #ifdef GCC 40 #ifdef __STDC__ 41 #include <stdarg.h> 42 #else 43 #include <varargs.h> 44 #endif 45 #define _SYS_VARARGS_H 46 #endif 47 48 #include "e1000g_debug.h" 49 #include "e1000g_sw.h" 50 51 #ifdef E1000G_DEBUG 52 int e1000g_debug = E1000G_WARN_LEVEL; 53 #endif 54 int e1000g_log_mode = E1000G_LOG_PRINT; 55 56 void 57 e1000g_log(void *instance, int level, char *fmt, ...) 58 { 59 struct e1000g *Adapter = (struct e1000g *)instance; 60 auto char name[NAMELEN]; 61 auto char buf[BUFSZ]; 62 va_list ap; 63 64 switch (level) { 65 #ifdef E1000G_DEBUG 66 case E1000G_VERBOSE_LEVEL: /* 16 or 0x010 */ 67 if (e1000g_debug < E1000G_VERBOSE_LEVEL) 68 return; 69 level = CE_CONT; 70 break; 71 72 case E1000G_TRACE_LEVEL: /* 8 or 0x008 */ 73 if (e1000g_debug < E1000G_TRACE_LEVEL) 74 return; 75 level = CE_CONT; 76 break; 77 78 case E1000G_INFO_LEVEL: /* 4 or 0x004 */ 79 if (e1000g_debug < E1000G_INFO_LEVEL) 80 return; 81 level = CE_CONT; 82 break; 83 84 case E1000G_WARN_LEVEL: /* 2 or 0x002 */ 85 if (e1000g_debug < E1000G_WARN_LEVEL) 86 return; 87 level = CE_CONT; 88 break; 89 90 case E1000G_ERRS_LEVEL: /* 1 or 0x001 */ 91 level = CE_CONT; 92 break; 93 #else 94 case CE_CONT: 95 case CE_NOTE: 96 case CE_WARN: 97 case CE_PANIC: 98 break; 99 #endif 100 default: 101 level = CE_CONT; 102 break; 103 } 104 105 if (Adapter != NULL) { 106 (void) sprintf(name, "%s - e1000g[%d] ", 107 ddi_get_name(Adapter->dip), ddi_get_instance(Adapter->dip)); 108 } else { 109 (void) sprintf(name, "e1000g"); 110 } 111 /* 112 * va_start uses built in macro __builtin_va_alist from the 113 * compiler libs which requires compiler system to have 114 * __BUILTIN_VA_ARG_INCR defined. 115 */ 116 /* 117 * Many compilation systems depend upon the use of special functions 118 * built into the the compilation system to handle variable argument 119 * lists and stack allocations. The method to obtain this in SunOS 120 * is to define the feature test macro "__BUILTIN_VA_ARG_INCR" which 121 * enables the following special built-in functions: 122 * __builtin_alloca 123 * __builtin_va_alist 124 * __builtin_va_arg_incr 125 * It is intended that the compilation system define this feature test 126 * macro, not the user of the system. 127 * 128 * The tests on the processor type are to provide a transitional period 129 * for existing compilation systems, and may be removed in a future 130 * release. 131 */ 132 /* 133 * Using GNU gcc compiler it doesn't expand to va_start.... 134 */ 135 va_start(ap, fmt); 136 (void) vsprintf(buf, fmt, ap); 137 va_end(ap); 138 139 if ((e1000g_log_mode & E1000G_LOG_ALL) == E1000G_LOG_ALL) 140 cmn_err(level, "%s: %s", name, buf); 141 else if (e1000g_log_mode & E1000G_LOG_DISPLAY) 142 cmn_err(level, "^%s: %s", name, buf); 143 else if (e1000g_log_mode & E1000G_LOG_PRINT) 144 cmn_err(level, "!%s: %s", name, buf); 145 else /* if they are not set properly then do both */ 146 cmn_err(level, "%s: %s", name, buf); 147 } 148