xref: /netbsd-src/sys/dev/ic/mpt_debug.c (revision a536ee5124e62c9a0051a252f7833dc8f50f44c9)
1 /*	$NetBSD: mpt_debug.c,v 1.8 2011/10/17 16:40:53 mbalmer 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.8 2011/10/17 16:40:53 mbalmer 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 	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(le16toh(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", le32toh(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",	le16toh(msg->ReplyQueueDepth));
339 	printf("\tReqFrameSize  0x%04x\n",	le16toh(msg->RequestFrameSize));
340 	printf("\tFW Version    0x%08x\n",	msg->FWVersion.Word);
341 	printf("\tProduct ID    0x%04x\n",	le16toh(msg->ProductID));
342 	printf("\tCredits       0x%04x\n",	le16toh(msg->GlobalCredits));
343 	printf("\tPorts         %d\n",		msg->NumberOfPorts);
344 	printf("\tEventState    0x%02x\n",	msg->EventState);
345 	printf("\tHostMFA_HA    0x%08x\n",
346 	    le32toh(msg->CurrentHostMfaHighAddr));
347 	printf("\tSenseBuf_HA   0x%08x\n",
348 	    le32toh(msg->CurrentSenseBufferHighAddr));
349 	printf("\tRepFrameSize  0x%04x\n",
350 	    le16toh(msg->CurReplyFrameSize));
351 	printf("\tMaxDevices    0x%02x\n",	msg->MaxDevices);
352 	printf("\tMaxBuses      0x%02x\n",	msg->MaxBuses);
353 	printf("\tFWImageSize   0x%04x\n",	le32toh(msg->FWImageSize));
354 }
355 
356 static void
357 mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg)
358 {
359 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
360 	printf("\tPort:         %d\n", msg->PortNumber);
361 }
362 
363 static void
364 mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg)
365 {
366 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
367 	printf("\tBus:          %d\n", msg->Bus);
368 	printf("\tTargetID      %d\n", msg->TargetID);
369 	printf("\tCDBLength     %d\n", msg->CDBLength);
370 	printf("\tSCSI Status:  %s\n", mpt_scsi_status(msg->SCSIStatus));
371 	printf("\tSCSI State:   %s\n", mpt_scsi_state(msg->SCSIState));
372 	printf("\tTransferCnt   0x%04x\n", le32toh(msg->TransferCount));
373 	printf("\tSenseCnt      0x%04x\n", le32toh(msg->SenseCount));
374 	printf("\tResponseInfo  0x%08x\n", le32toh(msg->ResponseInfo));
375 }
376 
377 
378 
379 static void
380 mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg)
381 {
382 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
383 	printf("\tEvent:        %s\n", mpt_ioc_event(le32toh(msg->Event)));
384 	printf("\tEventContext  0x%04x\n", le32toh(msg->EventContext));
385 	printf("\tAckRequired     %d\n", msg->AckRequired);
386 	printf("\tEventDataLength %d\n", le16toh(msg->EventDataLength));
387 	printf("\tContinuation    %d\n", msg->MsgFlags & 0x80);
388 	switch(msg->Event) {
389 	case MPI_EVENT_LOG_DATA:
390 		printf("\tEvtLogData:   0x%04x\n", le32toh(msg->Data[0]));
391 		break;
392 
393 	case MPI_EVENT_UNIT_ATTENTION:
394 		printf("\tTargetID:     0x%04x\n",
395 			msg->Data[0] & 0xff);
396 		printf("\tBus:          0x%04x\n",
397 			(msg->Data[0] >> 8) & 0xff);
398 		break;
399 
400 	case MPI_EVENT_IOC_BUS_RESET:
401 	case MPI_EVENT_EXT_BUS_RESET:
402 	case MPI_EVENT_RESCAN:
403 		printf("\tPort:           %d\n",
404 			(msg->Data[0] >> 8) & 0xff);
405 		break;
406 
407 	case MPI_EVENT_LINK_STATUS_CHANGE:
408 		printf("\tLinkState:    %d\n",
409 			msg->Data[0] & 0xff);
410 		printf("\tPort:         %d\n",
411 			(msg->Data[1] >> 8) & 0xff);
412 		break;
413 
414 	case MPI_EVENT_LOOP_STATE_CHANGE:
415 		printf("\tType:         %d\n",
416 			(msg->Data[0] >> 16) & 0xff);
417 		printf("\tChar3:      0x%02x\n",
418 			(msg->Data[0] >> 8) & 0xff);
419 		printf("\tChar4:      0x%02x\n",
420 			(msg->Data[0]     ) & 0xff);
421 		printf("\tPort:         %d\n",
422 			(msg->Data[1] >> 8) & 0xff);
423 		break;
424 
425 	case MPI_EVENT_LOGOUT:
426 		printf("\tN_PortId:   0x%04x\n", msg->Data[0]);
427 		printf("\tPort:         %d\n",
428 			(msg->Data[1] >> 8) & 0xff);
429 		break;
430 	}
431 
432 }
433 
434 void
435 mpt_print_reply(void *vmsg)
436 {
437 	MSG_DEFAULT_REPLY *msg = vmsg;
438 
439 	switch (msg->Function) {
440 	case MPI_FUNCTION_EVENT_NOTIFICATION:
441 		mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg);
442 		break;
443 	case MPI_FUNCTION_PORT_ENABLE:
444 		mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg);
445 		break;
446 	case MPI_FUNCTION_IOC_FACTS:
447 		mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg);
448 		break;
449 	case MPI_FUNCTION_IOC_INIT:
450 		mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg);
451 		break;
452 	case MPI_FUNCTION_SCSI_IO_REQUEST:
453 		mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg);
454 		break;
455 	default:
456 		mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
457 		break;
458 	}
459 }
460 
461 /*****************************************************************************/
462 /*  Request functions                                                        */
463 /*****************************************************************************/
464 static void
465 mpt_print_request_hdr(MSG_REQUEST_HEADER *req)
466 {
467 	printf("%s @ %p\n", mpt_ioc_function(req->Function), req);
468 	printf("\tChain Offset  0x%02x\n", req->ChainOffset);
469 	printf("\tMsgFlags      0x%02x\n", req->MsgFlags);
470 	printf("\tMsgContext    0x%08x\n", le32toh(req->MsgContext));
471 }
472 
473 void
474 mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg)
475 {
476 	MSG_SCSI_IO_REQUEST local, *msg = &local;
477 	int i;
478 
479 	memcpy(msg, orig_msg, sizeof (MSG_SCSI_IO_REQUEST));
480 	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
481 	printf("\tBus:                %d\n", msg->Bus);
482 	printf("\tTargetID            %d\n", msg->TargetID);
483 	printf("\tSenseBufferLength   %d\n", msg->SenseBufferLength);
484 	printf("\tLUN:              0x%0x\n", msg->LUN[1]);
485 	printf("\tControl           0x%08x ", le32toh(msg->Control));
486 #define MPI_PRINT_FIELD(x)						\
487 	case MPI_SCSIIO_CONTROL_ ## x :					\
488 		printf(" " #x " ");					\
489 		break
490 
491 	switch (le32toh(msg->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) {
492 	MPI_PRINT_FIELD(NODATATRANSFER);
493 	MPI_PRINT_FIELD(WRITE);
494 	MPI_PRINT_FIELD(READ);
495 	default:
496 		printf(" Invalid DIR! ");
497 		break;
498 	}
499 	switch (le32toh(msg->Control) & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) {
500 	MPI_PRINT_FIELD(SIMPLEQ);
501 	MPI_PRINT_FIELD(HEADOFQ);
502 	MPI_PRINT_FIELD(ORDEREDQ);
503 	MPI_PRINT_FIELD(ACAQ);
504 	MPI_PRINT_FIELD(UNTAGGED);
505 	MPI_PRINT_FIELD(NO_DISCONNECT);
506 	default:
507 		printf(" Unknown attribute! ");
508 		break;
509 	}
510 
511 	printf("\n");
512 #undef MPI_PRINT_FIELD
513 
514 	printf("\tDataLength\t0x%08x\n", le32toh(msg->DataLength));
515 	printf("\tSenseBufAddr\t0x%08x\n", le32toh(msg->SenseBufferLowAddr));
516 	printf("\tCDB[0:%d]\t", msg->CDBLength);
517 	for (i = 0; i < msg->CDBLength; i++)
518 		printf("%02x ", msg->CDB[i]);
519 	printf("\n");
520 	mpt_dump_sgl(&orig_msg->SGL);
521 }
522 
523 void
524 mpt_print_request(void *vreq)
525 {
526 	MSG_REQUEST_HEADER *req = vreq;
527 
528 	switch (req->Function) {
529 	case MPI_FUNCTION_SCSI_IO_REQUEST:
530 		mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req);
531 		break;
532 	default:
533 		mpt_print_request_hdr(req);
534 		break;
535 	}
536 }
537 
538 const char *
539 mpt_req_state(enum mpt_req_state state)
540 {
541 	const char *text;
542 
543 	switch (state) {
544 	case REQ_FREE:         text = "Free";         break;
545 	case REQ_IN_PROGRESS:  text = "In Progress";  break;
546 	case REQ_ON_CHIP:      text = "On Chip";      break;
547 	case REQ_TIMEOUT:      text = "Timeout";      break;
548 	default: 	       text = "Unknown";      break;
549 	}
550 	return text;
551 };
552 
553 static void
554 mpt_dump_sgl(SGE_IO_UNION *su)
555 {
556 	SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su;
557 	int iCount, flags;
558 
559 	iCount = MPT_SGL_MAX;
560 	do {
561 		int iprt;
562 
563 		printf("\t");
564 		flags = MPI_SGE_GET_FLAGS(le32toh(se->FlagsLength));
565 		switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) {
566 		case MPI_SGE_FLAGS_SIMPLE_ELEMENT:
567 		{
568 			printf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x\n",
569 			    se, le32toh(se->Address), le32toh(se->FlagsLength));
570 			printf(" ");
571 			break;
572 		}
573 		case MPI_SGE_FLAGS_CHAIN_ELEMENT:
574 		{
575 			SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se;
576 			printf("CE32 %p: Addr=0x%0x NxtChnO=0x%x Flgs=0x%x "
577 			    "Len=0x%0x\n", ce, le32toh(ce->Address),
578 			    ce->NextChainOffset, ce->Flags,
579 			    le16toh(ce->Length));
580 			flags = 0;
581 			break;
582 		}
583 		case MPI_SGE_FLAGS_TRANSACTION_ELEMENT:
584 			printf("TE32 @ %p\n", se);
585 			flags = 0;
586 			break;
587 		}
588 		iprt = 0;
589 #define MPT_PRINT_FLAG(x)						\
590 		if (flags & MPI_SGE_FLAGS_ ## x ) { 			\
591 			if (iprt == 0) {				\
592 				printf("\t");				\
593 			}						\
594 			printf(" ");					\
595 			printf( #x );					\
596 			iprt++;						\
597 		}
598 		MPT_PRINT_FLAG(LOCAL_ADDRESS);
599 		MPT_PRINT_FLAG(HOST_TO_IOC);
600 		MPT_PRINT_FLAG(64_BIT_ADDRESSING);
601 		MPT_PRINT_FLAG(LAST_ELEMENT);
602 		MPT_PRINT_FLAG(END_OF_BUFFER);
603 		MPT_PRINT_FLAG(END_OF_LIST);
604 #undef MPT_PRINT_FLAG
605 		if (iprt)
606 			printf("\n");
607 		se++;
608 		iCount -= 1;
609 	} while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && iCount != 0);
610 }
611