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