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