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