1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include "sys/bge_impl.h" 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate /* 33*0Sstevel@tonic-gate * Global variable for default debug flags 34*0Sstevel@tonic-gate */ 35*0Sstevel@tonic-gate uint32_t bge_debug; 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate /* 38*0Sstevel@tonic-gate * Global mutex used by logging routines below 39*0Sstevel@tonic-gate */ 40*0Sstevel@tonic-gate kmutex_t bge_log_mutex[1]; 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate /* 43*0Sstevel@tonic-gate * Static data used by logging routines; protected by <bge_log_mutex> 44*0Sstevel@tonic-gate */ 45*0Sstevel@tonic-gate static struct { 46*0Sstevel@tonic-gate const char *who; 47*0Sstevel@tonic-gate const char *fmt; 48*0Sstevel@tonic-gate int level; 49*0Sstevel@tonic-gate } bge_log_data; 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate /* 53*0Sstevel@tonic-gate * Backend print routine for all the routines below 54*0Sstevel@tonic-gate */ 55*0Sstevel@tonic-gate static void 56*0Sstevel@tonic-gate bge_vprt(const char *fmt, va_list args) 57*0Sstevel@tonic-gate { 58*0Sstevel@tonic-gate char buf[128]; 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate ASSERT(mutex_owned(bge_log_mutex)); 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate (void) vsnprintf(buf, sizeof (buf), fmt, args); 63*0Sstevel@tonic-gate cmn_err(bge_log_data.level, bge_log_data.fmt, bge_log_data.who, buf); 64*0Sstevel@tonic-gate } 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate /* 67*0Sstevel@tonic-gate * Report a run-time event (CE_NOTE, to console & log) 68*0Sstevel@tonic-gate */ 69*0Sstevel@tonic-gate void 70*0Sstevel@tonic-gate bge_notice(bge_t *bgep, const char *fmt, ...) 71*0Sstevel@tonic-gate { 72*0Sstevel@tonic-gate va_list args; 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate mutex_enter(bge_log_mutex); 75*0Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 76*0Sstevel@tonic-gate bge_log_data.fmt = "%s: %s"; 77*0Sstevel@tonic-gate bge_log_data.level = CE_NOTE; 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate va_start(args, fmt); 80*0Sstevel@tonic-gate bge_vprt(fmt, args); 81*0Sstevel@tonic-gate va_end(args); 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate mutex_exit(bge_log_mutex); 84*0Sstevel@tonic-gate } 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate /* 87*0Sstevel@tonic-gate * Log a run-time event (CE_NOTE, log only) 88*0Sstevel@tonic-gate */ 89*0Sstevel@tonic-gate void 90*0Sstevel@tonic-gate bge_log(bge_t *bgep, const char *fmt, ...) 91*0Sstevel@tonic-gate { 92*0Sstevel@tonic-gate va_list args; 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate mutex_enter(bge_log_mutex); 95*0Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 96*0Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 97*0Sstevel@tonic-gate bge_log_data.level = CE_NOTE; 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate va_start(args, fmt); 100*0Sstevel@tonic-gate bge_vprt(fmt, args); 101*0Sstevel@tonic-gate va_end(args); 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate mutex_exit(bge_log_mutex); 104*0Sstevel@tonic-gate } 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate /* 107*0Sstevel@tonic-gate * Log a run-time problem (CE_WARN, log only) 108*0Sstevel@tonic-gate */ 109*0Sstevel@tonic-gate void 110*0Sstevel@tonic-gate bge_problem(bge_t *bgep, const char *fmt, ...) 111*0Sstevel@tonic-gate { 112*0Sstevel@tonic-gate va_list args; 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate mutex_enter(bge_log_mutex); 115*0Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 116*0Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 117*0Sstevel@tonic-gate bge_log_data.level = CE_WARN; 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate va_start(args, fmt); 120*0Sstevel@tonic-gate bge_vprt(fmt, args); 121*0Sstevel@tonic-gate va_end(args); 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate mutex_exit(bge_log_mutex); 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate /* 127*0Sstevel@tonic-gate * Log a programming error (CE_WARN, log only) 128*0Sstevel@tonic-gate */ 129*0Sstevel@tonic-gate void 130*0Sstevel@tonic-gate bge_error(bge_t *bgep, const char *fmt, ...) 131*0Sstevel@tonic-gate { 132*0Sstevel@tonic-gate va_list args; 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate mutex_enter(bge_log_mutex); 135*0Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 136*0Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 137*0Sstevel@tonic-gate bge_log_data.level = CE_WARN; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate va_start(args, fmt); 140*0Sstevel@tonic-gate bge_vprt(fmt, args); 141*0Sstevel@tonic-gate va_end(args); 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate mutex_exit(bge_log_mutex); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate #if BGE_DEBUGGING 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate static void 149*0Sstevel@tonic-gate bge_prt(const char *fmt, ...) 150*0Sstevel@tonic-gate { 151*0Sstevel@tonic-gate va_list args; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate ASSERT(mutex_owned(bge_log_mutex)); 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate va_start(args, fmt); 156*0Sstevel@tonic-gate bge_vprt(fmt, args); 157*0Sstevel@tonic-gate va_end(args); 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate mutex_exit(bge_log_mutex); 160*0Sstevel@tonic-gate } 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate void 163*0Sstevel@tonic-gate (*bge_gdb(void))(const char *fmt, ...) 164*0Sstevel@tonic-gate { 165*0Sstevel@tonic-gate mutex_enter(bge_log_mutex); 166*0Sstevel@tonic-gate bge_log_data.who = "bge"; 167*0Sstevel@tonic-gate bge_log_data.fmt = "?%s: %s\n"; 168*0Sstevel@tonic-gate bge_log_data.level = CE_CONT; 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate return (bge_prt); 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate void 174*0Sstevel@tonic-gate (*bge_db(bge_t *bgep))(const char *fmt, ...) 175*0Sstevel@tonic-gate { 176*0Sstevel@tonic-gate mutex_enter(bge_log_mutex); 177*0Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 178*0Sstevel@tonic-gate bge_log_data.fmt = "?%s: %s\n"; 179*0Sstevel@tonic-gate bge_log_data.level = CE_CONT; 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate return (bge_prt); 182*0Sstevel@tonic-gate } 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate /* 185*0Sstevel@tonic-gate * Dump a chunk of memory, 16 bytes at a time 186*0Sstevel@tonic-gate */ 187*0Sstevel@tonic-gate static void 188*0Sstevel@tonic-gate minidump(bge_t *bgep, const char *caption, void *dp, uint_t len) 189*0Sstevel@tonic-gate { 190*0Sstevel@tonic-gate uint32_t buf[4]; 191*0Sstevel@tonic-gate uint32_t nbytes; 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate bge_log(bgep, "%d bytes of %s at address %p:-", len, caption, dp); 194*0Sstevel@tonic-gate 195*0Sstevel@tonic-gate for (len = MIN(len, BGE_STD_BUFF_SIZE); len != 0; len -= nbytes) { 196*0Sstevel@tonic-gate nbytes = MIN(len, sizeof (buf)); 197*0Sstevel@tonic-gate bzero(buf, sizeof (buf)); 198*0Sstevel@tonic-gate bcopy(dp, buf, nbytes); 199*0Sstevel@tonic-gate bge_log(bgep, "%08x %08x %08x %08x", 200*0Sstevel@tonic-gate buf[0], buf[1], buf[2], buf[3]); 201*0Sstevel@tonic-gate dp = (caddr_t)dp + nbytes; 202*0Sstevel@tonic-gate } 203*0Sstevel@tonic-gate } 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate void 206*0Sstevel@tonic-gate bge_pkt_dump(bge_t *bgep, bge_rbd_t *hrbdp, sw_rbd_t *srbdp, const char *msg) 207*0Sstevel@tonic-gate { 208*0Sstevel@tonic-gate bge_problem(bgep, "driver-detected hardware error: %s", msg); 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate minidump(bgep, "hardware descriptor", hrbdp, sizeof (*hrbdp)); 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate bge_log(bgep, "PCI address %llx packet len 0x%x token 0x%x " 213*0Sstevel@tonic-gate "flags 0x%x index 0x%x", 214*0Sstevel@tonic-gate hrbdp->host_buf_addr, 215*0Sstevel@tonic-gate hrbdp->len, 216*0Sstevel@tonic-gate hrbdp->opaque, 217*0Sstevel@tonic-gate hrbdp->flags, 218*0Sstevel@tonic-gate hrbdp->index); 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate if (srbdp != NULL) { 221*0Sstevel@tonic-gate minidump(bgep, "software descriptor", srbdp, sizeof (*srbdp)); 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate bge_log(bgep, "PCI address %llx buffer len 0x%x token 0x%x", 224*0Sstevel@tonic-gate srbdp->pbuf.cookie.dmac_laddress, 225*0Sstevel@tonic-gate srbdp->pbuf.alength, 226*0Sstevel@tonic-gate srbdp->pbuf.token); 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate minidump(bgep, "packet data", srbdp->pbuf.mem_va, hrbdp->len); 229*0Sstevel@tonic-gate } 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate void 233*0Sstevel@tonic-gate bge_dbg_enter(bge_t *bgep, const char *s) 234*0Sstevel@tonic-gate { 235*0Sstevel@tonic-gate uint32_t debug; 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate debug = bgep != NULL ? bgep->debug : bge_debug; 238*0Sstevel@tonic-gate if (debug & BGE_DBG_STOP) { 239*0Sstevel@tonic-gate cmn_err(CE_CONT, "bge_dbg_enter(%p): %s\n", (void *)bgep, s); 240*0Sstevel@tonic-gate debug_enter(""); 241*0Sstevel@tonic-gate } 242*0Sstevel@tonic-gate } 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate #endif /* BGE_DEBUGGING */ 245