1 /* 2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * This file may contain confidential information of Nvidia 8 * and should not be distributed in source form without approval 9 * from Sun Legal. 10 */ 11 12 #pragma ident "%Z%%M% %I% %E% SMI" 13 14 #include "nge.h" 15 16 17 /* 18 * Global variable for default debug flags 19 */ 20 uint32_t nge_debug; 21 22 /* 23 * Global mutex used by logging routines below 24 */ 25 kmutex_t nge_log_mutex[1]; 26 27 /* 28 * Static data used by logging routines; protected by <nge_log_mutex> 29 */ 30 static struct { 31 const char *who; 32 const char *fmt; 33 int level; 34 } nge_log_data; 35 36 37 /* 38 * Backend print routine for all the routines below 39 */ 40 static void 41 nge_vprt(const char *fmt, va_list args) 42 { 43 char buf[128]; 44 45 ASSERT(mutex_owned(nge_log_mutex)); 46 47 (void) vsnprintf(buf, sizeof (buf), fmt, args); 48 cmn_err(nge_log_data.level, nge_log_data.fmt, nge_log_data.who, buf); 49 } 50 51 52 /* 53 * Log a run-time event (CE_NOTE, log only) 54 */ 55 void 56 nge_log(nge_t *ngep, const char *fmt, ...) 57 { 58 va_list args; 59 60 mutex_enter(nge_log_mutex); 61 nge_log_data.who = ngep->ifname; 62 nge_log_data.fmt = "!%s: %s"; 63 nge_log_data.level = CE_NOTE; 64 65 va_start(args, fmt); 66 nge_vprt(fmt, args); 67 va_end(args); 68 69 mutex_exit(nge_log_mutex); 70 } 71 72 /* 73 * Log a run-time problem (CE_WARN, log only) 74 */ 75 void 76 nge_problem(nge_t *ngep, const char *fmt, ...) 77 { 78 va_list args; 79 80 mutex_enter(nge_log_mutex); 81 nge_log_data.who = ngep->ifname; 82 nge_log_data.fmt = "!%s: %s"; 83 nge_log_data.level = CE_WARN; 84 85 va_start(args, fmt); 86 nge_vprt(fmt, args); 87 va_end(args); 88 89 mutex_exit(nge_log_mutex); 90 } 91 92 /* 93 * Log a programming error (CE_WARN, log only) 94 */ 95 void 96 nge_error(nge_t *ngep, const char *fmt, ...) 97 { 98 va_list args; 99 100 mutex_enter(nge_log_mutex); 101 nge_log_data.who = ngep->ifname; 102 nge_log_data.fmt = "!%s: %s"; 103 nge_log_data.level = CE_WARN; 104 105 va_start(args, fmt); 106 nge_vprt(fmt, args); 107 va_end(args); 108 109 mutex_exit(nge_log_mutex); 110 } 111 112 static const char * 113 nge_class_string(uint8_t class_id) 114 { 115 const char *msg; 116 switch (class_id) { 117 default: 118 msg = "none"; 119 break; 120 121 case NGE_HW_ERR: 122 msg = "Hardware fatal error. Hardware will be reset"; 123 break; 124 125 case NGE_HW_LINK: 126 msg = "the link is broken, please check the connection"; 127 break; 128 129 case NGE_HW_BM: 130 msg = "Reset the hardware buffer management fails," 131 "need to power off/power on system. It is hardware bug"; 132 break; 133 134 case NGE_HW_RCHAN: 135 msg = "Reset rx's channel fails. Need to power off/power" 136 "on system"; 137 break; 138 139 case NGE_HW_TCHAN: 140 msg = "Reset rx's channel fails. Need to power off/power" 141 "on system"; 142 break; 143 144 case NGE_HW_ROM: 145 msg = "Unlock eeprom lock fails."; 146 break; 147 148 case NGE_SW_PROBLEM_ID: 149 msg = "Refill rx's bd fails"; 150 break; 151 } 152 return (msg); 153 } 154 155 void 156 nge_report(nge_t *ngep, uint8_t error_id) 157 { 158 const char *err_msg; 159 160 err_msg = nge_class_string(error_id); 161 nge_error(ngep, err_msg); 162 163 } 164 static void 165 nge_prt(const char *fmt, ...) 166 { 167 va_list args; 168 169 ASSERT(mutex_owned(nge_log_mutex)); 170 171 va_start(args, fmt); 172 nge_vprt(fmt, args); 173 va_end(args); 174 175 mutex_exit(nge_log_mutex); 176 } 177 178 void 179 (*nge_gdb(void))(const char *fmt, ...) 180 { 181 mutex_enter(nge_log_mutex); 182 183 nge_log_data.who = "nge"; 184 nge_log_data.fmt = "?%s: %s\n"; 185 nge_log_data.level = CE_CONT; 186 187 return (nge_prt); 188 } 189 190 void 191 (*nge_db(nge_t *ngep))(const char *fmt, ...) 192 { 193 mutex_enter(nge_log_mutex); 194 195 nge_log_data.who = ngep->ifname; 196 nge_log_data.fmt = "?%s: %s\n"; 197 nge_log_data.level = CE_CONT; 198 199 return (nge_prt); 200 } 201