2 * Debug routines for LSI '909 FC adapters.
5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-3-Clause
7 * Copyright (c) 2000, 2001 by Greg Ansley
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice immediately at the beginning of the file, without modification,
14 * this list of conditions, and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Copyright (c) 2002, 2006 by Matthew Jacob
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions are
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
41 * substantially similar to the "NO WARRANTY" disclaimer below
42 * ("Disclaimer") and any redistribution must be conditioned upon including
43 * a substantially similar Disclaimer requirement for further binary
45 * 3. Neither the names of the above listed copyright holders nor the names
46 * of any contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
50 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
53 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
59 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 * Support from Chris Ellsworth in order to make SAS adapters work
62 * is gratefully acknowledged.
64 * Support from LSI-Logic has also gone a great deal toward making this a
65 * workable subsystem and is gratefully acknowledged.
68 #include <sys/cdefs.h>
69 __FBSDID("$FreeBSD$");
71 #include <dev/mpt/mpt.h>
73 #include <dev/mpt/mpilib/mpi_ioc.h>
74 #include <dev/mpt/mpilib/mpi_init.h>
75 #include <dev/mpt/mpilib/mpi_fc.h>
76 #include <dev/mpt/mpilib/mpi_targ.h>
78 #include <cam/scsi/scsi_all.h>
80 #include <machine/stdarg.h> /* for use by mpt_prt below */
87 static const struct Error_Map IOC_Status[] = {
88 { MPI_IOCSTATUS_SUCCESS, "Success" },
89 { MPI_IOCSTATUS_INVALID_FUNCTION, "IOC: Invalid Function" },
90 { MPI_IOCSTATUS_BUSY, "IOC: Busy" },
91 { MPI_IOCSTATUS_INVALID_SGL, "IOC: Invalid SGL" },
92 { MPI_IOCSTATUS_INTERNAL_ERROR, "IOC: Internal Error" },
93 { MPI_IOCSTATUS_RESERVED, "IOC: Reserved" },
94 { MPI_IOCSTATUS_INSUFFICIENT_RESOURCES, "IOC: Insufficient Resources" },
95 { MPI_IOCSTATUS_INVALID_FIELD, "IOC: Invalid Field" },
96 { MPI_IOCSTATUS_INVALID_STATE, "IOC: Invalid State" },
97 { MPI_IOCSTATUS_CONFIG_INVALID_ACTION, "Invalid Action" },
98 { MPI_IOCSTATUS_CONFIG_INVALID_TYPE, "Invalid Type" },
99 { MPI_IOCSTATUS_CONFIG_INVALID_PAGE, "Invalid Page" },
100 { MPI_IOCSTATUS_CONFIG_INVALID_DATA, "Invalid Data" },
101 { MPI_IOCSTATUS_CONFIG_NO_DEFAULTS, "No Defaults" },
102 { MPI_IOCSTATUS_CONFIG_CANT_COMMIT, "Can't Commit" },
103 { MPI_IOCSTATUS_SCSI_RECOVERED_ERROR, "SCSI: Recoverd Error" },
104 { MPI_IOCSTATUS_SCSI_INVALID_BUS, "SCSI: Invalid Bus" },
105 { MPI_IOCSTATUS_SCSI_INVALID_TARGETID, "SCSI: Invalid Target ID" },
106 { MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE, "SCSI: Device Not There" },
107 { MPI_IOCSTATUS_SCSI_DATA_OVERRUN, "SCSI: Data Overrun" },
108 { MPI_IOCSTATUS_SCSI_DATA_UNDERRUN, "SCSI: Data Underrun" },
109 { MPI_IOCSTATUS_SCSI_IO_DATA_ERROR, "SCSI: Data Error" },
110 { MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR, "SCSI: Protocol Error" },
111 { MPI_IOCSTATUS_SCSI_TASK_TERMINATED, "SCSI: Task Terminated" },
112 { MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH, "SCSI: Residual Mismatch" },
113 { MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED, "SCSI: Task Management Failed" },
114 { MPI_IOCSTATUS_SCSI_IOC_TERMINATED, "SCSI: IOC Bus Reset" },
115 { MPI_IOCSTATUS_SCSI_EXT_TERMINATED, "SCSI: External Bus Reset" },
116 { MPI_IOCSTATUS_TARGET_PRIORITY_IO, "SCSI Target: Priority I/O" },
117 { MPI_IOCSTATUS_TARGET_INVALID_PORT, "SCSI Target: Invalid Port" },
118 { MPI_IOCSTATUS_TARGET_INVALID_IOCINDEX, "SCSI Target: Invalid IOC Index" },
119 { MPI_IOCSTATUS_TARGET_ABORTED, "SCSI Target: Aborted" },
120 { MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE, "SCSI Target: No Connection (Retryable)" },
121 { MPI_IOCSTATUS_TARGET_NO_CONNECTION, "SCSI Target: No Connection" },
122 { MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH,"SCSI Target: Transfer Count Mismatch" },
123 { MPI_IOCSTATUS_TARGET_FC_ABORTED, "FC: Aborted" },
124 { MPI_IOCSTATUS_TARGET_FC_RX_ID_INVALID, "FC: Receive ID Invalid" },
125 { MPI_IOCSTATUS_TARGET_FC_DID_INVALID, "FC: Receive DID Invalid" },
126 { MPI_IOCSTATUS_TARGET_FC_NODE_LOGGED_OUT,"FC: Node Logged Out" },
127 { MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND, "LAN: Device Not Found" },
128 { MPI_IOCSTATUS_LAN_DEVICE_FAILURE, "LAN: Device Not Failure" },
129 { MPI_IOCSTATUS_LAN_TRANSMIT_ERROR, "LAN: Transmit Error" },
130 { MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED, "LAN: Transmit Aborted" },
131 { MPI_IOCSTATUS_LAN_RECEIVE_ERROR, "LAN: Receive Error" },
132 { MPI_IOCSTATUS_LAN_RECEIVE_ABORTED, "LAN: Receive Aborted" },
133 { MPI_IOCSTATUS_LAN_PARTIAL_PACKET, "LAN: Partial Packet" },
134 { MPI_IOCSTATUS_LAN_CANCELED, "LAN: Canceled" },
138 static const struct Error_Map IOC_Func[] = {
139 { MPI_FUNCTION_SCSI_IO_REQUEST, "SCSI IO Request" },
140 { MPI_FUNCTION_SCSI_TASK_MGMT, "SCSI Task Management" },
141 { MPI_FUNCTION_IOC_INIT, "IOC Init" },
142 { MPI_FUNCTION_IOC_FACTS, "IOC Facts" },
143 { MPI_FUNCTION_CONFIG, "Config" },
144 { MPI_FUNCTION_PORT_FACTS, "Port Facts" },
145 { MPI_FUNCTION_PORT_ENABLE, "Port Enable" },
146 { MPI_FUNCTION_EVENT_NOTIFICATION, "Event Notification" },
147 { MPI_FUNCTION_EVENT_ACK, "Event Ack" },
148 { MPI_FUNCTION_FW_DOWNLOAD, "FW Download" },
149 { MPI_FUNCTION_TARGET_CMD_BUFFER_POST, "SCSI Target Command Buffer" },
150 { MPI_FUNCTION_TARGET_ASSIST, "Target Assist" },
151 { MPI_FUNCTION_TARGET_STATUS_SEND, "Target Status Send" },
152 { MPI_FUNCTION_TARGET_MODE_ABORT, "Target Mode Abort" },
156 static const struct Error_Map IOC_Event[] = {
157 { MPI_EVENT_NONE, "None" },
158 { MPI_EVENT_LOG_DATA, "LogData" },
159 { MPI_EVENT_STATE_CHANGE, "State Change" },
160 { MPI_EVENT_UNIT_ATTENTION, "Unit Attention" },
161 { MPI_EVENT_IOC_BUS_RESET, "IOC Bus Reset" },
162 { MPI_EVENT_EXT_BUS_RESET, "External Bus Reset" },
163 { MPI_EVENT_RESCAN, "Rescan" },
164 { MPI_EVENT_LINK_STATUS_CHANGE, "Link Status Change" },
165 { MPI_EVENT_LOOP_STATE_CHANGE, "Loop State Change" },
166 { MPI_EVENT_LOGOUT, "Logout" },
167 { MPI_EVENT_EVENT_CHANGE, "EventChange" },
171 static const struct Error_Map IOC_SCSIState[] = {
172 { MPI_SCSI_STATE_AUTOSENSE_VALID, "AutoSense_Valid" },
173 { MPI_SCSI_STATE_AUTOSENSE_FAILED, "AutoSense_Failed" },
174 { MPI_SCSI_STATE_NO_SCSI_STATUS, "No_SCSI_Status" },
175 { MPI_SCSI_STATE_TERMINATED, "State_Terminated" },
176 { MPI_SCSI_STATE_RESPONSE_INFO_VALID, "Repsonse_Info_Valid" },
177 { MPI_SCSI_STATE_QUEUE_TAG_REJECTED, "Queue Tag Rejected" },
181 static const struct Error_Map IOC_SCSIStatus[] = {
182 { SCSI_STATUS_OK, "OK" },
183 { SCSI_STATUS_CHECK_COND, "Check Condition" },
184 { SCSI_STATUS_COND_MET, "Check Condition Met" },
185 { SCSI_STATUS_BUSY, "Busy" },
186 { SCSI_STATUS_INTERMED, "Intermidiate Condition" },
187 { SCSI_STATUS_INTERMED_COND_MET, "Intermidiate Condition Met" },
188 { SCSI_STATUS_RESERV_CONFLICT, "Reservation Conflict" },
189 { SCSI_STATUS_CMD_TERMINATED, "Command Terminated" },
190 { SCSI_STATUS_QUEUE_FULL, "Queue Full" },
194 static const struct Error_Map IOC_Diag[] = {
195 { MPI_DIAG_DRWE, "DWE" },
196 { MPI_DIAG_FLASH_BAD_SIG, "FLASH_Bad" },
197 { MPI_DIAGNOSTIC_OFFSET, "Offset" },
198 { MPI_DIAG_RESET_ADAPTER, "Reset" },
199 { MPI_DIAG_DISABLE_ARM, "DisARM" },
200 { MPI_DIAG_MEM_ENABLE, "DME" },
204 static const struct Error_Map IOC_SCSITMType[] = {
205 { MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK, "Abort Task" },
206 { MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, "Abort Task Set" },
207 { MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, "Target Reset" },
208 { MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, "Reset Bus" },
209 { MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, "Logical Unit Reset" },
214 mpt_ioc_status(int code)
216 const struct Error_Map *status = IOC_Status;
218 while (status->Error_Code >= 0) {
219 if (status->Error_Code == (code & MPI_IOCSTATUS_MASK))
220 return status->Error_String;
223 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
228 mpt_ioc_diag(u_int32_t code)
230 const struct Error_Map *status = IOC_Diag;
231 static char buf[128];
233 char *end = &buf[128];
235 ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
236 while (status->Error_Code >= 0) {
237 if ((status->Error_Code & code) != 0)
238 ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
239 status->Error_String);
246 mpt_ioc_function(int code)
248 const struct Error_Map *status = IOC_Func;
250 while (status->Error_Code >= 0) {
251 if (status->Error_Code == code)
252 return status->Error_String;
255 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
260 mpt_ioc_event(int code)
262 const struct Error_Map *status = IOC_Event;
264 while (status->Error_Code >= 0) {
265 if (status->Error_Code == code)
266 return status->Error_String;
269 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
274 mpt_scsi_state(int code)
276 const struct Error_Map *status = IOC_SCSIState;
277 static char buf[128];
279 char *end = &buf[128];
281 ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
282 while (status->Error_Code >= 0) {
283 if ((status->Error_Code & code) != 0)
284 ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
285 status->Error_String);
292 mpt_scsi_status(int code)
294 const struct Error_Map *status = IOC_SCSIStatus;
296 while (status->Error_Code >= 0) {
297 if (status->Error_Code == code)
298 return status->Error_String;
301 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
306 mpt_who(int who_init)
311 case MPT_DB_INIT_NOONE: who = "No One"; break;
312 case MPT_DB_INIT_BIOS: who = "BIOS"; break;
313 case MPT_DB_INIT_ROMBIOS: who = "ROM BIOS"; break;
314 case MPT_DB_INIT_PCIPEER: who = "PCI Peer"; break;
315 case MPT_DB_INIT_HOST: who = "Host Driver"; break;
316 case MPT_DB_INIT_MANUFACTURE: who = "Manufacturing"; break;
317 default: who = "Unknown"; break;
323 mpt_state(u_int32_t mb)
327 switch (MPT_STATE(mb)) {
328 case MPT_DB_STATE_RESET: text = "Reset"; break;
329 case MPT_DB_STATE_READY: text = "Ready"; break;
330 case MPT_DB_STATE_RUNNING:text = "Running"; break;
331 case MPT_DB_STATE_FAULT: text = "Fault"; break;
332 default: text = "Unknown"; break;
338 mpt_scsi_tm_type(int code)
340 const struct Error_Map *status = IOC_SCSITMType;
342 while (status->Error_Code >= 0) {
343 if (status->Error_Code == code)
344 return status->Error_String;
347 snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
352 mpt_print_db(u_int32_t mb)
355 printf("mpt mailbox: (0x%x) State %s WhoInit %s\n",
356 mb, mpt_state(mb), mpt_who(MPT_WHO(mb)));
359 /*****************************************************************************/
360 /* Reply functions */
361 /*****************************************************************************/
363 mpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg)
366 printf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg);
367 printf("\tIOC Status %s\n", mpt_ioc_status(msg->IOCStatus));
368 printf("\tIOCLogInfo 0x%08x\n", msg->IOCLogInfo);
369 printf("\tMsgLength 0x%02x\n", msg->MsgLength);
370 printf("\tMsgFlags 0x%02x\n", msg->MsgFlags);
371 printf("\tMsgContext 0x%08x\n", msg->MsgContext);
375 mpt_print_init_reply(MSG_IOC_INIT_REPLY *msg)
378 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
379 printf("\tWhoInit %s\n", mpt_who(msg->WhoInit));
380 printf("\tMaxDevices 0x%02x\n", msg->MaxDevices);
381 printf("\tMaxBuses 0x%02x\n", msg->MaxBuses);
385 mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg)
388 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
389 printf("\tIOCNumber %d\n", msg->IOCNumber);
390 printf("\tMaxChainDepth %d\n", msg->MaxChainDepth);
391 printf("\tWhoInit %s\n", mpt_who(msg->WhoInit));
392 printf("\tBlockSize %d\n", msg->BlockSize);
393 printf("\tFlags %d\n", msg->Flags);
394 printf("\tReplyQueueDepth %d\n", msg->ReplyQueueDepth);
395 printf("\tReqFrameSize 0x%04x\n", msg->RequestFrameSize);
396 printf("\tFW Version 0x%08x\n", msg->FWVersion.Word);
397 printf("\tProduct ID 0x%04x\n", msg->ProductID);
398 printf("\tCredits 0x%04x\n", msg->GlobalCredits);
399 printf("\tPorts %d\n", msg->NumberOfPorts);
400 printf("\tEventState 0x%02x\n", msg->EventState);
401 printf("\tHostMFA_HA 0x%08x\n", msg->CurrentHostMfaHighAddr);
402 printf("\tSenseBuf_HA 0x%08x\n",
403 msg->CurrentSenseBufferHighAddr);
404 printf("\tRepFrameSize 0x%04x\n", msg->CurReplyFrameSize);
405 printf("\tMaxDevices 0x%02x\n", msg->MaxDevices);
406 printf("\tMaxBuses 0x%02x\n", msg->MaxBuses);
407 printf("\tFWImageSize 0x%04x\n", msg->FWImageSize);
411 mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg)
414 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
415 printf("\tPort: %d\n", msg->PortNumber);
419 mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg)
422 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
423 printf("\tBus: %d\n", msg->Bus);
424 printf("\tTargetID %d\n", msg->TargetID);
425 printf("\tCDBLength %d\n", msg->CDBLength);
426 printf("\tSCSI Status: %s\n", mpt_scsi_status(msg->SCSIStatus));
427 printf("\tSCSI State: %s\n", mpt_scsi_state(msg->SCSIState));
428 printf("\tTransferCnt 0x%04x\n", msg->TransferCount);
429 printf("\tSenseCnt 0x%04x\n", msg->SenseCount);
430 printf("\tResponseInfo 0x%08x\n", msg->ResponseInfo);
434 mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg)
437 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
438 printf("\tEvent: %s\n", mpt_ioc_event(msg->Event));
439 printf("\tEventContext 0x%04x\n", msg->EventContext);
440 printf("\tAckRequired %d\n", msg->AckRequired);
441 printf("\tEventDataLength %d\n", msg->EventDataLength);
442 printf("\tContinuation %d\n", msg->MsgFlags & 0x80);
444 case MPI_EVENT_LOG_DATA:
445 printf("\tEvtLogData: 0x%04x\n", msg->Data[0]);
448 case MPI_EVENT_UNIT_ATTENTION:
449 printf("\tTargetID: 0x%04x\n",
450 msg->Data[0] & 0xff);
451 printf("\tBus: 0x%04x\n",
452 (msg->Data[0] >> 8) & 0xff);
455 case MPI_EVENT_IOC_BUS_RESET:
456 case MPI_EVENT_EXT_BUS_RESET:
457 case MPI_EVENT_RESCAN:
458 printf("\tPort: %d\n",
459 (msg->Data[0] >> 8) & 0xff);
462 case MPI_EVENT_LINK_STATUS_CHANGE:
463 printf("\tLinkState: %d\n",
464 msg->Data[0] & 0xff);
465 printf("\tPort: %d\n",
466 (msg->Data[1] >> 8) & 0xff);
469 case MPI_EVENT_LOOP_STATE_CHANGE:
470 printf("\tType: %d\n",
471 (msg->Data[0] >> 16) & 0xff);
472 printf("\tChar3: 0x%02x\n",
473 (msg->Data[0] >> 8) & 0xff);
474 printf("\tChar4: 0x%02x\n",
475 (msg->Data[0] ) & 0xff);
476 printf("\tPort: %d\n",
477 (msg->Data[1] >> 8) & 0xff);
480 case MPI_EVENT_LOGOUT:
481 printf("\tN_PortId: 0x%04x\n", msg->Data[0]);
482 printf("\tPort: %d\n",
483 (msg->Data[1] >> 8) & 0xff);
490 mpt_print_reply(void *vmsg)
492 MSG_DEFAULT_REPLY *msg = vmsg;
494 switch (msg->Function) {
495 case MPI_FUNCTION_EVENT_NOTIFICATION:
496 mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg);
498 case MPI_FUNCTION_PORT_ENABLE:
499 mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg);
501 case MPI_FUNCTION_IOC_FACTS:
502 mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg);
504 case MPI_FUNCTION_IOC_INIT:
505 mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg);
507 case MPI_FUNCTION_SCSI_IO_REQUEST:
508 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
509 mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg);
512 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
517 /*****************************************************************************/
518 /* Request functions */
519 /*****************************************************************************/
521 mpt_print_request_hdr(MSG_REQUEST_HEADER *req)
524 printf("%s @ %p\n", mpt_ioc_function(req->Function), req);
525 printf("\tChain Offset 0x%02x\n", req->ChainOffset);
526 printf("\tMsgFlags 0x%02x\n", req->MsgFlags);
527 printf("\tMsgContext 0x%08x\n", req->MsgContext);
531 mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg)
533 MSG_SCSI_IO_REQUEST local, *msg = &local;
536 bcopy(orig_msg, msg, sizeof (MSG_SCSI_IO_REQUEST));
537 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
538 printf("\tBus: %d\n", msg->Bus);
539 printf("\tTargetID %d\n", msg->TargetID);
540 printf("\tSenseBufferLength %d\n", msg->SenseBufferLength);
541 printf("\tLUN: 0x%jx\n", (uintmax_t)be64dec(msg->LUN));
542 printf("\tControl 0x%08x ", msg->Control);
543 #define MPI_PRINT_FIELD(x) \
544 case MPI_SCSIIO_CONTROL_ ## x : \
545 printf(" " #x " "); \
548 switch (msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) {
549 MPI_PRINT_FIELD(NODATATRANSFER);
550 MPI_PRINT_FIELD(WRITE);
551 MPI_PRINT_FIELD(READ);
553 printf(" Invalid DIR! ");
556 switch (msg->Control & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) {
557 MPI_PRINT_FIELD(SIMPLEQ);
558 MPI_PRINT_FIELD(HEADOFQ);
559 MPI_PRINT_FIELD(ORDEREDQ);
560 MPI_PRINT_FIELD(ACAQ);
561 MPI_PRINT_FIELD(UNTAGGED);
562 MPI_PRINT_FIELD(NO_DISCONNECT);
564 printf(" Unknown attribute! ");
569 #undef MPI_PRINT_FIELD
571 printf("\tDataLength\t0x%08x\n", msg->DataLength);
572 printf("\tSenseBufAddr\t0x%08x\n", msg->SenseBufferLowAddr);
573 printf("\tCDB[0:%d]\t", msg->CDBLength);
574 for (i = 0; i < msg->CDBLength; i++)
575 printf("%02x ", msg->CDB[i]);
578 if ((msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) !=
579 MPI_SCSIIO_CONTROL_NODATATRANSFER ) {
580 mpt_dump_sgl(&orig_msg->SGL,
581 ((char *)&orig_msg->SGL)-(char *)orig_msg);
586 mpt_print_scsi_tmf_request(MSG_SCSI_TASK_MGMT *msg)
589 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
590 printf("\tLun 0x%jx\n", (uintmax_t)be64dec(msg->LUN));
591 printf("\tTaskType %s\n", mpt_scsi_tm_type(msg->TaskType));
592 printf("\tTaskMsgContext 0x%08x\n", msg->TaskMsgContext);
597 mpt_print_scsi_target_assist_request(PTR_MSG_TARGET_ASSIST_REQUEST msg)
600 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
601 printf("\tStatusCode 0x%02x\n", msg->StatusCode);
602 printf("\tTargetAssist 0x%02x\n", msg->TargetAssistFlags);
603 printf("\tQueueTag 0x%04x\n", msg->QueueTag);
604 printf("\tReplyWord 0x%08x\n", msg->ReplyWord);
605 printf("\tLun 0x%jx\n", (uintmax_t)be64dec(msg->LUN));
606 printf("\tRelativeOff 0x%08x\n", msg->RelativeOffset);
607 printf("\tDataLength 0x%08x\n", msg->DataLength);
608 mpt_dump_sgl(msg->SGL, 0);
612 mpt_print_scsi_target_status_send_request(MSG_TARGET_STATUS_SEND_REQUEST *msg)
616 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
617 printf("\tStatusCode 0x%02x\n", msg->StatusCode);
618 printf("\tStatusFlags 0x%02x\n", msg->StatusFlags);
619 printf("\tQueueTag 0x%04x\n", msg->QueueTag);
620 printf("\tReplyWord 0x%08x\n", msg->ReplyWord);
621 printf("\tLun 0x%jx\n", (uintmax_t)be64dec(msg->LUN));
622 x.u.Simple = msg->StatusDataSGE;
627 mpt_print_request(void *vreq)
629 MSG_REQUEST_HEADER *req = vreq;
631 switch (req->Function) {
632 case MPI_FUNCTION_SCSI_IO_REQUEST:
633 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
634 mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req);
636 case MPI_FUNCTION_SCSI_TASK_MGMT:
637 mpt_print_scsi_tmf_request((MSG_SCSI_TASK_MGMT *)req);
639 case MPI_FUNCTION_TARGET_ASSIST:
640 mpt_print_scsi_target_assist_request(
641 (PTR_MSG_TARGET_ASSIST_REQUEST)req);
643 case MPI_FUNCTION_TARGET_STATUS_SEND:
644 mpt_print_scsi_target_status_send_request(
645 (MSG_TARGET_STATUS_SEND_REQUEST *)req);
648 mpt_print_request_hdr(req);
654 typedef struct mpt_decode_entry {
658 } mpt_decode_entry_t;
661 mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries,
662 const char *name, u_int value, u_int *cur_column,
669 if (cur_column == NULL) {
671 cur_column = &dummy_column;
674 if (*cur_column >= wrap_point) {
678 printed = printf("%s[0x%x]", name, value);
680 printed += printf(" ");
681 *cur_column += printed;
685 while (printed_mask != 0xFF) {
688 for (entry = 0; entry < num_entries; entry++) {
689 if (((value & table[entry].mask)
690 != table[entry].value)
691 || ((printed_mask & table[entry].mask)
692 == table[entry].mask))
695 printed += printf("%s%s",
696 printed_mask == 0 ? ":(" : "|",
698 printed_mask |= table[entry].mask;
701 if (entry >= num_entries)
704 if (printed_mask != 0)
705 printed += printf(") ");
707 printed += printf(" ");
708 *cur_column += printed;
712 static const mpt_decode_entry_t req_state_parse_table[] = {
713 { "REQ_FREE", 0x00, 0xff },
714 { "REQ_ALLOCATED", 0x01, 0x01 },
715 { "REQ_QUEUED", 0x02, 0x02 },
716 { "REQ_DONE", 0x04, 0x04 },
717 { "REQ_TIMEDOUT", 0x08, 0x08 },
718 { "REQ_NEED_WAKEUP", 0x10, 0x10 }
722 mpt_req_state(mpt_req_state_t state)
725 mpt_decode_value(req_state_parse_table,
726 NUM_ELEMENTS(req_state_parse_table),
727 "REQ_STATE", state, NULL, 80);
732 MPI_SGE_FLAGS_END_OF_LIST | \
733 MPI_SGE_FLAGS_END_OF_BUFFER| \
734 MPI_SGE_FLAGS_LAST_ELEMENT)
736 mpt_dump_sgl(SGE_IO_UNION *su, int offset)
738 SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su;
739 const char allfox[4] = { 0xff, 0xff, 0xff, 0xff };
745 * Can't be any bigger than this.
747 lim = &((char *)se)[MPT_REQUEST_AREA - offset];
753 if (memcmp(se, allfox, 4) == 0) {
754 uint32_t *nxt = (uint32_t *)se;
755 printf("PAD %p\n", se);
762 flags = MPI_SGE_GET_FLAGS(se->FlagsLength);
763 switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) {
764 case MPI_SGE_FLAGS_SIMPLE_ELEMENT:
765 if (flags & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
766 SGE_SIMPLE64 *se64 = (SGE_SIMPLE64 *)se;
767 printf("SE64 %p: Addr=0x%08x%08x FlagsLength"
768 "=0x%0x\n", se64, se64->Address.High,
769 se64->Address.Low, se64->FlagsLength);
772 printf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x"
773 "\n", se, se->Address, se->FlagsLength);
777 case MPI_SGE_FLAGS_CHAIN_ELEMENT:
778 if (flags & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
779 SGE_CHAIN64 *ce64 = (SGE_CHAIN64 *) se;
780 printf("CE64 %p: Addr=0x%08x%08x NxtChnO=0x%x "
781 "Flgs=0x%x Len=0x%0x\n", ce64,
782 ce64->Address.High, ce64->Address.Low,
783 ce64->NextChainOffset,
784 ce64->Flags, ce64->Length);
787 SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se;
788 printf("CE32 %p: Addr=0x%0x NxtChnO=0x%x "
789 " Flgs=0x%x Len=0x%0x\n", ce, ce->Address,
790 ce->NextChainOffset, ce->Flags, ce->Length);
794 case MPI_SGE_FLAGS_TRANSACTION_ELEMENT:
795 printf("TE32 @ %p\n", se);
800 #define MPT_PRINT_FLAG(x) \
801 if (flags & MPI_SGE_FLAGS_ ## x ) { \
809 MPT_PRINT_FLAG(LOCAL_ADDRESS);
810 MPT_PRINT_FLAG(HOST_TO_IOC);
811 MPT_PRINT_FLAG(64_BIT_ADDRESSING);
812 MPT_PRINT_FLAG(LAST_ELEMENT);
813 MPT_PRINT_FLAG(END_OF_BUFFER);
814 MPT_PRINT_FLAG(END_OF_LIST);
815 #undef MPT_PRINT_FLAG
819 if ((flags & LAST_SGE) == LAST_SGE) {
822 } while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && nxtaddr < lim);
826 mpt_dump_data(struct mpt_softc *mpt, const char *msg, void *addr, int len)
831 mpt_prt(mpt, "%s:", msg);
832 for (offset = 0; offset < len; offset++) {
833 if ((offset & 0xf) == 0) {
836 mpt_prtc(mpt, " %02x", cp[offset]);
842 mpt_dump_request(struct mpt_softc *mpt, request_t *req)
844 uint32_t *pReq = req->req_vbuf;
847 mpt_prt(mpt, "Send Request %d (%jx):",
848 req->index, (uintmax_t) req->req_pbuf);
849 for (o = 0; o < mpt->ioc_facts.RequestFrameSize; o++) {
850 if ((o & 0x7) == 0) {
854 mpt_prtc(mpt, " %08x", pReq[o]);
860 mpt_prt(struct mpt_softc *mpt, const char *fmt, ...)
864 printf("%s: ", device_get_nameunit(mpt->dev));
871 mpt_prtc(struct mpt_softc *mpt, const char *fmt, ...)