mpt_debug.c revision 132107
1101704Smjacob/*
2119418Sobrien
3119418Sobrien#include <sys/cdefs.h>
4119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/mpt/mpt_debug.c 132107 2004-07-13 16:06:19Z stefanf $");
5101704Smjacob * Debug routines for LSI '909 FC  adapters.
6101704Smjacob * FreeBSD Version.
7101704Smjacob *
8101704Smjacob * Copyright (c)  2000, 2001 by Greg Ansley
9101704Smjacob *
10101704Smjacob * Redistribution and use in source and binary forms, with or without
11101704Smjacob * modification, are permitted provided that the following conditions
12101704Smjacob * are met:
13101704Smjacob * 1. Redistributions of source code must retain the above copyright
14101704Smjacob *    notice immediately at the beginning of the file, without modification,
15101704Smjacob *    this list of conditions, and the following disclaimer.
16101704Smjacob * 2. The name of the author may not be used to endorse or promote products
17101704Smjacob *    derived from this software without specific prior written permission.
18101704Smjacob *
19101704Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20101704Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21101704Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22101704Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23101704Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24101704Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25101704Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26101704Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27101704Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28101704Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29101704Smjacob * SUCH DAMAGE.
30101704Smjacob */
31101704Smjacob/*
32101704Smjacob * Additional Copyright (c) 2002 by Matthew Jacob under same license.
33101704Smjacob */
34101704Smjacob
35102199Smjacob#include <dev/mpt/mpt_freebsd.h>
36103914Smjacob#include <machine/stdarg.h>	/* for use by mpt_prt below */
37101704Smjacob
38101704Smjacobstruct Error_Map {
39101704Smjacob	int 	 Error_Code;
40101704Smjacob	char    *Error_String;
41101704Smjacob};
42101704Smjacob
43101704Smjacobstatic const struct Error_Map IOC_Status[] = {
44101704Smjacob{ MPI_IOCSTATUS_SUCCESS,                  "Success" },
45101704Smjacob{ MPI_IOCSTATUS_INVALID_FUNCTION,         "IOC: Invalid Function" },
46101704Smjacob{ MPI_IOCSTATUS_BUSY,                     "IOC: Busy" },
47101704Smjacob{ MPI_IOCSTATUS_INVALID_SGL,              "IOC: Invalid SGL" },
48101704Smjacob{ MPI_IOCSTATUS_INTERNAL_ERROR,           "IOC: Internal Error" },
49101704Smjacob{ MPI_IOCSTATUS_RESERVED,                 "IOC: Reserved" },
50101704Smjacob{ MPI_IOCSTATUS_INSUFFICIENT_RESOURCES,   "IOC: Insufficient Resources" },
51101704Smjacob{ MPI_IOCSTATUS_INVALID_FIELD,            "IOC: Invalid Field" },
52101704Smjacob{ MPI_IOCSTATUS_INVALID_STATE,            "IOC: Invalid State" },
53101704Smjacob{ MPI_IOCSTATUS_CONFIG_INVALID_ACTION,    "Invalid Action" },
54101704Smjacob{ MPI_IOCSTATUS_CONFIG_INVALID_TYPE,      "Invalid Type" },
55101704Smjacob{ MPI_IOCSTATUS_CONFIG_INVALID_PAGE,      "Invalid Page" },
56101704Smjacob{ MPI_IOCSTATUS_CONFIG_INVALID_DATA,      "Invalid Data" },
57101704Smjacob{ MPI_IOCSTATUS_CONFIG_NO_DEFAULTS,       "No Defaults" },
58101704Smjacob{ MPI_IOCSTATUS_CONFIG_CANT_COMMIT,       "Can't Commit" },
59101704Smjacob{ MPI_IOCSTATUS_SCSI_RECOVERED_ERROR,     "SCSI: Recoverd Error" },
60101704Smjacob{ MPI_IOCSTATUS_SCSI_INVALID_BUS,         "SCSI: Invalid Bus" },
61101704Smjacob{ MPI_IOCSTATUS_SCSI_INVALID_TARGETID,    "SCSI: Invalid Target ID" },
62101704Smjacob{ MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE,    "SCSI: Device Not There" },
63101704Smjacob{ MPI_IOCSTATUS_SCSI_DATA_OVERRUN,        "SCSI: Data Overrun" },
64101704Smjacob{ MPI_IOCSTATUS_SCSI_DATA_UNDERRUN,       "SCSI: Data Underrun" },
65101704Smjacob{ MPI_IOCSTATUS_SCSI_IO_DATA_ERROR,       "SCSI: Data Error" },
66101704Smjacob{ MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR,      "SCSI: Protocol Error" },
67101704Smjacob{ MPI_IOCSTATUS_SCSI_TASK_TERMINATED,     "SCSI: Task Terminated" },
68101704Smjacob{ MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH,   "SCSI: Residual Mismatch" },
69101704Smjacob{ MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED,    "SCSI: Task Management Failed" },
70101704Smjacob{ MPI_IOCSTATUS_SCSI_IOC_TERMINATED,      "SCSI: IOC Bus Reset" },
71101704Smjacob{ MPI_IOCSTATUS_SCSI_EXT_TERMINATED,      "SCSI: External Bus Reset" },
72101704Smjacob{ MPI_IOCSTATUS_TARGET_PRIORITY_IO,       "SCSI Target: Priority I/O" },
73101704Smjacob{ MPI_IOCSTATUS_TARGET_INVALID_PORT,      "SCSI Target: Invalid Port" },
74101704Smjacob{ MPI_IOCSTATUS_TARGET_INVALID_IOCINDEX,  "SCSI Target: Invalid IOC Index" },
75101704Smjacob{ MPI_IOCSTATUS_TARGET_ABORTED,           "SCSI Target: Aborted" },
76101704Smjacob{ MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE, "SCSI Target: No Connection (Retryable)" },
77101704Smjacob{ MPI_IOCSTATUS_TARGET_NO_CONNECTION,     "SCSI Target: No Connection" },
78101704Smjacob{ MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH,"SCSI Target: Transfer Count Mismatch" },
79101704Smjacob{ MPI_IOCSTATUS_TARGET_FC_ABORTED,        "FC: Aborted" },
80101704Smjacob{ MPI_IOCSTATUS_TARGET_FC_RX_ID_INVALID,  "FC: Recieve ID Invalid" },
81101704Smjacob{ MPI_IOCSTATUS_TARGET_FC_DID_INVALID,    "FC: Recieve DID Invalid" },
82101704Smjacob{ MPI_IOCSTATUS_TARGET_FC_NODE_LOGGED_OUT,"FC: Node Logged Out" },
83101704Smjacob{ MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND,     "LAN: Device Not Found" },
84101704Smjacob{ MPI_IOCSTATUS_LAN_DEVICE_FAILURE,       "LAN: Device Not Failure" },
85101704Smjacob{ MPI_IOCSTATUS_LAN_TRANSMIT_ERROR,       "LAN: Transmit Error" },
86101704Smjacob{ MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED,     "LAN: Transmit Aborted" },
87101704Smjacob{ MPI_IOCSTATUS_LAN_RECEIVE_ERROR,        "LAN: Recieve Error" },
88101704Smjacob{ MPI_IOCSTATUS_LAN_RECEIVE_ABORTED,      "LAN: Recieve Aborted" },
89101704Smjacob{ MPI_IOCSTATUS_LAN_PARTIAL_PACKET,       "LAN: Partial Packet" },
90101704Smjacob{ MPI_IOCSTATUS_LAN_CANCELED,             "LAN: Canceled" },
91101704Smjacob{ -1, 0},
92101704Smjacob};
93101704Smjacob
94101704Smjacobstatic const struct Error_Map IOC_Func[] = {
95101704Smjacob{ MPI_FUNCTION_SCSI_IO_REQUEST,              "SCSI IO Request" },
96101704Smjacob{ MPI_FUNCTION_SCSI_TASK_MGMT,               "SCSI Task Management" },
97101704Smjacob{ MPI_FUNCTION_IOC_INIT,                     "IOC Init" },
98101704Smjacob{ MPI_FUNCTION_IOC_FACTS,                    "IOC Facts" },
99101704Smjacob{ MPI_FUNCTION_CONFIG,                       "Config" },
100101704Smjacob{ MPI_FUNCTION_PORT_FACTS,                   "Port Facts" },
101101704Smjacob{ MPI_FUNCTION_PORT_ENABLE,                  "Port Enable" },
102101704Smjacob{ MPI_FUNCTION_EVENT_NOTIFICATION,           "Event Notification" },
103101704Smjacob{ MPI_FUNCTION_FW_DOWNLOAD,                  "FW Download" },
104101704Smjacob{ MPI_FUNCTION_TARGET_CMD_BUFFER_POST,       "SCSI Target Command Buffer" },
105101704Smjacob{ MPI_FUNCTION_TARGET_ASSIST,                "Target Assist" },
106101704Smjacob{ MPI_FUNCTION_TARGET_STATUS_SEND,           "Target Status Send" },
107101704Smjacob{ MPI_FUNCTION_TARGET_MODE_ABORT,            "Target Mode Abort" },
108101704Smjacob{ MPI_FUNCTION_TARGET_FC_BUF_POST_LINK_SRVC, "FC: Link Service Buffers" },
109101704Smjacob{ MPI_FUNCTION_TARGET_FC_RSP_LINK_SRVC,      "FC: Link Service Response" },
110101704Smjacob{ MPI_FUNCTION_TARGET_FC_EX_SEND_LINK_SRVC,  "FC: Send Extended Link Service" },
111101704Smjacob{ MPI_FUNCTION_TARGET_FC_ABORT,              "FC: Abort" },
112101704Smjacob{ MPI_FUNCTION_LAN_SEND,                     "LAN Send" },
113101704Smjacob{ MPI_FUNCTION_LAN_RECEIVE,                  "LAN Recieve" },
114101704Smjacob{ MPI_FUNCTION_LAN_RESET,                    "LAN Reset" },
115101704Smjacob{ -1, 0},
116101704Smjacob};
117101704Smjacob
118101704Smjacobstatic const struct Error_Map IOC_Event[] = {
119101704Smjacob{ MPI_EVENT_NONE,   	                "None" },
120101704Smjacob{ MPI_EVENT_LOG_DATA,                   "LogData" },
121101704Smjacob{ MPI_EVENT_STATE_CHANGE,               "State Change" },
122101704Smjacob{ MPI_EVENT_UNIT_ATTENTION,             "Unit Attention" },
123101704Smjacob{ MPI_EVENT_IOC_BUS_RESET,              "IOC Bus Reset" },
124101704Smjacob{ MPI_EVENT_EXT_BUS_RESET,              "External Bus Reset" },
125101704Smjacob{ MPI_EVENT_RESCAN,        	        "Rescan" },
126101704Smjacob{ MPI_EVENT_LINK_STATUS_CHANGE,	        "Link Status Change" },
127101704Smjacob{ MPI_EVENT_LOOP_STATE_CHANGE, 	        "Loop State Change" },
128101704Smjacob{ MPI_EVENT_LOGOUT,    	       		"Logout" },
129101704Smjacob{ MPI_EVENT_EVENT_CHANGE,               "EventChange" },
130101704Smjacob{ -1, 0},
131101704Smjacob};
132101704Smjacob
133101704Smjacobstatic const struct Error_Map IOC_SCSIState[] = {
134101704Smjacob{ MPI_SCSI_STATE_AUTOSENSE_VALID,	"AutoSense_Valid" },
135101704Smjacob{ MPI_SCSI_STATE_AUTOSENSE_FAILED,	"AutoSense_Failed" },
136101704Smjacob{ MPI_SCSI_STATE_NO_SCSI_STATUS,	"No_SCSI_Status" },
137101704Smjacob{ MPI_SCSI_STATE_TERMINATED,	   	"State_Terminated" },
138101704Smjacob{ MPI_SCSI_STATE_RESPONSE_INFO_VALID,	"Repsonse_Info_Valid" },
139101704Smjacob{ MPI_SCSI_STATE_QUEUE_TAG_REJECTED,	"Queue Tag Rejected" },
140101704Smjacob{ -1, 0},
141101704Smjacob};
142101704Smjacob
143101704Smjacobstatic const struct Error_Map IOC_SCSIStatus[] = {
144101704Smjacob{ SCSI_STATUS_OK,			"OK" },
145101704Smjacob{ SCSI_STATUS_CHECK_COND,		"Check Condition" },
146101704Smjacob{ SCSI_STATUS_COND_MET,			"Check Condition Met" },
147101704Smjacob{ SCSI_STATUS_BUSY,			"Busy" },
148101704Smjacob{ SCSI_STATUS_INTERMED,			"Intermidiate Condition" },
149101704Smjacob{ SCSI_STATUS_INTERMED_COND_MET,	"Intermidiate Condition Met" },
150101704Smjacob{ SCSI_STATUS_RESERV_CONFLICT,		"Reservation Conflict" },
151101704Smjacob{ SCSI_STATUS_CMD_TERMINATED,		"Command Terminated" },
152101704Smjacob{ SCSI_STATUS_QUEUE_FULL,		"Queue Full" },
153101704Smjacob{ -1, 0},
154101704Smjacob};
155101704Smjacob
156101704Smjacobstatic const struct Error_Map IOC_Diag[] = {
157101704Smjacob{ MPT_DIAG_ENABLED,	"DWE" },
158101704Smjacob{ MPT_DIAG_FLASHBAD,	"FLASH_Bad" },
159101704Smjacob{ MPT_DIAG_TTLI,	"TTLI" },
160101704Smjacob{ MPT_DIAG_RESET_IOC,	"Reset" },
161101704Smjacob{ MPT_DIAG_ARM_DISABLE,	"DisARM" },
162101704Smjacob{ MPT_DIAG_DME,		"DME" },
163101704Smjacob{ -1, 0 },
164101704Smjacob};
165101704Smjacob
166101704Smjacob
167101704Smjacobstatic void mpt_dump_sgl(SGE_IO_UNION *sgl);
168101704Smjacob
169101704Smjacobstatic char *
170101704Smjacobmpt_ioc_status(int code)
171101704Smjacob{
172101704Smjacob	const struct Error_Map *status = IOC_Status;
173101704Smjacob	static char buf[64];
174101704Smjacob	while (status->Error_Code >= 0) {
175101704Smjacob		if (status->Error_Code == (code & MPI_IOCSTATUS_MASK))
176101704Smjacob			return status->Error_String;
177101704Smjacob		status++;
178101704Smjacob	}
179101704Smjacob	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
180101704Smjacob	return buf;
181101704Smjacob}
182101704Smjacob
183101704Smjacobchar *
184101704Smjacobmpt_ioc_diag(u_int32_t code)
185101704Smjacob{
186101704Smjacob	const struct Error_Map *status = IOC_Diag;
187101704Smjacob	static char buf[128];
188101704Smjacob	char *ptr = buf;
189101704Smjacob	char *end = &buf[128];
190101704Smjacob	buf[0] = '\0';
191101704Smjacob	ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
192101704Smjacob	while (status->Error_Code >= 0) {
193101704Smjacob		if ((status->Error_Code & code) != 0)
194101704Smjacob			ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
195101704Smjacob				status->Error_String);
196101704Smjacob		status++;
197101704Smjacob	}
198101704Smjacob	return buf;
199101704Smjacob}
200101704Smjacob
201101704Smjacobstatic char *
202101704Smjacobmpt_ioc_function(int code)
203101704Smjacob{
204101704Smjacob	const struct Error_Map *status = IOC_Func;
205101704Smjacob	static char buf[64];
206101704Smjacob	while (status->Error_Code >= 0) {
207101704Smjacob		if (status->Error_Code == code)
208101704Smjacob			return status->Error_String;
209101704Smjacob		status++;
210101704Smjacob	}
211101704Smjacob	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
212101704Smjacob	return buf;
213101704Smjacob}
214101704Smjacobstatic char *
215101704Smjacobmpt_ioc_event(int code)
216101704Smjacob{
217101704Smjacob	const struct Error_Map *status = IOC_Event;
218101704Smjacob	static char buf[64];
219101704Smjacob	while (status->Error_Code >= 0) {
220101704Smjacob		if (status->Error_Code == code)
221101704Smjacob			return status->Error_String;
222101704Smjacob		status++;
223101704Smjacob	}
224101704Smjacob	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
225101704Smjacob	return buf;
226101704Smjacob}
227101704Smjacobstatic char *
228101704Smjacobmpt_scsi_state(int code)
229101704Smjacob{
230101704Smjacob	const struct Error_Map *status = IOC_SCSIState;
231101704Smjacob	static char buf[128];
232101704Smjacob	char *ptr = buf;
233101704Smjacob	char *end = &buf[128];
234101704Smjacob	buf[0] = '\0';
235101704Smjacob	ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
236101704Smjacob	while (status->Error_Code >= 0) {
237101704Smjacob		if ((status->Error_Code & code) != 0)
238101704Smjacob			ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
239101704Smjacob				status->Error_String);
240101704Smjacob		status++;
241101704Smjacob	}
242101704Smjacob	return buf;
243101704Smjacob}
244101704Smjacobstatic char *
245101704Smjacobmpt_scsi_status(int code)
246101704Smjacob{
247101704Smjacob	const struct Error_Map *status = IOC_SCSIStatus;
248101704Smjacob	static char buf[64];
249101704Smjacob	while (status->Error_Code >= 0) {
250101704Smjacob		if (status->Error_Code == code)
251101704Smjacob			return status->Error_String;
252101704Smjacob		status++;
253101704Smjacob	}
254101704Smjacob	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
255101704Smjacob	return buf;
256101704Smjacob}
257101704Smjacobstatic char *
258101704Smjacobmpt_who(int who_init)
259101704Smjacob{
260101704Smjacob	char *who;
261101704Smjacob
262101704Smjacob	switch (who_init) {
263101704Smjacob	case MPT_DB_INIT_NOONE:       who = "No One";        break;
264101704Smjacob	case MPT_DB_INIT_BIOS:        who = "BIOS";          break;
265101704Smjacob	case MPT_DB_INIT_ROMBIOS:     who = "ROM BIOS";      break;
266101704Smjacob	case MPT_DB_INIT_PCIPEER:     who = "PCI Peer";      break;
267101704Smjacob	case MPT_DB_INIT_HOST:        who = "Host Driver";   break;
268101704Smjacob	case MPT_DB_INIT_MANUFACTURE: who = "Manufacturing"; break;
269101704Smjacob	default:                      who = "Unknown";       break;
270101704Smjacob	}
271101704Smjacob	return who;
272101704Smjacob}
273101704Smjacob
274101704Smjacobstatic char *
275101704Smjacobmpt_state(u_int32_t mb)
276101704Smjacob{
277101704Smjacob	char *text;
278101704Smjacob
279101704Smjacob	switch (MPT_STATE(mb)) {
280101704Smjacob		case MPT_DB_STATE_RESET:  text = "Reset";   break;
281101704Smjacob		case MPT_DB_STATE_READY:  text = "Ready";   break;
282101704Smjacob		case MPT_DB_STATE_RUNNING:text = "Running"; break;
283101704Smjacob		case MPT_DB_STATE_FAULT:  text = "Fault";   break;
284101704Smjacob		default: 		  text = "Unknown"; break;
285101704Smjacob	}
286101704Smjacob	return text;
287132107Sstefanf}
288101704Smjacob
289101704Smjacobvoid
290101704Smjacobmpt_print_db(u_int32_t mb)
291101704Smjacob{
292101704Smjacob	printf("mpt mailbox: (0x%x) State %s  WhoInit %s\n",
293101704Smjacob	    mb, mpt_state(mb), mpt_who(MPT_WHO(mb)));
294101704Smjacob}
295101704Smjacob
296101704Smjacob/*****************************************************************************/
297101704Smjacob/*  Reply functions                                                          */
298101704Smjacob/*****************************************************************************/
299101704Smjacobstatic void
300101704Smjacobmpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg)
301101704Smjacob{
302101704Smjacob	printf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg);
303101704Smjacob	printf("\tIOC Status    %s\n", mpt_ioc_status(msg->IOCStatus));
304101704Smjacob	printf("\tIOCLogInfo    0x%08x\n", msg->IOCLogInfo);
305101704Smjacob	printf("\tMsgLength     0x%02x\n", msg->MsgLength);
306101704Smjacob	printf("\tMsgFlags      0x%02x\n", msg->MsgFlags);
307101704Smjacob	printf("\tMsgContext    0x%08x\n", msg->MsgContext);
308101704Smjacob}
309101704Smjacob
310101704Smjacobstatic void
311101704Smjacobmpt_print_init_reply(MSG_IOC_INIT_REPLY *msg)
312101704Smjacob{
313101704Smjacob	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
314101704Smjacob	printf("\tWhoInit       %s\n", mpt_who(msg->WhoInit));
315101704Smjacob	printf("\tMaxDevices    0x%02x\n", msg->MaxDevices);
316101704Smjacob	printf("\tMaxBuses     0x%02x\n", msg->MaxBuses);
317101704Smjacob}
318101704Smjacob
319101704Smjacobstatic void
320101704Smjacobmpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg)
321101704Smjacob{
322101704Smjacob	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
323101704Smjacob	printf("\tIOCNumber     %d\n",		msg->IOCNumber);
324101704Smjacob	printf("\tMaxChainDepth %d\n",		msg->MaxChainDepth);
325101704Smjacob	printf("\tWhoInit       %s\n",		mpt_who(msg->WhoInit));
326101704Smjacob	printf("\tBlockSize     %d\n",		msg->BlockSize);
327101704Smjacob	printf("\tFlags         %d\n",		msg->Flags);
328101704Smjacob	printf("\tReplyQueueDepth %d\n",	msg->ReplyQueueDepth);
329101704Smjacob	printf("\tReqFrameSize  0x%04x\n",	msg->RequestFrameSize);
330102199Smjacob	printf("\tFW Version    0x%08x\n",	msg->FWVersion.Word);
331101704Smjacob	printf("\tProduct ID    0x%04x\n",	msg->ProductID);
332101704Smjacob	printf("\tCredits       0x%04x\n",	msg->GlobalCredits);
333101704Smjacob	printf("\tPorts         %d\n",		msg->NumberOfPorts);
334101704Smjacob	printf("\tEventState    0x%02x\n",	msg->EventState);
335101704Smjacob	printf("\tHostMFA_HA    0x%08x\n",	msg->CurrentHostMfaHighAddr);
336101704Smjacob	printf("\tSenseBuf_HA   0x%08x\n",
337101704Smjacob	    msg->CurrentSenseBufferHighAddr);
338101704Smjacob	printf("\tRepFrameSize  0x%04x\n",	msg->CurReplyFrameSize);
339101704Smjacob	printf("\tMaxDevices    0x%02x\n",	msg->MaxDevices);
340101704Smjacob	printf("\tMaxBuses      0x%02x\n",	msg->MaxBuses);
341101704Smjacob	printf("\tFWImageSize   0x%04x\n",	msg->FWImageSize);
342101704Smjacob}
343101704Smjacob
344101704Smjacobstatic void
345101704Smjacobmpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg)
346101704Smjacob{
347101704Smjacob	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
348101704Smjacob	printf("\tPort:         %d\n", msg->PortNumber);
349101704Smjacob}
350101704Smjacob
351101704Smjacobstatic void
352101704Smjacobmpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg)
353101704Smjacob{
354101704Smjacob	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
355101704Smjacob	printf("\tBus:          %d\n", msg->Bus);
356101704Smjacob	printf("\tTargetID      %d\n", msg->TargetID);
357101704Smjacob	printf("\tCDBLength     %d\n", msg->CDBLength);
358101704Smjacob	printf("\tSCSI Status:  %s\n", mpt_scsi_status(msg->SCSIStatus));
359101704Smjacob	printf("\tSCSI State:   %s\n", mpt_scsi_state(msg->SCSIState));
360101704Smjacob	printf("\tTransferCnt   0x%04x\n", msg->TransferCount);
361101704Smjacob	printf("\tSenseCnt      0x%04x\n", msg->SenseCount);
362101704Smjacob	printf("\tResponseInfo  0x%08x\n", msg->ResponseInfo);
363101704Smjacob}
364101704Smjacob
365101704Smjacob
366101704Smjacob
367101704Smjacobstatic void
368101704Smjacobmpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg)
369101704Smjacob{
370101704Smjacob	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
371101704Smjacob	printf("\tEvent:        %s\n", mpt_ioc_event(msg->Event));
372101704Smjacob	printf("\tEventContext  0x%04x\n", msg->EventContext);
373101704Smjacob	printf("\tAckRequired     %d\n", msg->AckRequired);
374101704Smjacob	printf("\tEventDataLength %d\n", msg->EventDataLength);
375101704Smjacob	printf("\tContinuation    %d\n", msg->MsgFlags & 0x80);
376101704Smjacob	switch(msg->Event) {
377101704Smjacob	case MPI_EVENT_LOG_DATA:
378101704Smjacob		printf("\tEvtLogData:   0x%04x\n", msg->Data[0]);
379101704Smjacob		break;
380101704Smjacob
381101704Smjacob	case MPI_EVENT_UNIT_ATTENTION:
382101704Smjacob		printf("\tTargetID:     0x%04x\n",
383101704Smjacob			msg->Data[0] & 0xff);
384101704Smjacob		printf("\tBus:          0x%04x\n",
385101704Smjacob			(msg->Data[0] >> 8) & 0xff);
386101704Smjacob		break;
387101704Smjacob
388101704Smjacob	case MPI_EVENT_IOC_BUS_RESET:
389101704Smjacob	case MPI_EVENT_EXT_BUS_RESET:
390101704Smjacob	case MPI_EVENT_RESCAN:
391101704Smjacob		printf("\tPort:           %d\n",
392101704Smjacob			(msg->Data[0] >> 8) & 0xff);
393101704Smjacob		break;
394101704Smjacob
395101704Smjacob	case MPI_EVENT_LINK_STATUS_CHANGE:
396101704Smjacob		printf("\tLinkState:    %d\n",
397101704Smjacob			msg->Data[0] & 0xff);
398101704Smjacob		printf("\tPort:         %d\n",
399101704Smjacob			(msg->Data[1] >> 8) & 0xff);
400101704Smjacob		break;
401101704Smjacob
402101704Smjacob	case MPI_EVENT_LOOP_STATE_CHANGE:
403101704Smjacob		printf("\tType:         %d\n",
404101704Smjacob			(msg->Data[0] >> 16) & 0xff);
405101704Smjacob		printf("\tChar3:      0x%02x\n",
406101704Smjacob			(msg->Data[0] >> 8) & 0xff);
407101704Smjacob		printf("\tChar4:      0x%02x\n",
408101704Smjacob			(msg->Data[0]     ) & 0xff);
409101704Smjacob		printf("\tPort:         %d\n",
410101704Smjacob			(msg->Data[1] >> 8) & 0xff);
411101704Smjacob		break;
412101704Smjacob
413101704Smjacob	case MPI_EVENT_LOGOUT:
414101704Smjacob		printf("\tN_PortId:   0x%04x\n", msg->Data[0]);
415101704Smjacob		printf("\tPort:         %d\n",
416101704Smjacob			(msg->Data[1] >> 8) & 0xff);
417101704Smjacob		break;
418101704Smjacob	}
419101704Smjacob
420101704Smjacob}
421101704Smjacob
422101704Smjacobvoid
423101704Smjacobmpt_print_reply(void *vmsg)
424101704Smjacob{
425101704Smjacob	MSG_DEFAULT_REPLY *msg = vmsg;
426101704Smjacob
427101704Smjacob	switch (msg->Function) {
428101704Smjacob	case MPI_FUNCTION_EVENT_NOTIFICATION:
429101704Smjacob		mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg);
430101704Smjacob		break;
431101704Smjacob	case MPI_FUNCTION_PORT_ENABLE:
432101704Smjacob		mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg);
433101704Smjacob		break;
434101704Smjacob	case MPI_FUNCTION_IOC_FACTS:
435101704Smjacob		mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg);
436101704Smjacob		break;
437101704Smjacob	case MPI_FUNCTION_IOC_INIT:
438101704Smjacob		mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg);
439101704Smjacob		break;
440101704Smjacob	case MPI_FUNCTION_SCSI_IO_REQUEST:
441101704Smjacob		mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg);
442101704Smjacob		break;
443101704Smjacob	default:
444101704Smjacob		mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
445101704Smjacob		break;
446101704Smjacob	}
447101704Smjacob}
448101704Smjacob
449101704Smjacob/*****************************************************************************/
450101704Smjacob/*  Request functions                                                        */
451101704Smjacob/*****************************************************************************/
452101704Smjacobstatic void
453101704Smjacobmpt_print_request_hdr(MSG_REQUEST_HEADER *req)
454101704Smjacob{
455101704Smjacob	printf("%s @ %p\n", mpt_ioc_function(req->Function), req);
456101704Smjacob	printf("\tChain Offset  0x%02x\n", req->ChainOffset);
457101704Smjacob	printf("\tMsgFlags      0x%02x\n", req->MsgFlags);
458101704Smjacob	printf("\tMsgContext    0x%08x\n", req->MsgContext);
459101704Smjacob}
460101704Smjacob
461101704Smjacobvoid
462101704Smjacobmpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg)
463101704Smjacob{
464101704Smjacob	MSG_SCSI_IO_REQUEST local, *msg = &local;
465101704Smjacob	int i;
466101704Smjacob
467101704Smjacob	bcopy(orig_msg, msg, sizeof (MSG_SCSI_IO_REQUEST));
468101704Smjacob	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
469101704Smjacob	printf("\tBus:                %d\n", msg->Bus);
470101704Smjacob	printf("\tTargetID            %d\n", msg->TargetID);
471101704Smjacob	printf("\tSenseBufferLength   %d\n", msg->SenseBufferLength);
472101704Smjacob	printf("\tLUN:              0x%0x\n", msg->LUN[1]);
473101704Smjacob	printf("\tControl           0x%08x ", msg->Control);
474101704Smjacob#define MPI_PRINT_FIELD(x)						\
475101704Smjacob	case MPI_SCSIIO_CONTROL_ ## x :					\
476101704Smjacob		printf(" " #x " ");					\
477101704Smjacob		break
478101704Smjacob
479101704Smjacob	switch (msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) {
480101704Smjacob	MPI_PRINT_FIELD(NODATATRANSFER);
481101704Smjacob	MPI_PRINT_FIELD(WRITE);
482101704Smjacob	MPI_PRINT_FIELD(READ);
483101704Smjacob	default:
484101704Smjacob		printf(" Invalid DIR! ");
485101704Smjacob		break;
486101704Smjacob	}
487101704Smjacob	switch (msg->Control & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) {
488101704Smjacob	MPI_PRINT_FIELD(SIMPLEQ);
489101704Smjacob	MPI_PRINT_FIELD(HEADOFQ);
490101704Smjacob	MPI_PRINT_FIELD(ORDEREDQ);
491101704Smjacob	MPI_PRINT_FIELD(ACAQ);
492101704Smjacob	MPI_PRINT_FIELD(UNTAGGED);
493101704Smjacob	MPI_PRINT_FIELD(NO_DISCONNECT);
494101704Smjacob	default:
495101704Smjacob		printf(" Unknown attribute! ");
496101704Smjacob		break;
497101704Smjacob	}
498101704Smjacob
499101704Smjacob	printf("\n");
500101704Smjacob#undef MPI_PRINT_FIELD
501101704Smjacob
502101704Smjacob	printf("\tDataLength\t0x%08x\n", msg->DataLength);
503101704Smjacob	printf("\tSenseBufAddr\t0x%08x\n", msg->SenseBufferLowAddr);
504101704Smjacob	printf("\tCDB[0:%d]\t", msg->CDBLength);
505101704Smjacob	for (i = 0; i < msg->CDBLength; i++)
506101704Smjacob		printf("%02x ", msg->CDB[i]);
507101704Smjacob	printf("\n");
508101704Smjacob	mpt_dump_sgl(&orig_msg->SGL);
509101704Smjacob}
510101704Smjacob
511101704Smjacobvoid
512101704Smjacobmpt_print_request(void *vreq)
513101704Smjacob{
514101704Smjacob	MSG_REQUEST_HEADER *req = vreq;
515101704Smjacob
516101704Smjacob	switch (req->Function) {
517101704Smjacob	case MPI_FUNCTION_SCSI_IO_REQUEST:
518101704Smjacob		mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req);
519101704Smjacob		break;
520101704Smjacob	default:
521101704Smjacob		mpt_print_request_hdr(req);
522101704Smjacob		break;
523101704Smjacob	}
524101704Smjacob}
525101704Smjacob
526101704Smjacobchar *
527101704Smjacobmpt_req_state(enum mpt_req_state state)
528101704Smjacob{
529101704Smjacob	char *text;
530101704Smjacob
531101704Smjacob	switch (state) {
532101704Smjacob	case REQ_FREE:         text = "Free";         break;
533101704Smjacob	case REQ_IN_PROGRESS:  text = "In Progress";  break;
534101704Smjacob	case REQ_ON_CHIP:      text = "On Chip";      break;
535101704Smjacob	case REQ_TIMEOUT:      text = "Timeout";      break;
536101704Smjacob	default: 	       text = "Unknown";      break;
537101704Smjacob	}
538101704Smjacob	return text;
539132107Sstefanf}
540101704Smjacob
541101704Smjacobstatic void
542101704Smjacobmpt_dump_sgl(SGE_IO_UNION *su)
543101704Smjacob{
544101704Smjacob	SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su;
545101704Smjacob	int iCount, flags;
546101704Smjacob
547101704Smjacob	iCount = MPT_SGL_MAX;
548101704Smjacob	do {
549101704Smjacob		int iprt;
550101704Smjacob
551101704Smjacob		printf("\t");
552101704Smjacob		flags = MPI_SGE_GET_FLAGS(se->FlagsLength);
553101704Smjacob		switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) {
554101704Smjacob		case MPI_SGE_FLAGS_SIMPLE_ELEMENT:
555101704Smjacob		{
556101704Smjacob			printf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x\n",
557101704Smjacob			    se, se->Address, se->FlagsLength);
558101704Smjacob			printf(" ");
559101704Smjacob			break;
560101704Smjacob		}
561101704Smjacob		case MPI_SGE_FLAGS_CHAIN_ELEMENT:
562101704Smjacob		{
563101704Smjacob			SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se;
564101704Smjacob			printf("CE32 %p: Addr=0x%0x NxtChnO=0x%x Flgs=0x%x "
565101704Smjacob			    "Len=0x%0x\n", ce, ce->Address, ce->NextChainOffset,
566101704Smjacob			    ce->Flags, ce->Length);
567101704Smjacob			flags = 0;
568101704Smjacob			break;
569101704Smjacob		}
570101704Smjacob		case MPI_SGE_FLAGS_TRANSACTION_ELEMENT:
571101704Smjacob			printf("TE32 @ %p\n", se);
572101704Smjacob			flags = 0;
573101704Smjacob			break;
574101704Smjacob		}
575101704Smjacob		iprt = 0;
576101704Smjacob#define MPT_PRINT_FLAG(x)						\
577101704Smjacob		if (flags & MPI_SGE_FLAGS_ ## x ) { 			\
578101704Smjacob			if (iprt == 0) {				\
579101704Smjacob				printf("\t");				\
580101704Smjacob			}						\
581101704Smjacob			printf(" ");					\
582101704Smjacob			printf( #x );					\
583101704Smjacob			iprt++;						\
584101704Smjacob		}
585101704Smjacob		MPT_PRINT_FLAG(LOCAL_ADDRESS);
586101704Smjacob		MPT_PRINT_FLAG(HOST_TO_IOC);
587101704Smjacob		MPT_PRINT_FLAG(64_BIT_ADDRESSING);
588101704Smjacob		MPT_PRINT_FLAG(LAST_ELEMENT);
589101704Smjacob		MPT_PRINT_FLAG(END_OF_BUFFER);
590101704Smjacob		MPT_PRINT_FLAG(END_OF_LIST);
591101704Smjacob#undef MPT_PRINT_FLAG
592101704Smjacob		if (iprt)
593101704Smjacob			printf("\n");
594101704Smjacob		se++;
595101704Smjacob		iCount -= 1;
596101704Smjacob	} while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && iCount != 0);
597101704Smjacob}
598103914Smjacob
599103914Smjacobvoid
600103914Smjacobmpt_prt(mpt_softc_t *mpt, const char *fmt, ...)
601103914Smjacob{
602103914Smjacob	va_list ap;
603103914Smjacob	printf("%s: ", device_get_nameunit(mpt->dev));
604103914Smjacob	va_start(ap, fmt);
605103914Smjacob	vprintf(fmt, ap);
606103914Smjacob	va_end(ap);
607103914Smjacob	printf("\n");
608103914Smjacob}
609