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