1*5181Sgd78059 /* 2*5181Sgd78059 * CDDL HEADER START 3*5181Sgd78059 * 4*5181Sgd78059 * The contents of this file are subject to the terms of the 5*5181Sgd78059 * Common Development and Distribution License (the "License"). 6*5181Sgd78059 * You may not use this file except in compliance with the License. 7*5181Sgd78059 * 8*5181Sgd78059 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5181Sgd78059 * or http://www.opensolaris.org/os/licensing. 10*5181Sgd78059 * See the License for the specific language governing permissions 11*5181Sgd78059 * and limitations under the License. 12*5181Sgd78059 * 13*5181Sgd78059 * When distributing Covered Code, include this CDDL HEADER in each 14*5181Sgd78059 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5181Sgd78059 * If applicable, add the following below this CDDL HEADER, with the 16*5181Sgd78059 * fields enclosed by brackets "[]" replaced with your own identifying 17*5181Sgd78059 * information: Portions Copyright [yyyy] [name of copyright owner] 18*5181Sgd78059 * 19*5181Sgd78059 * CDDL HEADER END 20*5181Sgd78059 */ 21*5181Sgd78059 /* 22*5181Sgd78059 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23*5181Sgd78059 * Use is subject to license terms. 24*5181Sgd78059 */ 25*5181Sgd78059 26*5181Sgd78059 #pragma ident "%Z%%M% %I% %E% SMI" 27*5181Sgd78059 28*5181Sgd78059 #include "dmfe_impl.h" 29*5181Sgd78059 30*5181Sgd78059 31*5181Sgd78059 /* 32*5181Sgd78059 * Debug flags 33*5181Sgd78059 */ 34*5181Sgd78059 35*5181Sgd78059 #if DMFEDEBUG 36*5181Sgd78059 uint32_t dmfe_debug = 0; 37*5181Sgd78059 #endif /* DMFEDEBUG */ 38*5181Sgd78059 39*5181Sgd78059 40*5181Sgd78059 /* 41*5181Sgd78059 * ========== Message printing & debug routines ========== 42*5181Sgd78059 */ 43*5181Sgd78059 44*5181Sgd78059 static struct { 45*5181Sgd78059 kmutex_t mutex[1]; 46*5181Sgd78059 const char *ifname; 47*5181Sgd78059 const char *fmt; 48*5181Sgd78059 int level; 49*5181Sgd78059 } prtdata; 50*5181Sgd78059 51*5181Sgd78059 void 52*5181Sgd78059 dmfe_log_init() 53*5181Sgd78059 { 54*5181Sgd78059 mutex_init(prtdata.mutex, NULL, MUTEX_DRIVER, NULL); 55*5181Sgd78059 } 56*5181Sgd78059 57*5181Sgd78059 void 58*5181Sgd78059 dmfe_log_fini() 59*5181Sgd78059 { 60*5181Sgd78059 mutex_destroy(prtdata.mutex); 61*5181Sgd78059 } 62*5181Sgd78059 63*5181Sgd78059 /* 64*5181Sgd78059 * Backend print routine for all the routines below 65*5181Sgd78059 */ 66*5181Sgd78059 static void 67*5181Sgd78059 dmfe_vprt(const char *fmt, va_list args) 68*5181Sgd78059 { 69*5181Sgd78059 char buf[128]; 70*5181Sgd78059 71*5181Sgd78059 ASSERT(mutex_owned(prtdata.mutex)); 72*5181Sgd78059 73*5181Sgd78059 (void) vsnprintf(buf, sizeof (buf), fmt, args); 74*5181Sgd78059 cmn_err(prtdata.level, prtdata.fmt, prtdata.ifname, buf); 75*5181Sgd78059 } 76*5181Sgd78059 77*5181Sgd78059 #if DMFEDEBUG 78*5181Sgd78059 79*5181Sgd78059 static void 80*5181Sgd78059 dmfe_prt(const char *fmt, ...) 81*5181Sgd78059 { 82*5181Sgd78059 va_list args; 83*5181Sgd78059 84*5181Sgd78059 ASSERT(mutex_owned(prtdata.mutex)); 85*5181Sgd78059 86*5181Sgd78059 va_start(args, fmt); 87*5181Sgd78059 dmfe_vprt(fmt, args); 88*5181Sgd78059 va_end(args); 89*5181Sgd78059 90*5181Sgd78059 mutex_exit(prtdata.mutex); 91*5181Sgd78059 } 92*5181Sgd78059 93*5181Sgd78059 void 94*5181Sgd78059 (*dmfe_db(dmfe_t *dmfep))(const char *fmt, ...) 95*5181Sgd78059 { 96*5181Sgd78059 mutex_enter(prtdata.mutex); 97*5181Sgd78059 prtdata.ifname = dmfep->ifname; 98*5181Sgd78059 prtdata.fmt = "^%s: %s\n"; 99*5181Sgd78059 prtdata.level = CE_CONT; 100*5181Sgd78059 101*5181Sgd78059 return (dmfe_prt); 102*5181Sgd78059 } 103*5181Sgd78059 104*5181Sgd78059 void 105*5181Sgd78059 (*dmfe_gdb())(const char *fmt, ...) 106*5181Sgd78059 { 107*5181Sgd78059 mutex_enter(prtdata.mutex); 108*5181Sgd78059 prtdata.ifname = "dmfe"; 109*5181Sgd78059 prtdata.fmt = "^%s: %s\n"; 110*5181Sgd78059 prtdata.level = CE_CONT; 111*5181Sgd78059 112*5181Sgd78059 return (dmfe_prt); 113*5181Sgd78059 } 114*5181Sgd78059 115*5181Sgd78059 #endif /* DMFEDEBUG */ 116*5181Sgd78059 117*5181Sgd78059 /* 118*5181Sgd78059 * Report a run-time error (CE_WARN, to console & log) 119*5181Sgd78059 * Also logs all the chip's operating registers 120*5181Sgd78059 */ 121*5181Sgd78059 void 122*5181Sgd78059 dmfe_warning(dmfe_t *dmfep, const char *fmt, ...) 123*5181Sgd78059 { 124*5181Sgd78059 va_list args; 125*5181Sgd78059 uint32_t reg; 126*5181Sgd78059 int i; 127*5181Sgd78059 128*5181Sgd78059 mutex_enter(prtdata.mutex); 129*5181Sgd78059 prtdata.ifname = dmfep->ifname; 130*5181Sgd78059 prtdata.fmt = "%s: %s"; 131*5181Sgd78059 prtdata.level = CE_WARN; 132*5181Sgd78059 133*5181Sgd78059 va_start(args, fmt); 134*5181Sgd78059 dmfe_vprt(fmt, args); 135*5181Sgd78059 va_end(args); 136*5181Sgd78059 137*5181Sgd78059 /* 138*5181Sgd78059 * Record all the chip registers in the logfile 139*5181Sgd78059 */ 140*5181Sgd78059 for (i = 0; i < 16; ++i) { 141*5181Sgd78059 reg = dmfe_chip_get32(dmfep, 8*i); 142*5181Sgd78059 cmn_err(CE_NOTE, "!%s: CR%d\t%08x", dmfep->ifname, i, reg); 143*5181Sgd78059 } 144*5181Sgd78059 145*5181Sgd78059 mutex_exit(prtdata.mutex); 146*5181Sgd78059 } 147*5181Sgd78059 148*5181Sgd78059 /* 149*5181Sgd78059 * Log a programming error (CE_WARN, log only) 150*5181Sgd78059 */ 151*5181Sgd78059 void 152*5181Sgd78059 dmfe_error(dmfe_t *dmfep, const char *fmt, ...) 153*5181Sgd78059 { 154*5181Sgd78059 va_list args; 155*5181Sgd78059 156*5181Sgd78059 mutex_enter(prtdata.mutex); 157*5181Sgd78059 prtdata.ifname = dmfep->ifname; 158*5181Sgd78059 prtdata.fmt = "!%s: %s"; 159*5181Sgd78059 prtdata.level = CE_WARN; 160*5181Sgd78059 161*5181Sgd78059 va_start(args, fmt); 162*5181Sgd78059 dmfe_vprt(fmt, args); 163*5181Sgd78059 va_end(args); 164*5181Sgd78059 165*5181Sgd78059 mutex_exit(prtdata.mutex); 166*5181Sgd78059 } 167*5181Sgd78059 168*5181Sgd78059 /* 169*5181Sgd78059 * Report a run-time event (CE_NOTE, to console & log) 170*5181Sgd78059 */ 171*5181Sgd78059 void 172*5181Sgd78059 dmfe_notice(dmfe_t *dmfep, const char *fmt, ...) 173*5181Sgd78059 { 174*5181Sgd78059 va_list args; 175*5181Sgd78059 176*5181Sgd78059 mutex_enter(prtdata.mutex); 177*5181Sgd78059 prtdata.ifname = dmfep->ifname; 178*5181Sgd78059 prtdata.fmt = "%s: %s"; 179*5181Sgd78059 prtdata.level = CE_NOTE; 180*5181Sgd78059 181*5181Sgd78059 va_start(args, fmt); 182*5181Sgd78059 dmfe_vprt(fmt, args); 183*5181Sgd78059 va_end(args); 184*5181Sgd78059 185*5181Sgd78059 mutex_exit(prtdata.mutex); 186*5181Sgd78059 } 187*5181Sgd78059 188*5181Sgd78059 /* 189*5181Sgd78059 * Log a run-time event (CE_NOTE, log only) 190*5181Sgd78059 */ 191*5181Sgd78059 void 192*5181Sgd78059 dmfe_log(dmfe_t *dmfep, const char *fmt, ...) 193*5181Sgd78059 { 194*5181Sgd78059 va_list args; 195*5181Sgd78059 196*5181Sgd78059 mutex_enter(prtdata.mutex); 197*5181Sgd78059 prtdata.ifname = dmfep->ifname; 198*5181Sgd78059 prtdata.fmt = "!%s: %s"; 199*5181Sgd78059 prtdata.level = CE_NOTE; 200*5181Sgd78059 201*5181Sgd78059 va_start(args, fmt); 202*5181Sgd78059 dmfe_vprt(fmt, args); 203*5181Sgd78059 va_end(args); 204*5181Sgd78059 205*5181Sgd78059 mutex_exit(prtdata.mutex); 206*5181Sgd78059 } 207