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