16f3e57acSmx205022 /* 2*47693af9Smx205022 * CDDL HEADER START 3*47693af9Smx205022 * 4*47693af9Smx205022 * The contents of this file are subject to the terms of the 5*47693af9Smx205022 * Common Development and Distribution License (the "License"). 6*47693af9Smx205022 * You may not use this file except in compliance with the License. 7*47693af9Smx205022 * 8*47693af9Smx205022 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*47693af9Smx205022 * or http://www.opensolaris.org/os/licensing. 10*47693af9Smx205022 * See the License for the specific language governing permissions 11*47693af9Smx205022 * and limitations under the License. 12*47693af9Smx205022 * 13*47693af9Smx205022 * When distributing Covered Code, include this CDDL HEADER in each 14*47693af9Smx205022 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*47693af9Smx205022 * If applicable, add the following below this CDDL HEADER, with the 16*47693af9Smx205022 * fields enclosed by brackets "[]" replaced with your own identifying 17*47693af9Smx205022 * information: Portions Copyright [yyyy] [name of copyright owner] 18*47693af9Smx205022 * 19*47693af9Smx205022 * CDDL HEADER END 206f3e57acSmx205022 */ 216f3e57acSmx205022 226f3e57acSmx205022 /* 23*47693af9Smx205022 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*47693af9Smx205022 * Use is subject to license terms. 256f3e57acSmx205022 */ 266f3e57acSmx205022 276f3e57acSmx205022 #pragma ident "%Z%%M% %I% %E% SMI" 286f3e57acSmx205022 296f3e57acSmx205022 #include "nge.h" 306f3e57acSmx205022 316f3e57acSmx205022 326f3e57acSmx205022 /* 336f3e57acSmx205022 * Global variable for default debug flags 346f3e57acSmx205022 */ 356f3e57acSmx205022 uint32_t nge_debug; 366f3e57acSmx205022 376f3e57acSmx205022 /* 386f3e57acSmx205022 * Global mutex used by logging routines below 396f3e57acSmx205022 */ 406f3e57acSmx205022 kmutex_t nge_log_mutex[1]; 416f3e57acSmx205022 426f3e57acSmx205022 /* 436f3e57acSmx205022 * Static data used by logging routines; protected by <nge_log_mutex> 446f3e57acSmx205022 */ 456f3e57acSmx205022 static struct { 466f3e57acSmx205022 const char *who; 476f3e57acSmx205022 const char *fmt; 486f3e57acSmx205022 int level; 496f3e57acSmx205022 } nge_log_data; 506f3e57acSmx205022 516f3e57acSmx205022 526f3e57acSmx205022 /* 536f3e57acSmx205022 * Backend print routine for all the routines below 546f3e57acSmx205022 */ 556f3e57acSmx205022 static void 566f3e57acSmx205022 nge_vprt(const char *fmt, va_list args) 576f3e57acSmx205022 { 586f3e57acSmx205022 char buf[128]; 596f3e57acSmx205022 606f3e57acSmx205022 ASSERT(mutex_owned(nge_log_mutex)); 616f3e57acSmx205022 626f3e57acSmx205022 (void) vsnprintf(buf, sizeof (buf), fmt, args); 636f3e57acSmx205022 cmn_err(nge_log_data.level, nge_log_data.fmt, nge_log_data.who, buf); 646f3e57acSmx205022 } 656f3e57acSmx205022 666f3e57acSmx205022 676f3e57acSmx205022 /* 686f3e57acSmx205022 * Log a run-time event (CE_NOTE, log only) 696f3e57acSmx205022 */ 706f3e57acSmx205022 void 716f3e57acSmx205022 nge_log(nge_t *ngep, const char *fmt, ...) 726f3e57acSmx205022 { 736f3e57acSmx205022 va_list args; 746f3e57acSmx205022 756f3e57acSmx205022 mutex_enter(nge_log_mutex); 766f3e57acSmx205022 nge_log_data.who = ngep->ifname; 776f3e57acSmx205022 nge_log_data.fmt = "!%s: %s"; 786f3e57acSmx205022 nge_log_data.level = CE_NOTE; 796f3e57acSmx205022 806f3e57acSmx205022 va_start(args, fmt); 816f3e57acSmx205022 nge_vprt(fmt, args); 826f3e57acSmx205022 va_end(args); 836f3e57acSmx205022 846f3e57acSmx205022 mutex_exit(nge_log_mutex); 856f3e57acSmx205022 } 866f3e57acSmx205022 876f3e57acSmx205022 /* 886f3e57acSmx205022 * Log a run-time problem (CE_WARN, log only) 896f3e57acSmx205022 */ 906f3e57acSmx205022 void 916f3e57acSmx205022 nge_problem(nge_t *ngep, const char *fmt, ...) 926f3e57acSmx205022 { 936f3e57acSmx205022 va_list args; 946f3e57acSmx205022 956f3e57acSmx205022 mutex_enter(nge_log_mutex); 966f3e57acSmx205022 nge_log_data.who = ngep->ifname; 976f3e57acSmx205022 nge_log_data.fmt = "!%s: %s"; 986f3e57acSmx205022 nge_log_data.level = CE_WARN; 996f3e57acSmx205022 1006f3e57acSmx205022 va_start(args, fmt); 1016f3e57acSmx205022 nge_vprt(fmt, args); 1026f3e57acSmx205022 va_end(args); 1036f3e57acSmx205022 1046f3e57acSmx205022 mutex_exit(nge_log_mutex); 1056f3e57acSmx205022 } 1066f3e57acSmx205022 1076f3e57acSmx205022 /* 1086f3e57acSmx205022 * Log a programming error (CE_WARN, log only) 1096f3e57acSmx205022 */ 1106f3e57acSmx205022 void 1116f3e57acSmx205022 nge_error(nge_t *ngep, const char *fmt, ...) 1126f3e57acSmx205022 { 1136f3e57acSmx205022 va_list args; 1146f3e57acSmx205022 1156f3e57acSmx205022 mutex_enter(nge_log_mutex); 1166f3e57acSmx205022 nge_log_data.who = ngep->ifname; 1176f3e57acSmx205022 nge_log_data.fmt = "!%s: %s"; 1186f3e57acSmx205022 nge_log_data.level = CE_WARN; 1196f3e57acSmx205022 1206f3e57acSmx205022 va_start(args, fmt); 1216f3e57acSmx205022 nge_vprt(fmt, args); 1226f3e57acSmx205022 va_end(args); 1236f3e57acSmx205022 1246f3e57acSmx205022 mutex_exit(nge_log_mutex); 1256f3e57acSmx205022 } 1266f3e57acSmx205022 1276f3e57acSmx205022 static const char * 1286f3e57acSmx205022 nge_class_string(uint8_t class_id) 1296f3e57acSmx205022 { 1306f3e57acSmx205022 const char *msg; 1316f3e57acSmx205022 switch (class_id) { 1326f3e57acSmx205022 default: 1336f3e57acSmx205022 msg = "none"; 1346f3e57acSmx205022 break; 1356f3e57acSmx205022 1366f3e57acSmx205022 case NGE_HW_ERR: 1376f3e57acSmx205022 msg = "Hardware fatal error. Hardware will be reset"; 1386f3e57acSmx205022 break; 1396f3e57acSmx205022 1406f3e57acSmx205022 case NGE_HW_LINK: 1416f3e57acSmx205022 msg = "the link is broken, please check the connection"; 1426f3e57acSmx205022 break; 1436f3e57acSmx205022 1446f3e57acSmx205022 case NGE_HW_BM: 1456f3e57acSmx205022 msg = "Reset the hardware buffer management fails," 1466f3e57acSmx205022 "need to power off/power on system. It is hardware bug"; 1476f3e57acSmx205022 break; 1486f3e57acSmx205022 1496f3e57acSmx205022 case NGE_HW_RCHAN: 1506f3e57acSmx205022 msg = "Reset rx's channel fails. Need to power off/power" 1516f3e57acSmx205022 "on system"; 1526f3e57acSmx205022 break; 1536f3e57acSmx205022 1546f3e57acSmx205022 case NGE_HW_TCHAN: 1556f3e57acSmx205022 msg = "Reset rx's channel fails. Need to power off/power" 1566f3e57acSmx205022 "on system"; 1576f3e57acSmx205022 break; 1586f3e57acSmx205022 1596f3e57acSmx205022 case NGE_HW_ROM: 1606f3e57acSmx205022 msg = "Unlock eeprom lock fails."; 1616f3e57acSmx205022 break; 1626f3e57acSmx205022 1636f3e57acSmx205022 case NGE_SW_PROBLEM_ID: 1646f3e57acSmx205022 msg = "Refill rx's bd fails"; 1656f3e57acSmx205022 break; 1666f3e57acSmx205022 } 1676f3e57acSmx205022 return (msg); 1686f3e57acSmx205022 } 1696f3e57acSmx205022 1706f3e57acSmx205022 void 1716f3e57acSmx205022 nge_report(nge_t *ngep, uint8_t error_id) 1726f3e57acSmx205022 { 1736f3e57acSmx205022 const char *err_msg; 1746f3e57acSmx205022 1756f3e57acSmx205022 err_msg = nge_class_string(error_id); 1766f3e57acSmx205022 nge_error(ngep, err_msg); 1776f3e57acSmx205022 1786f3e57acSmx205022 } 1796f3e57acSmx205022 static void 1806f3e57acSmx205022 nge_prt(const char *fmt, ...) 1816f3e57acSmx205022 { 1826f3e57acSmx205022 va_list args; 1836f3e57acSmx205022 1846f3e57acSmx205022 ASSERT(mutex_owned(nge_log_mutex)); 1856f3e57acSmx205022 1866f3e57acSmx205022 va_start(args, fmt); 1876f3e57acSmx205022 nge_vprt(fmt, args); 1886f3e57acSmx205022 va_end(args); 1896f3e57acSmx205022 1906f3e57acSmx205022 mutex_exit(nge_log_mutex); 1916f3e57acSmx205022 } 1926f3e57acSmx205022 1936f3e57acSmx205022 void 1946f3e57acSmx205022 (*nge_gdb(void))(const char *fmt, ...) 1956f3e57acSmx205022 { 1966f3e57acSmx205022 mutex_enter(nge_log_mutex); 1976f3e57acSmx205022 1986f3e57acSmx205022 nge_log_data.who = "nge"; 1996f3e57acSmx205022 nge_log_data.fmt = "?%s: %s\n"; 2006f3e57acSmx205022 nge_log_data.level = CE_CONT; 2016f3e57acSmx205022 2026f3e57acSmx205022 return (nge_prt); 2036f3e57acSmx205022 } 2046f3e57acSmx205022 2056f3e57acSmx205022 void 2066f3e57acSmx205022 (*nge_db(nge_t *ngep))(const char *fmt, ...) 2076f3e57acSmx205022 { 2086f3e57acSmx205022 mutex_enter(nge_log_mutex); 2096f3e57acSmx205022 2106f3e57acSmx205022 nge_log_data.who = ngep->ifname; 2116f3e57acSmx205022 nge_log_data.fmt = "?%s: %s\n"; 2126f3e57acSmx205022 nge_log_data.level = CE_CONT; 2136f3e57acSmx205022 2146f3e57acSmx205022 return (nge_prt); 2156f3e57acSmx205022 } 216