10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51369Sdduvall * Common Development and Distribution License (the "License"). 61369Sdduvall * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211369Sdduvall 220Sstevel@tonic-gate /* 231369Sdduvall * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 29*2675Szh199473 #include "bge_impl.h" 300Sstevel@tonic-gate 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * Global variable for default debug flags 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate uint32_t bge_debug; 360Sstevel@tonic-gate 370Sstevel@tonic-gate /* 380Sstevel@tonic-gate * Global mutex used by logging routines below 390Sstevel@tonic-gate */ 400Sstevel@tonic-gate kmutex_t bge_log_mutex[1]; 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * Static data used by logging routines; protected by <bge_log_mutex> 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate static struct { 460Sstevel@tonic-gate const char *who; 470Sstevel@tonic-gate const char *fmt; 480Sstevel@tonic-gate int level; 490Sstevel@tonic-gate } bge_log_data; 500Sstevel@tonic-gate 510Sstevel@tonic-gate 520Sstevel@tonic-gate /* 530Sstevel@tonic-gate * Backend print routine for all the routines below 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate static void 560Sstevel@tonic-gate bge_vprt(const char *fmt, va_list args) 570Sstevel@tonic-gate { 580Sstevel@tonic-gate char buf[128]; 590Sstevel@tonic-gate 600Sstevel@tonic-gate ASSERT(mutex_owned(bge_log_mutex)); 610Sstevel@tonic-gate 620Sstevel@tonic-gate (void) vsnprintf(buf, sizeof (buf), fmt, args); 630Sstevel@tonic-gate cmn_err(bge_log_data.level, bge_log_data.fmt, bge_log_data.who, buf); 640Sstevel@tonic-gate } 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * Report a run-time event (CE_NOTE, to console & log) 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate void 700Sstevel@tonic-gate bge_notice(bge_t *bgep, const char *fmt, ...) 710Sstevel@tonic-gate { 720Sstevel@tonic-gate va_list args; 730Sstevel@tonic-gate 740Sstevel@tonic-gate mutex_enter(bge_log_mutex); 750Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 760Sstevel@tonic-gate bge_log_data.fmt = "%s: %s"; 770Sstevel@tonic-gate bge_log_data.level = CE_NOTE; 780Sstevel@tonic-gate 790Sstevel@tonic-gate va_start(args, fmt); 800Sstevel@tonic-gate bge_vprt(fmt, args); 810Sstevel@tonic-gate va_end(args); 820Sstevel@tonic-gate 830Sstevel@tonic-gate mutex_exit(bge_log_mutex); 840Sstevel@tonic-gate } 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* 870Sstevel@tonic-gate * Log a run-time event (CE_NOTE, log only) 880Sstevel@tonic-gate */ 890Sstevel@tonic-gate void 900Sstevel@tonic-gate bge_log(bge_t *bgep, const char *fmt, ...) 910Sstevel@tonic-gate { 920Sstevel@tonic-gate va_list args; 930Sstevel@tonic-gate 940Sstevel@tonic-gate mutex_enter(bge_log_mutex); 950Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 960Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 970Sstevel@tonic-gate bge_log_data.level = CE_NOTE; 980Sstevel@tonic-gate 990Sstevel@tonic-gate va_start(args, fmt); 1000Sstevel@tonic-gate bge_vprt(fmt, args); 1010Sstevel@tonic-gate va_end(args); 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate mutex_exit(bge_log_mutex); 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * Log a run-time problem (CE_WARN, log only) 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate void 1100Sstevel@tonic-gate bge_problem(bge_t *bgep, const char *fmt, ...) 1110Sstevel@tonic-gate { 1120Sstevel@tonic-gate va_list args; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate mutex_enter(bge_log_mutex); 1150Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 1160Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 1170Sstevel@tonic-gate bge_log_data.level = CE_WARN; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate va_start(args, fmt); 1200Sstevel@tonic-gate bge_vprt(fmt, args); 1210Sstevel@tonic-gate va_end(args); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate mutex_exit(bge_log_mutex); 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate /* 1270Sstevel@tonic-gate * Log a programming error (CE_WARN, log only) 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate void 1300Sstevel@tonic-gate bge_error(bge_t *bgep, const char *fmt, ...) 1310Sstevel@tonic-gate { 1320Sstevel@tonic-gate va_list args; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate mutex_enter(bge_log_mutex); 1350Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 1360Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 1370Sstevel@tonic-gate bge_log_data.level = CE_WARN; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate va_start(args, fmt); 1400Sstevel@tonic-gate bge_vprt(fmt, args); 1410Sstevel@tonic-gate va_end(args); 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate mutex_exit(bge_log_mutex); 1440Sstevel@tonic-gate } 1450Sstevel@tonic-gate 1461865Sdilpreet void 1471865Sdilpreet bge_fm_ereport(bge_t *bgep, char *detail) 1481865Sdilpreet { 1491865Sdilpreet uint64_t ena; 1501865Sdilpreet char buf[FM_MAX_CLASS]; 1511865Sdilpreet 1521865Sdilpreet (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail); 1531865Sdilpreet ena = fm_ena_generate(0, FM_ENA_FMT1); 1541865Sdilpreet if (DDI_FM_EREPORT_CAP(bgep->fm_capabilities)) { 1551865Sdilpreet ddi_fm_ereport_post(bgep->devinfo, buf, ena, DDI_NOSLEEP, 1561865Sdilpreet FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL); 1571865Sdilpreet } 1581865Sdilpreet } 1591865Sdilpreet 1600Sstevel@tonic-gate #if BGE_DEBUGGING 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate static void 1630Sstevel@tonic-gate bge_prt(const char *fmt, ...) 1640Sstevel@tonic-gate { 1650Sstevel@tonic-gate va_list args; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate ASSERT(mutex_owned(bge_log_mutex)); 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate va_start(args, fmt); 1700Sstevel@tonic-gate bge_vprt(fmt, args); 1710Sstevel@tonic-gate va_end(args); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate mutex_exit(bge_log_mutex); 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate void 1770Sstevel@tonic-gate (*bge_gdb(void))(const char *fmt, ...) 1780Sstevel@tonic-gate { 1790Sstevel@tonic-gate mutex_enter(bge_log_mutex); 1800Sstevel@tonic-gate bge_log_data.who = "bge"; 1810Sstevel@tonic-gate bge_log_data.fmt = "?%s: %s\n"; 1820Sstevel@tonic-gate bge_log_data.level = CE_CONT; 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate return (bge_prt); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate void 1880Sstevel@tonic-gate (*bge_db(bge_t *bgep))(const char *fmt, ...) 1890Sstevel@tonic-gate { 1900Sstevel@tonic-gate mutex_enter(bge_log_mutex); 1910Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 1920Sstevel@tonic-gate bge_log_data.fmt = "?%s: %s\n"; 1930Sstevel@tonic-gate bge_log_data.level = CE_CONT; 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate return (bge_prt); 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* 1990Sstevel@tonic-gate * Dump a chunk of memory, 16 bytes at a time 2000Sstevel@tonic-gate */ 2010Sstevel@tonic-gate static void 2020Sstevel@tonic-gate minidump(bge_t *bgep, const char *caption, void *dp, uint_t len) 2030Sstevel@tonic-gate { 2040Sstevel@tonic-gate uint32_t buf[4]; 2050Sstevel@tonic-gate uint32_t nbytes; 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate bge_log(bgep, "%d bytes of %s at address %p:-", len, caption, dp); 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate for (len = MIN(len, BGE_STD_BUFF_SIZE); len != 0; len -= nbytes) { 2100Sstevel@tonic-gate nbytes = MIN(len, sizeof (buf)); 2110Sstevel@tonic-gate bzero(buf, sizeof (buf)); 2120Sstevel@tonic-gate bcopy(dp, buf, nbytes); 2130Sstevel@tonic-gate bge_log(bgep, "%08x %08x %08x %08x", 2140Sstevel@tonic-gate buf[0], buf[1], buf[2], buf[3]); 2150Sstevel@tonic-gate dp = (caddr_t)dp + nbytes; 2160Sstevel@tonic-gate } 2170Sstevel@tonic-gate } 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate void 2200Sstevel@tonic-gate bge_pkt_dump(bge_t *bgep, bge_rbd_t *hrbdp, sw_rbd_t *srbdp, const char *msg) 2210Sstevel@tonic-gate { 2220Sstevel@tonic-gate bge_problem(bgep, "driver-detected hardware error: %s", msg); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate minidump(bgep, "hardware descriptor", hrbdp, sizeof (*hrbdp)); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate bge_log(bgep, "PCI address %llx packet len 0x%x token 0x%x " 2270Sstevel@tonic-gate "flags 0x%x index 0x%x", 2280Sstevel@tonic-gate hrbdp->host_buf_addr, 2290Sstevel@tonic-gate hrbdp->len, 2300Sstevel@tonic-gate hrbdp->opaque, 2310Sstevel@tonic-gate hrbdp->flags, 2320Sstevel@tonic-gate hrbdp->index); 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate if (srbdp != NULL) { 2350Sstevel@tonic-gate minidump(bgep, "software descriptor", srbdp, sizeof (*srbdp)); 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate bge_log(bgep, "PCI address %llx buffer len 0x%x token 0x%x", 2380Sstevel@tonic-gate srbdp->pbuf.cookie.dmac_laddress, 2390Sstevel@tonic-gate srbdp->pbuf.alength, 2400Sstevel@tonic-gate srbdp->pbuf.token); 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate minidump(bgep, "packet data", srbdp->pbuf.mem_va, hrbdp->len); 2430Sstevel@tonic-gate } 2440Sstevel@tonic-gate } 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate void 2470Sstevel@tonic-gate bge_dbg_enter(bge_t *bgep, const char *s) 2480Sstevel@tonic-gate { 2490Sstevel@tonic-gate uint32_t debug; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate debug = bgep != NULL ? bgep->debug : bge_debug; 2520Sstevel@tonic-gate if (debug & BGE_DBG_STOP) { 2530Sstevel@tonic-gate cmn_err(CE_CONT, "bge_dbg_enter(%p): %s\n", (void *)bgep, s); 2540Sstevel@tonic-gate debug_enter(""); 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate #endif /* BGE_DEBUGGING */ 259