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