xref: /netbsd-src/sys/dev/ic/mpt_debug.c (revision aad9773e38ed2370a628a6416e098f9008fc10a7)
1 /*	$NetBSD: mpt_debug.c,v 1.10 2014/04/17 16:05:45 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.10 2014/04/17 16:05:45 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: Receive ID Invalid" },
85 { MPI_IOCSTATUS_TARGET_FC_DID_INVALID,    "FC: Receive 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: Receive Error" },
92 { MPI_IOCSTATUS_LAN_RECEIVE_ABORTED,      "LAN: Receive 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 Receive" },
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 	size_t len;
199 	len = snprintf(tbuf, sizeof(tbuf), "(0x%08x)", code);
200 	if (len > sizeof(tbuf))
201 		return tbuf;
202 	while (status->Error_Code >= 0) {
203 		if ((status->Error_Code & code) != 0) {
204 			if (len >= sizeof(tbuf))
205 				return tbuf;
206 			len += snprintf(tbuf + len, sizeof(tbuf) - len, "%s ",
207 			    status->Error_String);
208 		}
209 		status++;
210 	}
211 	return tbuf;
212 }
213 
214 static const char *
215 mpt_ioc_function(int code)
216 {
217 	const struct Error_Map *status = IOC_Func;
218 	static char tbuf[64];
219 	while (status->Error_Code >= 0) {
220 		if (status->Error_Code == code)
221 			return status->Error_String;
222 		status++;
223 	}
224 	snprintf(tbuf, sizeof tbuf, "Unknown (0x%08x)", code);
225 	return tbuf;
226 }
227 static const char *
228 mpt_ioc_event(int code)
229 {
230 	const struct Error_Map *status = IOC_Event;
231 	static char tbuf[64];
232 	while (status->Error_Code >= 0) {
233 		if (status->Error_Code == code)
234 			return status->Error_String;
235 		status++;
236 	}
237 	snprintf(tbuf, sizeof tbuf, "Unknown (0x%08x)", code);
238 	return tbuf;
239 }
240 static char *
241 mpt_scsi_state(int code)
242 {
243 	const struct Error_Map *status = IOC_SCSIState;
244 	static char tbuf[128];
245 	size_t len;
246 	len = snprintf(tbuf, sizeof(tbuf), "(0x%08x)", code);
247 	if (len > sizeof(tbuf))
248 		return tbuf;
249 	while (status->Error_Code >= 0) {
250 		if ((status->Error_Code & code) != 0) {
251 			if (len >= sizeof(tbuf))
252 				return tbuf;
253 			len += snprintf(tbuf + len, sizeof(tbuf) - len, "%s ",
254 				status->Error_String);
255 		}
256 		status++;
257 	}
258 	return tbuf;
259 }
260 static const char *
261 mpt_scsi_status(int code)
262 {
263 	const struct Error_Map *status = IOC_SCSIStatus;
264 	static char tbuf[64];
265 	while (status->Error_Code >= 0) {
266 		if (status->Error_Code == code)
267 			return status->Error_String;
268 		status++;
269 	}
270 	snprintf(tbuf, sizeof tbuf, "Unknown (0x%08x)", code);
271 	return tbuf;
272 }
273 static const char *
274 mpt_who(int who_init)
275 {
276 	const char *who;
277 
278 	switch (who_init) {
279 	case MPT_DB_INIT_NOONE:       who = "No One";        break;
280 	case MPT_DB_INIT_BIOS:        who = "BIOS";          break;
281 	case MPT_DB_INIT_ROMBIOS:     who = "ROM BIOS";      break;
282 	case MPT_DB_INIT_PCIPEER:     who = "PCI Peer";      break;
283 	case MPT_DB_INIT_HOST:        who = "Host Driver";   break;
284 	case MPT_DB_INIT_MANUFACTURE: who = "Manufacturing"; break;
285 	default:                      who = "Unknown";       break;
286 	}
287 	return who;
288 }
289 
290 static const char *
291 mpt_state(u_int32_t mb)
292 {
293 	const char *text;
294 
295 	switch (MPT_STATE(mb)) {
296 		case MPT_DB_STATE_RESET:  text = "Reset";   break;
297 		case MPT_DB_STATE_READY:  text = "Ready";   break;
298 		case MPT_DB_STATE_RUNNING:text = "Running"; break;
299 		case MPT_DB_STATE_FAULT:  text = "Fault";   break;
300 		default: 		  text = "Unknown"; break;
301 	}
302 	return text;
303 };
304 
305 void
306 mpt_print_db(u_int32_t mb)
307 {
308 	printf("mpt mailbox: (0x%x) State %s  WhoInit %s\n",
309 	    mb, mpt_state(mb), mpt_who(MPT_WHO(mb)));
310 }
311 
312 /*****************************************************************************/
313 /*  Reply functions                                                          */
314 /*****************************************************************************/
315 static void
316 mpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg)
317 {
318 	printf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg);
319 	printf("\tIOC Status    %s\n", mpt_ioc_status(le16toh(msg->IOCStatus)));
320 	printf("\tIOCLogInfo    0x%08x\n", msg->IOCLogInfo);
321 	printf("\tMsgLength     0x%02x\n", msg->MsgLength);
322 	printf("\tMsgFlags      0x%02x\n", msg->MsgFlags);
323 	printf("\tMsgContext    0x%08x\n", le32toh(msg->MsgContext));
324 }
325 
326 static void
327 mpt_print_init_reply(MSG_IOC_INIT_REPLY *msg)
328 {
329 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
330 	printf("\tWhoInit       %s\n", mpt_who(msg->WhoInit));
331 	printf("\tMaxDevices    0x%02x\n", msg->MaxDevices);
332 	printf("\tMaxBuses     0x%02x\n", msg->MaxBuses);
333 }
334 
335 static void
336 mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg)
337 {
338 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
339 	printf("\tIOCNumber     %d\n",		msg->IOCNumber);
340 	printf("\tMaxChainDepth %d\n",		msg->MaxChainDepth);
341 	printf("\tWhoInit       %s\n",		mpt_who(msg->WhoInit));
342 	printf("\tBlockSize     %d\n",		msg->BlockSize);
343 	printf("\tFlags         %d\n",		msg->Flags);
344 	printf("\tReplyQueueDepth %d\n",	le16toh(msg->ReplyQueueDepth));
345 	printf("\tReqFrameSize  0x%04x\n",	le16toh(msg->RequestFrameSize));
346 	printf("\tFW Version    0x%08x\n",	msg->FWVersion.Word);
347 	printf("\tProduct ID    0x%04x\n",	le16toh(msg->ProductID));
348 	printf("\tCredits       0x%04x\n",	le16toh(msg->GlobalCredits));
349 	printf("\tPorts         %d\n",		msg->NumberOfPorts);
350 	printf("\tEventState    0x%02x\n",	msg->EventState);
351 	printf("\tHostMFA_HA    0x%08x\n",
352 	    le32toh(msg->CurrentHostMfaHighAddr));
353 	printf("\tSenseBuf_HA   0x%08x\n",
354 	    le32toh(msg->CurrentSenseBufferHighAddr));
355 	printf("\tRepFrameSize  0x%04x\n",
356 	    le16toh(msg->CurReplyFrameSize));
357 	printf("\tMaxDevices    0x%02x\n",	msg->MaxDevices);
358 	printf("\tMaxBuses      0x%02x\n",	msg->MaxBuses);
359 	printf("\tFWImageSize   0x%04x\n",	le32toh(msg->FWImageSize));
360 }
361 
362 static void
363 mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg)
364 {
365 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
366 	printf("\tPort:         %d\n", msg->PortNumber);
367 }
368 
369 static void
370 mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg)
371 {
372 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
373 	printf("\tBus:          %d\n", msg->Bus);
374 	printf("\tTargetID      %d\n", msg->TargetID);
375 	printf("\tCDBLength     %d\n", msg->CDBLength);
376 	printf("\tSCSI Status:  %s\n", mpt_scsi_status(msg->SCSIStatus));
377 	printf("\tSCSI State:   %s\n", mpt_scsi_state(msg->SCSIState));
378 	printf("\tTransferCnt   0x%04x\n", le32toh(msg->TransferCount));
379 	printf("\tSenseCnt      0x%04x\n", le32toh(msg->SenseCount));
380 	printf("\tResponseInfo  0x%08x\n", le32toh(msg->ResponseInfo));
381 }
382 
383 
384 
385 static void
386 mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg)
387 {
388 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
389 	printf("\tEvent:        %s\n", mpt_ioc_event(le32toh(msg->Event)));
390 	printf("\tEventContext  0x%04x\n", le32toh(msg->EventContext));
391 	printf("\tAckRequired     %d\n", msg->AckRequired);
392 	printf("\tEventDataLength %d\n", le16toh(msg->EventDataLength));
393 	printf("\tContinuation    %d\n", msg->MsgFlags & 0x80);
394 	switch(msg->Event) {
395 	case MPI_EVENT_LOG_DATA:
396 		printf("\tEvtLogData:   0x%04x\n", le32toh(msg->Data[0]));
397 		break;
398 
399 	case MPI_EVENT_UNIT_ATTENTION:
400 		printf("\tTargetID:     0x%04x\n",
401 			msg->Data[0] & 0xff);
402 		printf("\tBus:          0x%04x\n",
403 			(msg->Data[0] >> 8) & 0xff);
404 		break;
405 
406 	case MPI_EVENT_IOC_BUS_RESET:
407 	case MPI_EVENT_EXT_BUS_RESET:
408 	case MPI_EVENT_RESCAN:
409 		printf("\tPort:           %d\n",
410 			(msg->Data[0] >> 8) & 0xff);
411 		break;
412 
413 	case MPI_EVENT_LINK_STATUS_CHANGE:
414 		printf("\tLinkState:    %d\n",
415 			msg->Data[0] & 0xff);
416 		printf("\tPort:         %d\n",
417 			(msg->Data[1] >> 8) & 0xff);
418 		break;
419 
420 	case MPI_EVENT_LOOP_STATE_CHANGE:
421 		printf("\tType:         %d\n",
422 			(msg->Data[0] >> 16) & 0xff);
423 		printf("\tChar3:      0x%02x\n",
424 			(msg->Data[0] >> 8) & 0xff);
425 		printf("\tChar4:      0x%02x\n",
426 			(msg->Data[0]     ) & 0xff);
427 		printf("\tPort:         %d\n",
428 			(msg->Data[1] >> 8) & 0xff);
429 		break;
430 
431 	case MPI_EVENT_LOGOUT:
432 		printf("\tN_PortId:   0x%04x\n", msg->Data[0]);
433 		printf("\tPort:         %d\n",
434 			(msg->Data[1] >> 8) & 0xff);
435 		break;
436 	}
437 
438 }
439 
440 void
441 mpt_print_reply(void *vmsg)
442 {
443 	MSG_DEFAULT_REPLY *msg = vmsg;
444 
445 	switch (msg->Function) {
446 	case MPI_FUNCTION_EVENT_NOTIFICATION:
447 		mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg);
448 		break;
449 	case MPI_FUNCTION_PORT_ENABLE:
450 		mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg);
451 		break;
452 	case MPI_FUNCTION_IOC_FACTS:
453 		mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg);
454 		break;
455 	case MPI_FUNCTION_IOC_INIT:
456 		mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg);
457 		break;
458 	case MPI_FUNCTION_SCSI_IO_REQUEST:
459 		mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg);
460 		break;
461 	default:
462 		mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
463 		break;
464 	}
465 }
466 
467 /*****************************************************************************/
468 /*  Request functions                                                        */
469 /*****************************************************************************/
470 static void
471 mpt_print_request_hdr(MSG_REQUEST_HEADER *req)
472 {
473 	printf("%s @ %p\n", mpt_ioc_function(req->Function), req);
474 	printf("\tChain Offset  0x%02x\n", req->ChainOffset);
475 	printf("\tMsgFlags      0x%02x\n", req->MsgFlags);
476 	printf("\tMsgContext    0x%08x\n", le32toh(req->MsgContext));
477 }
478 
479 void
480 mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg)
481 {
482 	MSG_SCSI_IO_REQUEST local, *msg = &local;
483 	int i;
484 
485 	memcpy(msg, orig_msg, sizeof (MSG_SCSI_IO_REQUEST));
486 	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
487 	printf("\tBus:                %d\n", msg->Bus);
488 	printf("\tTargetID            %d\n", msg->TargetID);
489 	printf("\tSenseBufferLength   %d\n", msg->SenseBufferLength);
490 	printf("\tLUN:              0x%0x\n", msg->LUN[1]);
491 	printf("\tControl           0x%08x ", le32toh(msg->Control));
492 #define MPI_PRINT_FIELD(x)						\
493 	case MPI_SCSIIO_CONTROL_ ## x :					\
494 		printf(" " #x " ");					\
495 		break
496 
497 	switch (le32toh(msg->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) {
498 	MPI_PRINT_FIELD(NODATATRANSFER);
499 	MPI_PRINT_FIELD(WRITE);
500 	MPI_PRINT_FIELD(READ);
501 	default:
502 		printf(" Invalid DIR! ");
503 		break;
504 	}
505 	switch (le32toh(msg->Control) & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) {
506 	MPI_PRINT_FIELD(SIMPLEQ);
507 	MPI_PRINT_FIELD(HEADOFQ);
508 	MPI_PRINT_FIELD(ORDEREDQ);
509 	MPI_PRINT_FIELD(ACAQ);
510 	MPI_PRINT_FIELD(UNTAGGED);
511 	MPI_PRINT_FIELD(NO_DISCONNECT);
512 	default:
513 		printf(" Unknown attribute! ");
514 		break;
515 	}
516 
517 	printf("\n");
518 #undef MPI_PRINT_FIELD
519 
520 	printf("\tDataLength\t0x%08x\n", le32toh(msg->DataLength));
521 	printf("\tSenseBufAddr\t0x%08x\n", le32toh(msg->SenseBufferLowAddr));
522 	printf("\tCDB[0:%d]\t", msg->CDBLength);
523 	for (i = 0; i < msg->CDBLength; i++)
524 		printf("%02x ", msg->CDB[i]);
525 	printf("\n");
526 	mpt_dump_sgl(&orig_msg->SGL);
527 }
528 
529 void
530 mpt_print_request(void *vreq)
531 {
532 	MSG_REQUEST_HEADER *req = vreq;
533 
534 	switch (req->Function) {
535 	case MPI_FUNCTION_SCSI_IO_REQUEST:
536 		mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req);
537 		break;
538 	default:
539 		mpt_print_request_hdr(req);
540 		break;
541 	}
542 }
543 
544 const char *
545 mpt_req_state(enum mpt_req_state state)
546 {
547 	const char *text;
548 
549 	switch (state) {
550 	case REQ_FREE:         text = "Free";         break;
551 	case REQ_IN_PROGRESS:  text = "In Progress";  break;
552 	case REQ_ON_CHIP:      text = "On Chip";      break;
553 	case REQ_TIMEOUT:      text = "Timeout";      break;
554 	default: 	       text = "Unknown";      break;
555 	}
556 	return text;
557 };
558 
559 static void
560 mpt_dump_sgl(SGE_IO_UNION *su)
561 {
562 	SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su;
563 	int iCount, flags;
564 
565 	iCount = MPT_SGL_MAX;
566 	do {
567 		int iprt;
568 
569 		printf("\t");
570 		flags = MPI_SGE_GET_FLAGS(le32toh(se->FlagsLength));
571 		switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) {
572 		case MPI_SGE_FLAGS_SIMPLE_ELEMENT:
573 		{
574 			printf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x\n",
575 			    se, le32toh(se->Address), le32toh(se->FlagsLength));
576 			printf(" ");
577 			break;
578 		}
579 		case MPI_SGE_FLAGS_CHAIN_ELEMENT:
580 		{
581 			SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se;
582 			printf("CE32 %p: Addr=0x%0x NxtChnO=0x%x Flgs=0x%x "
583 			    "Len=0x%0x\n", ce, le32toh(ce->Address),
584 			    ce->NextChainOffset, ce->Flags,
585 			    le16toh(ce->Length));
586 			flags = 0;
587 			break;
588 		}
589 		case MPI_SGE_FLAGS_TRANSACTION_ELEMENT:
590 			printf("TE32 @ %p\n", se);
591 			flags = 0;
592 			break;
593 		}
594 		iprt = 0;
595 #define MPT_PRINT_FLAG(x)						\
596 		if (flags & MPI_SGE_FLAGS_ ## x ) { 			\
597 			if (iprt == 0) {				\
598 				printf("\t");				\
599 			}						\
600 			printf(" ");					\
601 			printf( #x );					\
602 			iprt++;						\
603 		}
604 		MPT_PRINT_FLAG(LOCAL_ADDRESS);
605 		MPT_PRINT_FLAG(HOST_TO_IOC);
606 		MPT_PRINT_FLAG(64_BIT_ADDRESSING);
607 		MPT_PRINT_FLAG(LAST_ELEMENT);
608 		MPT_PRINT_FLAG(END_OF_BUFFER);
609 		MPT_PRINT_FLAG(END_OF_LIST);
610 #undef MPT_PRINT_FLAG
611 		if (iprt)
612 			printf("\n");
613 		se++;
614 		iCount -= 1;
615 	} while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && iCount != 0);
616 }
617