Robert Mustacchi | d14abf1 | 2014-06-06 22:58:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * CDDL HEADER START |
| 3 | * |
| 4 | * The contents of this file are subject to the terms of the |
| 5 | * Common Development and Distribution License (the "License"). |
| 6 | * You may not use this file except in compliance with the License. |
| 7 | * |
| 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
| 9 | * or http://www.opensolaris.org/os/licensing. |
| 10 | * See the License for the specific language governing permissions |
| 11 | * and limitations under the License. |
| 12 | * |
| 13 | * When distributing Covered Code, include this CDDL HEADER in each |
| 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
| 15 | * If applicable, add the following below this CDDL HEADER, with the |
| 16 | * fields enclosed by brackets "[]" replaced with your own identifying |
| 17 | * information: Portions Copyright [yyyy] [name of copyright owner] |
| 18 | * |
| 19 | * CDDL HEADER END |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * Copyright 2014 QLogic Corporation |
| 24 | * The contents of this file are subject to the terms of the |
| 25 | * QLogic End User License (the "License"). |
| 26 | * You may not use this file except in compliance with the License. |
| 27 | * |
| 28 | * You can obtain a copy of the License at |
| 29 | * http://www.qlogic.com/Resources/Documents/DriverDownloadHelp/ |
| 30 | * QLogic_End_User_Software_License.txt |
| 31 | * See the License for the specific language governing permissions |
| 32 | * and limitations under the License. |
| 33 | */ |
| 34 | |
| 35 | #include "bnxe.h" |
| 36 | |
| 37 | #define BNXE_LOG_LEN 256 |
| 38 | |
| 39 | |
| 40 | #ifdef DBG |
| 41 | |
| 42 | void DbgMessageFunc(void * pDev, |
| 43 | int level, |
| 44 | char * pFmt, |
| 45 | ...) |
| 46 | { |
| 47 | um_device_t * pUM = (um_device_t *)pDev; |
| 48 | va_list argp; |
| 49 | int ce; |
| 50 | |
| 51 | if ((pUM != NULL) && |
| 52 | (((pUM->devParams.debug_level & level & CP_ALL) != (level & CP_ALL)) || |
| 53 | ((pUM->devParams.debug_level & LV_MASK) < (level & LV_MASK)))) |
| 54 | { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | ce = (((level & LV_VERBOSE) == LV_VERBOSE) ? CE_NOTE : |
| 59 | ((level & LV_INFORM) == LV_INFORM) ? CE_NOTE : |
| 60 | ((level & LV_WARN) == LV_WARN) ? CE_WARN : |
| 61 | CE_PANIC); |
| 62 | |
| 63 | va_start(argp, pFmt); |
| 64 | vcmn_err(ce, pFmt, argp); |
| 65 | va_end(argp); |
| 66 | } |
| 67 | |
| 68 | #endif /* DBG */ |
| 69 | |
| 70 | |
| 71 | void elink_cb_dbg(struct elink_dev * bp, char * fmt) |
| 72 | { |
| 73 | um_device_t * pUM = (um_device_t *)bp; |
| 74 | char buf[BNXE_LOG_LEN]; |
| 75 | |
| 76 | #ifdef DBG |
| 77 | if ((pUM->devParams.debug_level & LV_MASK) < LV_WARN) |
| 78 | { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | snprintf(buf, sizeof(buf), fmt); |
| 83 | cmn_err(CE_NOTE, "!%s: ELINK %s", BnxeDevName(pUM), buf); |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | |
| 88 | void elink_cb_dbg1(struct elink_dev * bp, char * fmt, u32 arg1) |
| 89 | { |
| 90 | um_device_t * pUM = (um_device_t *)bp; |
| 91 | char buf[BNXE_LOG_LEN]; |
| 92 | |
| 93 | #ifdef DBG |
| 94 | if ((pUM->devParams.debug_level & LV_MASK) < LV_WARN) |
| 95 | { |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | snprintf(buf, sizeof(buf), fmt, arg1); |
| 100 | cmn_err(CE_NOTE, "!%s: ELINK %s", BnxeDevName(pUM), buf); |
| 101 | #endif |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void elink_cb_dbg2(struct elink_dev * bp, char * fmt, u32 arg1, u32 arg2) |
| 106 | { |
| 107 | um_device_t * pUM = (um_device_t *)bp; |
| 108 | char buf[BNXE_LOG_LEN]; |
| 109 | |
| 110 | #ifdef DBG |
| 111 | if ((pUM->devParams.debug_level & LV_MASK) < LV_WARN) |
| 112 | { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | snprintf(buf, sizeof(buf), fmt, arg1, arg2); |
| 117 | cmn_err(CE_NOTE, "!%s: ELINK %s", BnxeDevName(pUM), buf); |
| 118 | #endif |
| 119 | } |
| 120 | |
| 121 | |
| 122 | void elink_cb_dbg3(struct elink_dev * bp, char * fmt, u32 arg1, u32 arg2, u32 arg3) |
| 123 | { |
| 124 | um_device_t * pUM = (um_device_t *)bp; |
| 125 | char buf[BNXE_LOG_LEN]; |
| 126 | |
| 127 | #ifdef DBG |
| 128 | if ((pUM->devParams.debug_level & LV_MASK) < LV_WARN) |
| 129 | { |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | snprintf(buf, sizeof(buf), fmt, arg1, arg2, arg3); |
| 134 | cmn_err(CE_NOTE, "!%s: ELINK %s", BnxeDevName(pUM), buf); |
| 135 | #endif |
| 136 | } |
| 137 | |
| 138 | |
| 139 | void BnxeLogInfo(void * pDev, |
| 140 | char * pFmt, |
| 141 | ...) |
| 142 | { |
| 143 | um_device_t * pUM = (um_device_t *)pDev; |
| 144 | char buf[BNXE_LOG_LEN]; |
| 145 | va_list argp; |
| 146 | |
| 147 | /* |
| 148 | * Info message are logged to syslog only if logEnable is |
| 149 | * turned on. They are never logged to the console. If |
| 150 | * pUM is NULL then the log is allowed through as if logEnable |
| 151 | * was turned on. |
| 152 | */ |
| 153 | |
| 154 | if (pUM && !pUM->devParams.logEnable) |
| 155 | { |
| 156 | return; |
| 157 | } |
| 158 | /* if !pUM then let the log through */ |
| 159 | |
| 160 | va_start(argp, pFmt); |
| 161 | vsnprintf(buf, sizeof(buf), pFmt, argp); |
| 162 | va_end(argp); |
| 163 | |
| 164 | cmn_err(CE_NOTE, "!%s: %s", BnxeDevName(pUM), buf); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | void BnxeLogWarn(void * pDev, |
| 169 | char * pFmt, |
| 170 | ...) |
| 171 | { |
| 172 | um_device_t * pUM = (um_device_t *)pDev; |
| 173 | char buf[BNXE_LOG_LEN]; |
| 174 | va_list argp; |
| 175 | |
| 176 | /* |
| 177 | * Warning message are always logged to syslog. They are |
| 178 | * never logged to the console. |
| 179 | */ |
| 180 | |
| 181 | va_start(argp, pFmt); |
| 182 | vsnprintf(buf, sizeof(buf), pFmt, argp); |
| 183 | va_end(argp); |
| 184 | |
| 185 | cmn_err(CE_WARN, "!%s: %s", BnxeDevName(pUM), buf); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | #ifdef DBG |
| 190 | |
| 191 | void BnxeLogDbg(void * pDev, |
| 192 | char * pFmt, |
| 193 | ...) |
| 194 | { |
| 195 | um_device_t * pUM = (um_device_t *)pDev; |
| 196 | char buf[BNXE_LOG_LEN]; |
| 197 | va_list argp; |
| 198 | |
| 199 | /* |
| 200 | * Debug message are always logged to syslog. They are |
| 201 | * never logged to the console. Debug messages are only |
| 202 | * available when the DEBUG compile time flag is turned on. |
| 203 | */ |
| 204 | |
| 205 | va_start(argp, pFmt); |
| 206 | vsnprintf(buf, sizeof(buf), pFmt, argp); |
| 207 | va_end(argp); |
| 208 | |
| 209 | cmn_err(CE_WARN, "!%s: %s", BnxeDevName(pUM), buf); |
| 210 | } |
| 211 | |
| 212 | #endif /* DBG */ |
| 213 | |
| 214 | |
| 215 | void BnxeDumpMem(um_device_t * pUM, |
| 216 | char * pTag, |
| 217 | u8_t * pMem, |
| 218 | u32_t len) |
| 219 | { |
| 220 | char buf[256]; |
| 221 | char c[32]; |
| 222 | int xx; |
| 223 | |
| 224 | mutex_enter(&bnxeLoaderMutex); |
| 225 | |
| 226 | cmn_err(CE_WARN, "!%s ++++++++++++ %s", BnxeDevName(pUM), pTag); |
| 227 | strcpy(buf, "!** 000: "); |
| 228 | |
| 229 | for (xx = 0; xx < len; xx++) |
| 230 | { |
| 231 | if ((xx != 0) && (xx % 16 == 0)) |
| 232 | { |
| 233 | cmn_err(CE_WARN, buf); |
| 234 | strcpy(buf, "!** "); |
| 235 | snprintf(c, sizeof(c), "%03x", xx); |
| 236 | strcat(buf, c); |
| 237 | strcat(buf, ": "); |
| 238 | } |
| 239 | |
| 240 | snprintf(c, sizeof(c), "%02x ", *pMem); |
| 241 | strcat(buf, c); |
| 242 | |
| 243 | pMem++; |
| 244 | } |
| 245 | |
| 246 | cmn_err(CE_WARN, buf); |
| 247 | cmn_err(CE_WARN, "!%s ------------ %s", BnxeDevName(pUM), pTag); |
| 248 | |
| 249 | mutex_exit(&bnxeLoaderMutex); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void BnxeDumpPkt(um_device_t * pUM, |
| 254 | char * pTag, |
| 255 | mblk_t * pMblk, |
| 256 | boolean_t contents) |
| 257 | { |
| 258 | char buf[256]; |
| 259 | char c[32]; |
| 260 | u8_t * pMem; |
| 261 | int i, xx = 0; |
| 262 | |
| 263 | mutex_enter(&bnxeLoaderMutex); |
| 264 | |
| 265 | cmn_err(CE_WARN, "!%s ++++++++++++ %s", BnxeDevName(pUM), pTag); |
| 266 | |
| 267 | while (pMblk) |
| 268 | { |
| 269 | pMem = pMblk->b_rptr; |
| 270 | strcpy(buf, "!** > "); |
| 271 | snprintf(c, sizeof(c), "%03x", xx); |
| 272 | strcat(buf, c); |
| 273 | strcat(buf, ": "); |
| 274 | |
| 275 | if (contents) |
| 276 | { |
| 277 | for (i = 0; i < MBLKL(pMblk); i++) |
| 278 | { |
| 279 | if ((xx != 0) && (xx % 16 == 0)) |
| 280 | { |
| 281 | cmn_err(CE_WARN, buf); |
| 282 | strcpy(buf, "!** "); |
| 283 | snprintf(c, sizeof(c), "%03x", xx); |
| 284 | strcat(buf, c); |
| 285 | strcat(buf, ": "); |
| 286 | } |
| 287 | |
| 288 | snprintf(c, sizeof(c), "%02x ", *pMem); |
| 289 | strcat(buf, c); |
| 290 | |
| 291 | pMem++; |
| 292 | xx++; |
| 293 | } |
| 294 | } |
| 295 | else |
| 296 | { |
| 297 | snprintf(c, sizeof(c), "%d", (int)MBLKL(pMblk)); |
| 298 | strcat(buf, c); |
| 299 | xx += MBLKL(pMblk); |
| 300 | } |
| 301 | |
| 302 | cmn_err(CE_WARN, buf); |
| 303 | pMblk = pMblk->b_cont; |
| 304 | } |
| 305 | |
| 306 | cmn_err(CE_WARN, "!%s ------------ %s", BnxeDevName(pUM), pTag); |
| 307 | |
| 308 | mutex_exit(&bnxeLoaderMutex); |
| 309 | } |