1 /*- 2 * Debug routines for LSI '909 FC adapters. 3 * FreeBSD Version. 4 * 5 * Copyright (c) 2000, 2001 by Greg Ansley 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice immediately at the beginning of the file, without modification, 12 * this list of conditions, and the following disclaimer. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * Additional Copyright (c) 2002 by Matthew Jacob under same license. 29 */ 30 31 #include <sys/cdefs.h> 32 __FBSDID("$FreeBSD$"); 33 34 #include <dev/mpt/mpt.h> 35 36 #include <dev/mpt/mpilib/mpi_ioc.h> 37 #include <dev/mpt/mpilib/mpi_init.h> 38 #include <dev/mpt/mpilib/mpi_fc.h> 39 40 #include <cam/scsi/scsi_all.h> 41 42 #include <machine/stdarg.h> /* for use by mpt_prt below */ 43 44 struct Error_Map { 45 int Error_Code; 46 char *Error_String; 47 }; 48 49 static const struct Error_Map IOC_Status[] = { 50 { MPI_IOCSTATUS_SUCCESS, "Success" }, 51 { MPI_IOCSTATUS_INVALID_FUNCTION, "IOC: Invalid Function" }, 52 { MPI_IOCSTATUS_BUSY, "IOC: Busy" }, 53 { MPI_IOCSTATUS_INVALID_SGL, "IOC: Invalid SGL" }, 54 { MPI_IOCSTATUS_INTERNAL_ERROR, "IOC: Internal Error" }, 55 { MPI_IOCSTATUS_RESERVED, "IOC: Reserved" }, 56 { MPI_IOCSTATUS_INSUFFICIENT_RESOURCES, "IOC: Insufficient Resources" }, 57 { MPI_IOCSTATUS_INVALID_FIELD, "IOC: Invalid Field" }, 58 { MPI_IOCSTATUS_INVALID_STATE, "IOC: Invalid State" }, 59 { MPI_IOCSTATUS_CONFIG_INVALID_ACTION, "Invalid Action" }, 60 { MPI_IOCSTATUS_CONFIG_INVALID_TYPE, "Invalid Type" }, 61 { MPI_IOCSTATUS_CONFIG_INVALID_PAGE, "Invalid Page" }, 62 { MPI_IOCSTATUS_CONFIG_INVALID_DATA, "Invalid Data" }, 63 { MPI_IOCSTATUS_CONFIG_NO_DEFAULTS, "No Defaults" }, 64 { MPI_IOCSTATUS_CONFIG_CANT_COMMIT, "Can't Commit" }, 65 { MPI_IOCSTATUS_SCSI_RECOVERED_ERROR, "SCSI: Recoverd Error" }, 66 { MPI_IOCSTATUS_SCSI_INVALID_BUS, "SCSI: Invalid Bus" }, 67 { MPI_IOCSTATUS_SCSI_INVALID_TARGETID, "SCSI: Invalid Target ID" }, 68 { MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE, "SCSI: Device Not There" }, 69 { MPI_IOCSTATUS_SCSI_DATA_OVERRUN, "SCSI: Data Overrun" }, 70 { MPI_IOCSTATUS_SCSI_DATA_UNDERRUN, "SCSI: Data Underrun" }, 71 { MPI_IOCSTATUS_SCSI_IO_DATA_ERROR, "SCSI: Data Error" }, 72 { MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR, "SCSI: Protocol Error" }, 73 { MPI_IOCSTATUS_SCSI_TASK_TERMINATED, "SCSI: Task Terminated" }, 74 { MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH, "SCSI: Residual Mismatch" }, 75 { MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED, "SCSI: Task Management Failed" }, 76 { MPI_IOCSTATUS_SCSI_IOC_TERMINATED, "SCSI: IOC Bus Reset" }, 77 { MPI_IOCSTATUS_SCSI_EXT_TERMINATED, "SCSI: External Bus Reset" }, 78 { MPI_IOCSTATUS_TARGET_PRIORITY_IO, "SCSI Target: Priority I/O" }, 79 { MPI_IOCSTATUS_TARGET_INVALID_PORT, "SCSI Target: Invalid Port" }, 80 { MPI_IOCSTATUS_TARGET_INVALID_IOCINDEX, "SCSI Target: Invalid IOC Index" }, 81 { MPI_IOCSTATUS_TARGET_ABORTED, "SCSI Target: Aborted" }, 82 { MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE, "SCSI Target: No Connection (Retryable)" }, 83 { MPI_IOCSTATUS_TARGET_NO_CONNECTION, "SCSI Target: No Connection" }, 84 { MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH,"SCSI Target: Transfer Count Mismatch" }, 85 { MPI_IOCSTATUS_TARGET_FC_ABORTED, "FC: Aborted" }, 86 { MPI_IOCSTATUS_TARGET_FC_RX_ID_INVALID, "FC: Recieve ID Invalid" }, 87 { MPI_IOCSTATUS_TARGET_FC_DID_INVALID, "FC: Recieve DID Invalid" }, 88 { MPI_IOCSTATUS_TARGET_FC_NODE_LOGGED_OUT,"FC: Node Logged Out" }, 89 { MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND, "LAN: Device Not Found" }, 90 { MPI_IOCSTATUS_LAN_DEVICE_FAILURE, "LAN: Device Not Failure" }, 91 { MPI_IOCSTATUS_LAN_TRANSMIT_ERROR, "LAN: Transmit Error" }, 92 { MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED, "LAN: Transmit Aborted" }, 93 { MPI_IOCSTATUS_LAN_RECEIVE_ERROR, "LAN: Recieve Error" }, 94 { MPI_IOCSTATUS_LAN_RECEIVE_ABORTED, "LAN: Recieve Aborted" }, 95 { MPI_IOCSTATUS_LAN_PARTIAL_PACKET, "LAN: Partial Packet" }, 96 { MPI_IOCSTATUS_LAN_CANCELED, "LAN: Canceled" }, 97 { -1, 0}, 98 }; 99 100 static const struct Error_Map IOC_Func[] = { 101 { MPI_FUNCTION_SCSI_IO_REQUEST, "SCSI IO Request" }, 102 { MPI_FUNCTION_SCSI_TASK_MGMT, "SCSI Task Management" }, 103 { MPI_FUNCTION_IOC_INIT, "IOC Init" }, 104 { MPI_FUNCTION_IOC_FACTS, "IOC Facts" }, 105 { MPI_FUNCTION_CONFIG, "Config" }, 106 { MPI_FUNCTION_PORT_FACTS, "Port Facts" }, 107 { MPI_FUNCTION_PORT_ENABLE, "Port Enable" }, 108 { MPI_FUNCTION_EVENT_NOTIFICATION, "Event Notification" }, 109 { MPI_FUNCTION_EVENT_ACK, "Event Ack" }, 110 { MPI_FUNCTION_FW_DOWNLOAD, "FW Download" }, 111 { MPI_FUNCTION_TARGET_CMD_BUFFER_POST, "SCSI Target Command Buffer" }, 112 { MPI_FUNCTION_TARGET_ASSIST, "Target Assist" }, 113 { MPI_FUNCTION_TARGET_STATUS_SEND, "Target Status Send" }, 114 { MPI_FUNCTION_TARGET_MODE_ABORT, "Target Mode Abort" }, 115 { -1, 0}, 116 }; 117 118 static const struct Error_Map IOC_Event[] = { 119 { MPI_EVENT_NONE, "None" }, 120 { MPI_EVENT_LOG_DATA, "LogData" }, 121 { MPI_EVENT_STATE_CHANGE, "State Change" }, 122 { MPI_EVENT_UNIT_ATTENTION, "Unit Attention" }, 123 { MPI_EVENT_IOC_BUS_RESET, "IOC Bus Reset" }, 124 { MPI_EVENT_EXT_BUS_RESET, "External Bus Reset" }, 125 { MPI_EVENT_RESCAN, "Rescan" }, 126 { MPI_EVENT_LINK_STATUS_CHANGE, "Link Status Change" }, 127 { MPI_EVENT_LOOP_STATE_CHANGE, "Loop State Change" }, 128 { MPI_EVENT_LOGOUT, "Logout" }, 129 { MPI_EVENT_EVENT_CHANGE, "EventChange" }, 130 { -1, 0}, 131 }; 132 133 static const struct Error_Map IOC_SCSIState[] = { 134 { MPI_SCSI_STATE_AUTOSENSE_VALID, "AutoSense_Valid" }, 135 { MPI_SCSI_STATE_AUTOSENSE_FAILED, "AutoSense_Failed" }, 136 { MPI_SCSI_STATE_NO_SCSI_STATUS, "No_SCSI_Status" }, 137 { MPI_SCSI_STATE_TERMINATED, "State_Terminated" }, 138 { MPI_SCSI_STATE_RESPONSE_INFO_VALID, "Repsonse_Info_Valid" }, 139 { MPI_SCSI_STATE_QUEUE_TAG_REJECTED, "Queue Tag Rejected" }, 140 { -1, 0}, 141 }; 142 143 static const struct Error_Map IOC_SCSIStatus[] = { 144 { SCSI_STATUS_OK, "OK" }, 145 { SCSI_STATUS_CHECK_COND, "Check Condition" }, 146 { SCSI_STATUS_COND_MET, "Check Condition Met" }, 147 { SCSI_STATUS_BUSY, "Busy" }, 148 { SCSI_STATUS_INTERMED, "Intermidiate Condition" }, 149 { SCSI_STATUS_INTERMED_COND_MET, "Intermidiate Condition Met" }, 150 { SCSI_STATUS_RESERV_CONFLICT, "Reservation Conflict" }, 151 { SCSI_STATUS_CMD_TERMINATED, "Command Terminated" }, 152 { SCSI_STATUS_QUEUE_FULL, "Queue Full" }, 153 { -1, 0}, 154 }; 155 156 static const struct Error_Map IOC_Diag[] = { 157 { MPI_DIAG_DRWE, "DWE" }, 158 { MPI_DIAG_FLASH_BAD_SIG, "FLASH_Bad" }, 159 { MPI_DIAGNOSTIC_OFFSET, "Offset" }, 160 { MPI_DIAG_RESET_ADAPTER, "Reset" }, 161 { MPI_DIAG_DISABLE_ARM, "DisARM" }, 162 { MPI_DIAG_MEM_ENABLE, "DME" }, 163 { -1, 0 }, 164 }; 165 166 static const struct Error_Map IOC_SCSITMType[] = { 167 { MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK, "Abort Task" }, 168 { MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, "Abort Task Set" }, 169 { MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, "Target Reset" }, 170 { MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, "Reset Bus" }, 171 { MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, "Logical Unit Reset" }, 172 { -1, 0 }, 173 }; 174 175 static void mpt_dump_sgl(SGE_IO_UNION *sgl); 176 177 static char * 178 mpt_ioc_status(int code) 179 { 180 const struct Error_Map *status = IOC_Status; 181 static char buf[64]; 182 while (status->Error_Code >= 0) { 183 if (status->Error_Code == (code & MPI_IOCSTATUS_MASK)) 184 return status->Error_String; 185 status++; 186 } 187 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code); 188 return buf; 189 } 190 191 char * 192 mpt_ioc_diag(u_int32_t code) 193 { 194 const struct Error_Map *status = IOC_Diag; 195 static char buf[128]; 196 char *ptr = buf; 197 char *end = &buf[128]; 198 buf[0] = '\0'; 199 ptr += snprintf(buf, sizeof buf, "(0x%08x)", code); 200 while (status->Error_Code >= 0) { 201 if ((status->Error_Code & code) != 0) 202 ptr += snprintf(ptr, (size_t)(end-ptr), "%s ", 203 status->Error_String); 204 status++; 205 } 206 return buf; 207 } 208 209 static char * 210 mpt_ioc_function(int code) 211 { 212 const struct Error_Map *status = IOC_Func; 213 static char buf[64]; 214 while (status->Error_Code >= 0) { 215 if (status->Error_Code == code) 216 return status->Error_String; 217 status++; 218 } 219 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code); 220 return buf; 221 } 222 static char * 223 mpt_ioc_event(int code) 224 { 225 const struct Error_Map *status = IOC_Event; 226 static char buf[64]; 227 while (status->Error_Code >= 0) { 228 if (status->Error_Code == code) 229 return status->Error_String; 230 status++; 231 } 232 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code); 233 return buf; 234 } 235 static char * 236 mpt_scsi_state(int code) 237 { 238 const struct Error_Map *status = IOC_SCSIState; 239 static char buf[128]; 240 char *ptr = buf; 241 char *end = &buf[128]; 242 buf[0] = '\0'; 243 ptr += snprintf(buf, sizeof buf, "(0x%08x)", code); 244 while (status->Error_Code >= 0) { 245 if ((status->Error_Code & code) != 0) 246 ptr += snprintf(ptr, (size_t)(end-ptr), "%s ", 247 status->Error_String); 248 status++; 249 } 250 return buf; 251 } 252 static char * 253 mpt_scsi_status(int code) 254 { 255 const struct Error_Map *status = IOC_SCSIStatus; 256 static char buf[64]; 257 while (status->Error_Code >= 0) { 258 if (status->Error_Code == code) 259 return status->Error_String; 260 status++; 261 } 262 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code); 263 return buf; 264 } 265 static char * 266 mpt_who(int who_init) 267 { 268 char *who; 269 270 switch (who_init) { 271 case MPT_DB_INIT_NOONE: who = "No One"; break; 272 case MPT_DB_INIT_BIOS: who = "BIOS"; break; 273 case MPT_DB_INIT_ROMBIOS: who = "ROM BIOS"; break; 274 case MPT_DB_INIT_PCIPEER: who = "PCI Peer"; break; 275 case MPT_DB_INIT_HOST: who = "Host Driver"; break; 276 case MPT_DB_INIT_MANUFACTURE: who = "Manufacturing"; break; 277 default: who = "Unknown"; break; 278 } 279 return who; 280 } 281 282 static char * 283 mpt_state(u_int32_t mb) 284 { 285 char *text; 286 287 switch (MPT_STATE(mb)) { 288 case MPT_DB_STATE_RESET: text = "Reset"; break; 289 case MPT_DB_STATE_READY: text = "Ready"; break; 290 case MPT_DB_STATE_RUNNING:text = "Running"; break; 291 case MPT_DB_STATE_FAULT: text = "Fault"; break; 292 default: text = "Unknown"; break; 293 } 294 return text; 295 } 296 297 static char * 298 mpt_scsi_tm_type(int code) 299 { 300 const struct Error_Map *status = IOC_SCSITMType; 301 static char buf[64]; 302 while (status->Error_Code >= 0) { 303 if (status->Error_Code == code) 304 return status->Error_String; 305 status++; 306 } 307 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code); 308 return buf; 309 } 310 311 void 312 mpt_print_db(u_int32_t mb) 313 { 314 printf("mpt mailbox: (0x%x) State %s WhoInit %s\n", 315 mb, mpt_state(mb), mpt_who(MPT_WHO(mb))); 316 } 317 318 /*****************************************************************************/ 319 /* Reply functions */ 320 /*****************************************************************************/ 321 static void 322 mpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg) 323 { 324 printf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg); 325 printf("\tIOC Status %s\n", mpt_ioc_status(msg->IOCStatus)); 326 printf("\tIOCLogInfo 0x%08x\n", msg->IOCLogInfo); 327 printf("\tMsgLength 0x%02x\n", msg->MsgLength); 328 printf("\tMsgFlags 0x%02x\n", msg->MsgFlags); 329 printf("\tMsgContext 0x%08x\n", msg->MsgContext); 330 } 331 332 static void 333 mpt_print_init_reply(MSG_IOC_INIT_REPLY *msg) 334 { 335 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg); 336 printf("\tWhoInit %s\n", mpt_who(msg->WhoInit)); 337 printf("\tMaxDevices 0x%02x\n", msg->MaxDevices); 338 printf("\tMaxBuses 0x%02x\n", msg->MaxBuses); 339 } 340 341 static void 342 mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg) 343 { 344 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg); 345 printf("\tIOCNumber %d\n", msg->IOCNumber); 346 printf("\tMaxChainDepth %d\n", msg->MaxChainDepth); 347 printf("\tWhoInit %s\n", mpt_who(msg->WhoInit)); 348 printf("\tBlockSize %d\n", msg->BlockSize); 349 printf("\tFlags %d\n", msg->Flags); 350 printf("\tReplyQueueDepth %d\n", msg->ReplyQueueDepth); 351 printf("\tReqFrameSize 0x%04x\n", msg->RequestFrameSize); 352 printf("\tFW Version 0x%08x\n", msg->FWVersion.Word); 353 printf("\tProduct ID 0x%04x\n", msg->ProductID); 354 printf("\tCredits 0x%04x\n", msg->GlobalCredits); 355 printf("\tPorts %d\n", msg->NumberOfPorts); 356 printf("\tEventState 0x%02x\n", msg->EventState); 357 printf("\tHostMFA_HA 0x%08x\n", msg->CurrentHostMfaHighAddr); 358 printf("\tSenseBuf_HA 0x%08x\n", 359 msg->CurrentSenseBufferHighAddr); 360 printf("\tRepFrameSize 0x%04x\n", msg->CurReplyFrameSize); 361 printf("\tMaxDevices 0x%02x\n", msg->MaxDevices); 362 printf("\tMaxBuses 0x%02x\n", msg->MaxBuses); 363 printf("\tFWImageSize 0x%04x\n", msg->FWImageSize); 364 } 365 366 static void 367 mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg) 368 { 369 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg); 370 printf("\tPort: %d\n", msg->PortNumber); 371 } 372 373 static void 374 mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg) 375 { 376 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg); 377 printf("\tBus: %d\n", msg->Bus); 378 printf("\tTargetID %d\n", msg->TargetID); 379 printf("\tCDBLength %d\n", msg->CDBLength); 380 printf("\tSCSI Status: %s\n", mpt_scsi_status(msg->SCSIStatus)); 381 printf("\tSCSI State: %s\n", mpt_scsi_state(msg->SCSIState)); 382 printf("\tTransferCnt 0x%04x\n", msg->TransferCount); 383 printf("\tSenseCnt 0x%04x\n", msg->SenseCount); 384 printf("\tResponseInfo 0x%08x\n", msg->ResponseInfo); 385 } 386 387 388 389 static void 390 mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg) 391 { 392 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg); 393 printf("\tEvent: %s\n", mpt_ioc_event(msg->Event)); 394 printf("\tEventContext 0x%04x\n", msg->EventContext); 395 printf("\tAckRequired %d\n", msg->AckRequired); 396 printf("\tEventDataLength %d\n", msg->EventDataLength); 397 printf("\tContinuation %d\n", msg->MsgFlags & 0x80); 398 switch(msg->Event) { 399 case MPI_EVENT_LOG_DATA: 400 printf("\tEvtLogData: 0x%04x\n", msg->Data[0]); 401 break; 402 403 case MPI_EVENT_UNIT_ATTENTION: 404 printf("\tTargetID: 0x%04x\n", 405 msg->Data[0] & 0xff); 406 printf("\tBus: 0x%04x\n", 407 (msg->Data[0] >> 8) & 0xff); 408 break; 409 410 case MPI_EVENT_IOC_BUS_RESET: 411 case MPI_EVENT_EXT_BUS_RESET: 412 case MPI_EVENT_RESCAN: 413 printf("\tPort: %d\n", 414 (msg->Data[0] >> 8) & 0xff); 415 break; 416 417 case MPI_EVENT_LINK_STATUS_CHANGE: 418 printf("\tLinkState: %d\n", 419 msg->Data[0] & 0xff); 420 printf("\tPort: %d\n", 421 (msg->Data[1] >> 8) & 0xff); 422 break; 423 424 case MPI_EVENT_LOOP_STATE_CHANGE: 425 printf("\tType: %d\n", 426 (msg->Data[0] >> 16) & 0xff); 427 printf("\tChar3: 0x%02x\n", 428 (msg->Data[0] >> 8) & 0xff); 429 printf("\tChar4: 0x%02x\n", 430 (msg->Data[0] ) & 0xff); 431 printf("\tPort: %d\n", 432 (msg->Data[1] >> 8) & 0xff); 433 break; 434 435 case MPI_EVENT_LOGOUT: 436 printf("\tN_PortId: 0x%04x\n", msg->Data[0]); 437 printf("\tPort: %d\n", 438 (msg->Data[1] >> 8) & 0xff); 439 break; 440 } 441 442 } 443 444 void 445 mpt_print_reply(void *vmsg) 446 { 447 MSG_DEFAULT_REPLY *msg = vmsg; 448 449 switch (msg->Function) { 450 case MPI_FUNCTION_EVENT_NOTIFICATION: 451 mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg); 452 break; 453 case MPI_FUNCTION_PORT_ENABLE: 454 mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg); 455 break; 456 case MPI_FUNCTION_IOC_FACTS: 457 mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg); 458 break; 459 case MPI_FUNCTION_IOC_INIT: 460 mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg); 461 break; 462 case MPI_FUNCTION_SCSI_IO_REQUEST: 463 mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg); 464 break; 465 default: 466 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg); 467 break; 468 } 469 } 470 471 /*****************************************************************************/ 472 /* Request functions */ 473 /*****************************************************************************/ 474 static void 475 mpt_print_request_hdr(MSG_REQUEST_HEADER *req) 476 { 477 printf("%s @ %p\n", mpt_ioc_function(req->Function), req); 478 printf("\tChain Offset 0x%02x\n", req->ChainOffset); 479 printf("\tMsgFlags 0x%02x\n", req->MsgFlags); 480 printf("\tMsgContext 0x%08x\n", req->MsgContext); 481 } 482 483 void 484 mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg) 485 { 486 MSG_SCSI_IO_REQUEST local, *msg = &local; 487 int i; 488 489 bcopy(orig_msg, msg, sizeof (MSG_SCSI_IO_REQUEST)); 490 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg); 491 printf("\tBus: %d\n", msg->Bus); 492 printf("\tTargetID %d\n", msg->TargetID); 493 printf("\tSenseBufferLength %d\n", msg->SenseBufferLength); 494 printf("\tLUN: 0x%0x\n", msg->LUN[1]); 495 printf("\tControl 0x%08x ", msg->Control); 496 #define MPI_PRINT_FIELD(x) \ 497 case MPI_SCSIIO_CONTROL_ ## x : \ 498 printf(" " #x " "); \ 499 break 500 501 switch (msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) { 502 MPI_PRINT_FIELD(NODATATRANSFER); 503 MPI_PRINT_FIELD(WRITE); 504 MPI_PRINT_FIELD(READ); 505 default: 506 printf(" Invalid DIR! "); 507 break; 508 } 509 switch (msg->Control & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) { 510 MPI_PRINT_FIELD(SIMPLEQ); 511 MPI_PRINT_FIELD(HEADOFQ); 512 MPI_PRINT_FIELD(ORDEREDQ); 513 MPI_PRINT_FIELD(ACAQ); 514 MPI_PRINT_FIELD(UNTAGGED); 515 MPI_PRINT_FIELD(NO_DISCONNECT); 516 default: 517 printf(" Unknown attribute! "); 518 break; 519 } 520 521 printf("\n"); 522 #undef MPI_PRINT_FIELD 523 524 printf("\tDataLength\t0x%08x\n", msg->DataLength); 525 printf("\tSenseBufAddr\t0x%08x\n", msg->SenseBufferLowAddr); 526 printf("\tCDB[0:%d]\t", msg->CDBLength); 527 for (i = 0; i < msg->CDBLength; i++) 528 printf("%02x ", msg->CDB[i]); 529 printf("\n"); 530 mpt_dump_sgl(&orig_msg->SGL); 531 } 532 533 static void 534 mpt_print_scsi_tmf_request(MSG_SCSI_TASK_MGMT *msg) 535 { 536 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg); 537 printf("\tLun 0x%02x\n", msg->LUN[1]); 538 printf("\tTaskType %s\n", mpt_scsi_tm_type(msg->TaskType)); 539 printf("\tTaskMsgContext 0x%08x\n", msg->TaskMsgContext); 540 } 541 542 void 543 mpt_print_request(void *vreq) 544 { 545 MSG_REQUEST_HEADER *req = vreq; 546 547 switch (req->Function) { 548 case MPI_FUNCTION_SCSI_IO_REQUEST: 549 mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req); 550 break; 551 case MPI_FUNCTION_SCSI_TASK_MGMT: 552 mpt_print_scsi_tmf_request((MSG_SCSI_TASK_MGMT *)req); 553 default: 554 mpt_print_request_hdr(req); 555 break; 556 } 557 } 558 559 int 560 mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries, 561 const char *name, u_int value, u_int *cur_column, 562 u_int wrap_point) 563 { 564 int printed; 565 u_int printed_mask; 566 u_int dummy_column; 567 568 if (cur_column == NULL) { 569 dummy_column = 0; 570 cur_column = &dummy_column; 571 } 572 573 if (*cur_column >= wrap_point) { 574 printf("\n"); 575 *cur_column = 0; 576 } 577 printed = printf("%s[0x%x]", name, value); 578 if (table == NULL) { 579 printed += printf(" "); 580 *cur_column += printed; 581 return (printed); 582 } 583 printed_mask = 0; 584 while (printed_mask != 0xFF) { 585 int entry; 586 587 for (entry = 0; entry < num_entries; entry++) { 588 if (((value & table[entry].mask) 589 != table[entry].value) 590 || ((printed_mask & table[entry].mask) 591 == table[entry].mask)) 592 continue; 593 594 printed += printf("%s%s", 595 printed_mask == 0 ? ":(" : "|", 596 table[entry].name); 597 printed_mask |= table[entry].mask; 598 break; 599 } 600 if (entry >= num_entries) 601 break; 602 } 603 if (printed_mask != 0) 604 printed += printf(") "); 605 else 606 printed += printf(" "); 607 *cur_column += printed; 608 return (printed); 609 } 610 611 static mpt_decode_entry_t req_state_parse_table[] = { 612 { "REQ_FREE", 0x00, 0xff }, 613 { "REQ_ALLOCATED", 0x01, 0x01 }, 614 { "REQ_QUEUED", 0x02, 0x02 }, 615 { "REQ_DONE", 0x04, 0x04 }, 616 { "REQ_TIMEDOUT", 0x08, 0x08 }, 617 { "REQ_NEED_WAKEUP", 0x10, 0x10 } 618 }; 619 620 void 621 mpt_req_state(mpt_req_state_t state) 622 { 623 mpt_decode_value(req_state_parse_table, 624 NUM_ELEMENTS(req_state_parse_table), 625 "REQ_STATE", state, NULL, 80); 626 } 627 628 static void 629 mpt_dump_sgl(SGE_IO_UNION *su) 630 { 631 SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su; 632 int iCount, flags; 633 634 iCount = MPT_SGL_MAX; 635 do { 636 int iprt; 637 638 printf("\t"); 639 flags = MPI_SGE_GET_FLAGS(se->FlagsLength); 640 switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) { 641 case MPI_SGE_FLAGS_SIMPLE_ELEMENT: 642 { 643 printf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x\n", 644 se, se->Address, se->FlagsLength); 645 printf(" "); 646 break; 647 } 648 case MPI_SGE_FLAGS_CHAIN_ELEMENT: 649 { 650 SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se; 651 printf("CE32 %p: Addr=0x%0x NxtChnO=0x%x Flgs=0x%x " 652 "Len=0x%0x\n", ce, ce->Address, ce->NextChainOffset, 653 ce->Flags, ce->Length); 654 flags = 0; 655 break; 656 } 657 case MPI_SGE_FLAGS_TRANSACTION_ELEMENT: 658 printf("TE32 @ %p\n", se); 659 flags = 0; 660 break; 661 } 662 iprt = 0; 663 #define MPT_PRINT_FLAG(x) \ 664 if (flags & MPI_SGE_FLAGS_ ## x ) { \ 665 if (iprt == 0) { \ 666 printf("\t"); \ 667 } \ 668 printf(" "); \ 669 printf( #x ); \ 670 iprt++; \ 671 } 672 MPT_PRINT_FLAG(LOCAL_ADDRESS); 673 MPT_PRINT_FLAG(HOST_TO_IOC); 674 MPT_PRINT_FLAG(64_BIT_ADDRESSING); 675 MPT_PRINT_FLAG(LAST_ELEMENT); 676 MPT_PRINT_FLAG(END_OF_BUFFER); 677 MPT_PRINT_FLAG(END_OF_LIST); 678 #undef MPT_PRINT_FLAG 679 if (iprt) 680 printf("\n"); 681 se++; 682 iCount -= 1; 683 } while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && iCount != 0); 684 } 685 686 void 687 mpt_prt(struct mpt_softc *mpt, const char *fmt, ...) 688 { 689 va_list ap; 690 691 printf("%s: ", device_get_nameunit(mpt->dev)); 692 va_start(ap, fmt); 693 vprintf(fmt, ap); 694 va_end(ap); 695 } 696 697 void 698 mpt_prtc(struct mpt_softc *mpt, const char *fmt, ...) 699 { 700 va_list ap; 701 702 va_start(ap, fmt); 703 vprintf(fmt, ap); 704 va_end(ap); 705 } 706