1*5578Smx205022 /*
2*5578Smx205022 * CDDL HEADER START
3*5578Smx205022 *
4*5578Smx205022 * The contents of this file are subject to the terms of the
5*5578Smx205022 * Common Development and Distribution License (the "License").
6*5578Smx205022 * You may not use this file except in compliance with the License.
7*5578Smx205022 *
8*5578Smx205022 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5578Smx205022 * or http://www.opensolaris.org/os/licensing.
10*5578Smx205022 * See the License for the specific language governing permissions
11*5578Smx205022 * and limitations under the License.
12*5578Smx205022 *
13*5578Smx205022 * When distributing Covered Code, include this CDDL HEADER in each
14*5578Smx205022 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5578Smx205022 * If applicable, add the following below this CDDL HEADER, with the
16*5578Smx205022 * fields enclosed by brackets "[]" replaced with your own identifying
17*5578Smx205022 * information: Portions Copyright [yyyy] [name of copyright owner]
18*5578Smx205022 *
19*5578Smx205022 * CDDL HEADER END
20*5578Smx205022 */
21*5578Smx205022
225574Smx205022 /*
235574Smx205022 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
245574Smx205022 * Use is subject to license terms.
255574Smx205022 */
265574Smx205022
275574Smx205022 #pragma ident "%Z%%M% %I% %E% SMI"
285574Smx205022
295574Smx205022 #include "nge.h"
305574Smx205022
315574Smx205022
325574Smx205022 /*
335574Smx205022 * Global variable for default debug flags
345574Smx205022 */
355574Smx205022 uint32_t nge_debug;
365574Smx205022
375574Smx205022 /*
385574Smx205022 * Global mutex used by logging routines below
395574Smx205022 */
405574Smx205022 kmutex_t nge_log_mutex[1];
415574Smx205022
425574Smx205022 /*
435574Smx205022 * Static data used by logging routines; protected by <nge_log_mutex>
445574Smx205022 */
455574Smx205022 static struct {
465574Smx205022 const char *who;
475574Smx205022 const char *fmt;
485574Smx205022 int level;
495574Smx205022 } nge_log_data;
505574Smx205022
515574Smx205022
525574Smx205022 /*
535574Smx205022 * Backend print routine for all the routines below
545574Smx205022 */
555574Smx205022 static void
nge_vprt(const char * fmt,va_list args)565574Smx205022 nge_vprt(const char *fmt, va_list args)
575574Smx205022 {
585574Smx205022 char buf[128];
595574Smx205022
605574Smx205022 ASSERT(mutex_owned(nge_log_mutex));
615574Smx205022
625574Smx205022 (void) vsnprintf(buf, sizeof (buf), fmt, args);
635574Smx205022 cmn_err(nge_log_data.level, nge_log_data.fmt, nge_log_data.who, buf);
645574Smx205022 }
655574Smx205022
665574Smx205022
675574Smx205022 /*
685574Smx205022 * Log a run-time event (CE_NOTE, log only)
695574Smx205022 */
705574Smx205022 void
nge_log(nge_t * ngep,const char * fmt,...)715574Smx205022 nge_log(nge_t *ngep, const char *fmt, ...)
725574Smx205022 {
735574Smx205022 va_list args;
745574Smx205022
755574Smx205022 mutex_enter(nge_log_mutex);
765574Smx205022 nge_log_data.who = ngep->ifname;
775574Smx205022 nge_log_data.fmt = "!%s: %s";
785574Smx205022 nge_log_data.level = CE_NOTE;
795574Smx205022
805574Smx205022 va_start(args, fmt);
815574Smx205022 nge_vprt(fmt, args);
825574Smx205022 va_end(args);
835574Smx205022
845574Smx205022 mutex_exit(nge_log_mutex);
855574Smx205022 }
865574Smx205022
875574Smx205022 /*
885574Smx205022 * Log a run-time problem (CE_WARN, log only)
895574Smx205022 */
905574Smx205022 void
nge_problem(nge_t * ngep,const char * fmt,...)915574Smx205022 nge_problem(nge_t *ngep, const char *fmt, ...)
925574Smx205022 {
935574Smx205022 va_list args;
945574Smx205022
955574Smx205022 mutex_enter(nge_log_mutex);
965574Smx205022 nge_log_data.who = ngep->ifname;
975574Smx205022 nge_log_data.fmt = "!%s: %s";
985574Smx205022 nge_log_data.level = CE_WARN;
995574Smx205022
1005574Smx205022 va_start(args, fmt);
1015574Smx205022 nge_vprt(fmt, args);
1025574Smx205022 va_end(args);
1035574Smx205022
1045574Smx205022 mutex_exit(nge_log_mutex);
1055574Smx205022 }
1065574Smx205022
1075574Smx205022 /*
1085574Smx205022 * Log a programming error (CE_WARN, log only)
1095574Smx205022 */
1105574Smx205022 void
nge_error(nge_t * ngep,const char * fmt,...)1115574Smx205022 nge_error(nge_t *ngep, const char *fmt, ...)
1125574Smx205022 {
1135574Smx205022 va_list args;
1145574Smx205022
1155574Smx205022 mutex_enter(nge_log_mutex);
1165574Smx205022 nge_log_data.who = ngep->ifname;
1175574Smx205022 nge_log_data.fmt = "!%s: %s";
1185574Smx205022 nge_log_data.level = CE_WARN;
1195574Smx205022
1205574Smx205022 va_start(args, fmt);
1215574Smx205022 nge_vprt(fmt, args);
1225574Smx205022 va_end(args);
1235574Smx205022
1245574Smx205022 mutex_exit(nge_log_mutex);
1255574Smx205022 }
1265574Smx205022
1275574Smx205022 static const char *
nge_class_string(uint8_t class_id)1285574Smx205022 nge_class_string(uint8_t class_id)
1295574Smx205022 {
1305574Smx205022 const char *msg;
1315574Smx205022 switch (class_id) {
1325574Smx205022 default:
1335574Smx205022 msg = "none";
1345574Smx205022 break;
1355574Smx205022
1365574Smx205022 case NGE_HW_ERR:
1375574Smx205022 msg = "Hardware fatal error. Hardware will be reset";
1385574Smx205022 break;
1395574Smx205022
1405574Smx205022 case NGE_HW_LINK:
1415574Smx205022 msg = "the link is broken, please check the connection";
1425574Smx205022 break;
1435574Smx205022
1445574Smx205022 case NGE_HW_BM:
1455574Smx205022 msg = "Reset the hardware buffer management fails,"
1465574Smx205022 "need to power off/power on system. It is hardware bug";
1475574Smx205022 break;
1485574Smx205022
1495574Smx205022 case NGE_HW_RCHAN:
1505574Smx205022 msg = "Reset rx's channel fails. Need to power off/power"
1515574Smx205022 "on system";
1525574Smx205022 break;
1535574Smx205022
1545574Smx205022 case NGE_HW_TCHAN:
1555574Smx205022 msg = "Reset rx's channel fails. Need to power off/power"
1565574Smx205022 "on system";
1575574Smx205022 break;
1585574Smx205022
1595574Smx205022 case NGE_HW_ROM:
1605574Smx205022 msg = "Unlock eeprom lock fails.";
1615574Smx205022 break;
1625574Smx205022
1635574Smx205022 case NGE_SW_PROBLEM_ID:
1645574Smx205022 msg = "Refill rx's bd fails";
1655574Smx205022 break;
1665574Smx205022 }
1675574Smx205022 return (msg);
1685574Smx205022 }
1695574Smx205022
1705574Smx205022 void
nge_report(nge_t * ngep,uint8_t error_id)1715574Smx205022 nge_report(nge_t *ngep, uint8_t error_id)
1725574Smx205022 {
1735574Smx205022 const char *err_msg;
1745574Smx205022
1755574Smx205022 err_msg = nge_class_string(error_id);
1765574Smx205022 nge_error(ngep, err_msg);
1775574Smx205022
1785574Smx205022 }
1795574Smx205022 static void
nge_prt(const char * fmt,...)1805574Smx205022 nge_prt(const char *fmt, ...)
1815574Smx205022 {
1825574Smx205022 va_list args;
1835574Smx205022
1845574Smx205022 ASSERT(mutex_owned(nge_log_mutex));
1855574Smx205022
1865574Smx205022 va_start(args, fmt);
1875574Smx205022 nge_vprt(fmt, args);
1885574Smx205022 va_end(args);
1895574Smx205022
1905574Smx205022 mutex_exit(nge_log_mutex);
1915574Smx205022 }
1925574Smx205022
1935574Smx205022 void
nge_gdb(void)1945574Smx205022 (*nge_gdb(void))(const char *fmt, ...)
1955574Smx205022 {
1965574Smx205022 mutex_enter(nge_log_mutex);
1975574Smx205022
1985574Smx205022 nge_log_data.who = "nge";
1995574Smx205022 nge_log_data.fmt = "?%s: %s\n";
2005574Smx205022 nge_log_data.level = CE_CONT;
2015574Smx205022
2025574Smx205022 return (nge_prt);
2035574Smx205022 }
2045574Smx205022
2055574Smx205022 void
nge_db(nge_t * ngep)2065574Smx205022 (*nge_db(nge_t *ngep))(const char *fmt, ...)
2075574Smx205022 {
2085574Smx205022 mutex_enter(nge_log_mutex);
2095574Smx205022
2105574Smx205022 nge_log_data.who = ngep->ifname;
2115574Smx205022 nge_log_data.fmt = "?%s: %s\n";
2125574Smx205022 nge_log_data.level = CE_CONT;
2135574Smx205022
2145574Smx205022 return (nge_prt);
2155574Smx205022 }
216