17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 562387023Sdduvall * Common Development and Distribution License (the "License"). 662387023Sdduvall * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2162387023Sdduvall 227c478bd9Sstevel@tonic-gate /* 23*0d2a8e5eSgd78059 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 29f724721bSzh199473 #include "bge_impl.h" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * Global variable for default debug flags 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate uint32_t bge_debug; 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * Global mutex used by logging routines below 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate kmutex_t bge_log_mutex[1]; 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * Static data used by logging routines; protected by <bge_log_mutex> 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate static struct { 467c478bd9Sstevel@tonic-gate const char *who; 477c478bd9Sstevel@tonic-gate const char *fmt; 487c478bd9Sstevel@tonic-gate int level; 497c478bd9Sstevel@tonic-gate } bge_log_data; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Backend print routine for all the routines below 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate static void 567c478bd9Sstevel@tonic-gate bge_vprt(const char *fmt, va_list args) 577c478bd9Sstevel@tonic-gate { 587c478bd9Sstevel@tonic-gate char buf[128]; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(bge_log_mutex)); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate (void) vsnprintf(buf, sizeof (buf), fmt, args); 637c478bd9Sstevel@tonic-gate cmn_err(bge_log_data.level, bge_log_data.fmt, bge_log_data.who, buf); 647c478bd9Sstevel@tonic-gate } 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * Log a run-time event (CE_NOTE, log only) 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate void 707c478bd9Sstevel@tonic-gate bge_log(bge_t *bgep, const char *fmt, ...) 717c478bd9Sstevel@tonic-gate { 727c478bd9Sstevel@tonic-gate va_list args; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate mutex_enter(bge_log_mutex); 757c478bd9Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 767c478bd9Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 777c478bd9Sstevel@tonic-gate bge_log_data.level = CE_NOTE; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate va_start(args, fmt); 807c478bd9Sstevel@tonic-gate bge_vprt(fmt, args); 817c478bd9Sstevel@tonic-gate va_end(args); 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate mutex_exit(bge_log_mutex); 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * Log a run-time problem (CE_WARN, log only) 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate void 907c478bd9Sstevel@tonic-gate bge_problem(bge_t *bgep, const char *fmt, ...) 917c478bd9Sstevel@tonic-gate { 927c478bd9Sstevel@tonic-gate va_list args; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate mutex_enter(bge_log_mutex); 957c478bd9Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 967c478bd9Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 977c478bd9Sstevel@tonic-gate bge_log_data.level = CE_WARN; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate va_start(args, fmt); 1007c478bd9Sstevel@tonic-gate bge_vprt(fmt, args); 1017c478bd9Sstevel@tonic-gate va_end(args); 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate mutex_exit(bge_log_mutex); 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Log a programming error (CE_WARN, log only) 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate void 1107c478bd9Sstevel@tonic-gate bge_error(bge_t *bgep, const char *fmt, ...) 1117c478bd9Sstevel@tonic-gate { 1127c478bd9Sstevel@tonic-gate va_list args; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate mutex_enter(bge_log_mutex); 1157c478bd9Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 1167c478bd9Sstevel@tonic-gate bge_log_data.fmt = "!%s: %s"; 1177c478bd9Sstevel@tonic-gate bge_log_data.level = CE_WARN; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate va_start(args, fmt); 1207c478bd9Sstevel@tonic-gate bge_vprt(fmt, args); 1217c478bd9Sstevel@tonic-gate va_end(args); 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate mutex_exit(bge_log_mutex); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate 12600d0963fSdilpreet void 12700d0963fSdilpreet bge_fm_ereport(bge_t *bgep, char *detail) 12800d0963fSdilpreet { 12900d0963fSdilpreet uint64_t ena; 13000d0963fSdilpreet char buf[FM_MAX_CLASS]; 13100d0963fSdilpreet 13200d0963fSdilpreet (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail); 13300d0963fSdilpreet ena = fm_ena_generate(0, FM_ENA_FMT1); 13400d0963fSdilpreet if (DDI_FM_EREPORT_CAP(bgep->fm_capabilities)) { 13500d0963fSdilpreet ddi_fm_ereport_post(bgep->devinfo, buf, ena, DDI_NOSLEEP, 13600d0963fSdilpreet FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL); 13700d0963fSdilpreet } 13800d0963fSdilpreet } 13900d0963fSdilpreet 1407c478bd9Sstevel@tonic-gate #if BGE_DEBUGGING 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate static void 1437c478bd9Sstevel@tonic-gate bge_prt(const char *fmt, ...) 1447c478bd9Sstevel@tonic-gate { 1457c478bd9Sstevel@tonic-gate va_list args; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(bge_log_mutex)); 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate va_start(args, fmt); 1507c478bd9Sstevel@tonic-gate bge_vprt(fmt, args); 1517c478bd9Sstevel@tonic-gate va_end(args); 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate mutex_exit(bge_log_mutex); 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate void 1577c478bd9Sstevel@tonic-gate (*bge_gdb(void))(const char *fmt, ...) 1587c478bd9Sstevel@tonic-gate { 1597c478bd9Sstevel@tonic-gate mutex_enter(bge_log_mutex); 1607c478bd9Sstevel@tonic-gate bge_log_data.who = "bge"; 1617c478bd9Sstevel@tonic-gate bge_log_data.fmt = "?%s: %s\n"; 1627c478bd9Sstevel@tonic-gate bge_log_data.level = CE_CONT; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate return (bge_prt); 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate void 1687c478bd9Sstevel@tonic-gate (*bge_db(bge_t *bgep))(const char *fmt, ...) 1697c478bd9Sstevel@tonic-gate { 1707c478bd9Sstevel@tonic-gate mutex_enter(bge_log_mutex); 1717c478bd9Sstevel@tonic-gate bge_log_data.who = bgep->ifname; 1727c478bd9Sstevel@tonic-gate bge_log_data.fmt = "?%s: %s\n"; 1737c478bd9Sstevel@tonic-gate bge_log_data.level = CE_CONT; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate return (bge_prt); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate /* 1797c478bd9Sstevel@tonic-gate * Dump a chunk of memory, 16 bytes at a time 1807c478bd9Sstevel@tonic-gate */ 1817c478bd9Sstevel@tonic-gate static void 1827c478bd9Sstevel@tonic-gate minidump(bge_t *bgep, const char *caption, void *dp, uint_t len) 1837c478bd9Sstevel@tonic-gate { 1847c478bd9Sstevel@tonic-gate uint32_t buf[4]; 1857c478bd9Sstevel@tonic-gate uint32_t nbytes; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate bge_log(bgep, "%d bytes of %s at address %p:-", len, caption, dp); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate for (len = MIN(len, BGE_STD_BUFF_SIZE); len != 0; len -= nbytes) { 1907c478bd9Sstevel@tonic-gate nbytes = MIN(len, sizeof (buf)); 1917c478bd9Sstevel@tonic-gate bzero(buf, sizeof (buf)); 1927c478bd9Sstevel@tonic-gate bcopy(dp, buf, nbytes); 1937c478bd9Sstevel@tonic-gate bge_log(bgep, "%08x %08x %08x %08x", 1947c478bd9Sstevel@tonic-gate buf[0], buf[1], buf[2], buf[3]); 1957c478bd9Sstevel@tonic-gate dp = (caddr_t)dp + nbytes; 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate void 2007c478bd9Sstevel@tonic-gate bge_pkt_dump(bge_t *bgep, bge_rbd_t *hrbdp, sw_rbd_t *srbdp, const char *msg) 2017c478bd9Sstevel@tonic-gate { 2027c478bd9Sstevel@tonic-gate bge_problem(bgep, "driver-detected hardware error: %s", msg); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate minidump(bgep, "hardware descriptor", hrbdp, sizeof (*hrbdp)); 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate bge_log(bgep, "PCI address %llx packet len 0x%x token 0x%x " 2077c478bd9Sstevel@tonic-gate "flags 0x%x index 0x%x", 2087c478bd9Sstevel@tonic-gate hrbdp->host_buf_addr, 2097c478bd9Sstevel@tonic-gate hrbdp->len, 2107c478bd9Sstevel@tonic-gate hrbdp->opaque, 2117c478bd9Sstevel@tonic-gate hrbdp->flags, 2127c478bd9Sstevel@tonic-gate hrbdp->index); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate if (srbdp != NULL) { 2157c478bd9Sstevel@tonic-gate minidump(bgep, "software descriptor", srbdp, sizeof (*srbdp)); 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate bge_log(bgep, "PCI address %llx buffer len 0x%x token 0x%x", 2187c478bd9Sstevel@tonic-gate srbdp->pbuf.cookie.dmac_laddress, 2197c478bd9Sstevel@tonic-gate srbdp->pbuf.alength, 2207c478bd9Sstevel@tonic-gate srbdp->pbuf.token); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate minidump(bgep, "packet data", srbdp->pbuf.mem_va, hrbdp->len); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate void 2277c478bd9Sstevel@tonic-gate bge_dbg_enter(bge_t *bgep, const char *s) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate uint32_t debug; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate debug = bgep != NULL ? bgep->debug : bge_debug; 2327c478bd9Sstevel@tonic-gate if (debug & BGE_DBG_STOP) { 2337c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "bge_dbg_enter(%p): %s\n", (void *)bgep, s); 2347c478bd9Sstevel@tonic-gate debug_enter(""); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate #endif /* BGE_DEBUGGING */ 239