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