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