xref: /freebsd-src/sys/dev/mpt/mpt_debug.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1098ca2bdSWarner Losh /*-
29b631363SMatt Jacob  * Debug routines for LSI '909 FC  adapters.
39b631363SMatt Jacob  * FreeBSD Version.
49b631363SMatt Jacob  *
5*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause AND BSD-3-Clause
6718cf2ccSPedro F. Giffuni  *
79b631363SMatt Jacob  * Copyright (c)  2000, 2001 by Greg Ansley
89b631363SMatt Jacob  *
99b631363SMatt Jacob  * Redistribution and use in source and binary forms, with or without
109b631363SMatt Jacob  * modification, are permitted provided that the following conditions
119b631363SMatt Jacob  * are met:
129b631363SMatt Jacob  * 1. Redistributions of source code must retain the above copyright
139b631363SMatt Jacob  *    notice immediately at the beginning of the file, without modification,
149b631363SMatt Jacob  *    this list of conditions, and the following disclaimer.
159b631363SMatt Jacob  * 2. The name of the author may not be used to endorse or promote products
169b631363SMatt Jacob  *    derived from this software without specific prior written permission.
179b631363SMatt Jacob  *
189b631363SMatt Jacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199b631363SMatt Jacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
209b631363SMatt Jacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219b631363SMatt Jacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
229b631363SMatt Jacob  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
239b631363SMatt Jacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
249b631363SMatt Jacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
259b631363SMatt Jacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
269b631363SMatt Jacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
279b631363SMatt Jacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
289b631363SMatt Jacob  * SUCH DAMAGE.
29b0a2fdeeSScott Long  *
300b80d21bSMatt Jacob  */
310b80d21bSMatt Jacob /*-
320b80d21bSMatt Jacob  * Copyright (c) 2002, 2006 by Matthew Jacob
330b80d21bSMatt Jacob  * All rights reserved.
340b80d21bSMatt Jacob  *
350b80d21bSMatt Jacob  * Redistribution and use in source and binary forms, with or without
360b80d21bSMatt Jacob  * modification, are permitted provided that the following conditions are
370b80d21bSMatt Jacob  * met:
380b80d21bSMatt Jacob  * 1. Redistributions of source code must retain the above copyright
390b80d21bSMatt Jacob  *    notice, this list of conditions and the following disclaimer.
400b80d21bSMatt Jacob  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
410b80d21bSMatt Jacob  *    substantially similar to the "NO WARRANTY" disclaimer below
420b80d21bSMatt Jacob  *    ("Disclaimer") and any redistribution must be conditioned upon including
430b80d21bSMatt Jacob  *    a substantially similar Disclaimer requirement for further binary
440b80d21bSMatt Jacob  *    redistribution.
450b80d21bSMatt Jacob  * 3. Neither the names of the above listed copyright holders nor the names
460b80d21bSMatt Jacob  *    of any contributors may be used to endorse or promote products derived
470b80d21bSMatt Jacob  *    from this software without specific prior written permission.
480b80d21bSMatt Jacob  *
490b80d21bSMatt Jacob  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
500b80d21bSMatt Jacob  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
510b80d21bSMatt Jacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
520b80d21bSMatt Jacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
530b80d21bSMatt Jacob  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
540b80d21bSMatt Jacob  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
550b80d21bSMatt Jacob  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
560b80d21bSMatt Jacob  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
570b80d21bSMatt Jacob  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
580b80d21bSMatt Jacob  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
590b80d21bSMatt Jacob  * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
600b80d21bSMatt Jacob  *
610b80d21bSMatt Jacob  * Support from Chris Ellsworth in order to make SAS adapters work
620b80d21bSMatt Jacob  * is gratefully acknowledged.
63ec5fe39dSMatt Jacob  *
64ec5fe39dSMatt Jacob  * Support from LSI-Logic has also gone a great deal toward making this a
65ec5fe39dSMatt Jacob  * workable subsystem and is gratefully acknowledged.
669b631363SMatt Jacob  */
679b631363SMatt Jacob 
689295c6c5SDavid E. O'Brien #include <sys/cdefs.h>
69b0a2fdeeSScott Long #include <dev/mpt/mpt.h>
70b0a2fdeeSScott Long 
71b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_ioc.h>
72b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_init.h>
73b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_fc.h>
74c87e3f83SMatt Jacob #include <dev/mpt/mpilib/mpi_targ.h>
75b0a2fdeeSScott Long 
76b0a2fdeeSScott Long #include <cam/scsi/scsi_all.h>
77b0a2fdeeSScott Long 
78301472c2SMatt Jacob #include <machine/stdarg.h>	/* for use by mpt_prt below */
799b631363SMatt Jacob 
809b631363SMatt Jacob struct Error_Map {
819b631363SMatt Jacob 	int 	 Error_Code;
829b631363SMatt Jacob 	char    *Error_String;
839b631363SMatt Jacob };
849b631363SMatt Jacob 
859b631363SMatt Jacob static const struct Error_Map IOC_Status[] = {
869b631363SMatt Jacob { MPI_IOCSTATUS_SUCCESS,                  "Success" },
879b631363SMatt Jacob { MPI_IOCSTATUS_INVALID_FUNCTION,         "IOC: Invalid Function" },
889b631363SMatt Jacob { MPI_IOCSTATUS_BUSY,                     "IOC: Busy" },
899b631363SMatt Jacob { MPI_IOCSTATUS_INVALID_SGL,              "IOC: Invalid SGL" },
909b631363SMatt Jacob { MPI_IOCSTATUS_INTERNAL_ERROR,           "IOC: Internal Error" },
919b631363SMatt Jacob { MPI_IOCSTATUS_RESERVED,                 "IOC: Reserved" },
929b631363SMatt Jacob { MPI_IOCSTATUS_INSUFFICIENT_RESOURCES,   "IOC: Insufficient Resources" },
939b631363SMatt Jacob { MPI_IOCSTATUS_INVALID_FIELD,            "IOC: Invalid Field" },
949b631363SMatt Jacob { MPI_IOCSTATUS_INVALID_STATE,            "IOC: Invalid State" },
959b631363SMatt Jacob { MPI_IOCSTATUS_CONFIG_INVALID_ACTION,    "Invalid Action" },
969b631363SMatt Jacob { MPI_IOCSTATUS_CONFIG_INVALID_TYPE,      "Invalid Type" },
979b631363SMatt Jacob { MPI_IOCSTATUS_CONFIG_INVALID_PAGE,      "Invalid Page" },
989b631363SMatt Jacob { MPI_IOCSTATUS_CONFIG_INVALID_DATA,      "Invalid Data" },
999b631363SMatt Jacob { MPI_IOCSTATUS_CONFIG_NO_DEFAULTS,       "No Defaults" },
1009b631363SMatt Jacob { MPI_IOCSTATUS_CONFIG_CANT_COMMIT,       "Can't Commit" },
1019b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_RECOVERED_ERROR,     "SCSI: Recoverd Error" },
1029b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_INVALID_BUS,         "SCSI: Invalid Bus" },
1039b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_INVALID_TARGETID,    "SCSI: Invalid Target ID" },
1049b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE,    "SCSI: Device Not There" },
1059b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_DATA_OVERRUN,        "SCSI: Data Overrun" },
1069b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_DATA_UNDERRUN,       "SCSI: Data Underrun" },
1079b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_IO_DATA_ERROR,       "SCSI: Data Error" },
1089b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR,      "SCSI: Protocol Error" },
1099b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_TASK_TERMINATED,     "SCSI: Task Terminated" },
1109b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH,   "SCSI: Residual Mismatch" },
1119b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED,    "SCSI: Task Management Failed" },
1129b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_IOC_TERMINATED,      "SCSI: IOC Bus Reset" },
1139b631363SMatt Jacob { MPI_IOCSTATUS_SCSI_EXT_TERMINATED,      "SCSI: External Bus Reset" },
1149b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_PRIORITY_IO,       "SCSI Target: Priority I/O" },
1159b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_INVALID_PORT,      "SCSI Target: Invalid Port" },
1169b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_INVALID_IOCINDEX,  "SCSI Target: Invalid IOC Index" },
1179b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_ABORTED,           "SCSI Target: Aborted" },
1189b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE, "SCSI Target: No Connection (Retryable)" },
1199b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_NO_CONNECTION,     "SCSI Target: No Connection" },
1209b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH,"SCSI Target: Transfer Count Mismatch" },
1219b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_FC_ABORTED,        "FC: Aborted" },
1225ab13afcSMarius Strobl { MPI_IOCSTATUS_TARGET_FC_RX_ID_INVALID,  "FC: Receive ID Invalid" },
1235ab13afcSMarius Strobl { MPI_IOCSTATUS_TARGET_FC_DID_INVALID,    "FC: Receive DID Invalid" },
1249b631363SMatt Jacob { MPI_IOCSTATUS_TARGET_FC_NODE_LOGGED_OUT,"FC: Node Logged Out" },
1259b631363SMatt Jacob { MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND,     "LAN: Device Not Found" },
1269b631363SMatt Jacob { MPI_IOCSTATUS_LAN_DEVICE_FAILURE,       "LAN: Device Not Failure" },
1279b631363SMatt Jacob { MPI_IOCSTATUS_LAN_TRANSMIT_ERROR,       "LAN: Transmit Error" },
1289b631363SMatt Jacob { MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED,     "LAN: Transmit Aborted" },
1295ab13afcSMarius Strobl { MPI_IOCSTATUS_LAN_RECEIVE_ERROR,        "LAN: Receive Error" },
1305ab13afcSMarius Strobl { MPI_IOCSTATUS_LAN_RECEIVE_ABORTED,      "LAN: Receive Aborted" },
1319b631363SMatt Jacob { MPI_IOCSTATUS_LAN_PARTIAL_PACKET,       "LAN: Partial Packet" },
1329b631363SMatt Jacob { MPI_IOCSTATUS_LAN_CANCELED,             "LAN: Canceled" },
1339b631363SMatt Jacob { -1, 0},
1349b631363SMatt Jacob };
1359b631363SMatt Jacob 
1369b631363SMatt Jacob static const struct Error_Map IOC_Func[] = {
1379b631363SMatt Jacob { MPI_FUNCTION_SCSI_IO_REQUEST,              "SCSI IO Request" },
1389b631363SMatt Jacob { MPI_FUNCTION_SCSI_TASK_MGMT,               "SCSI Task Management" },
1399b631363SMatt Jacob { MPI_FUNCTION_IOC_INIT,                     "IOC Init" },
1409b631363SMatt Jacob { MPI_FUNCTION_IOC_FACTS,                    "IOC Facts" },
1419b631363SMatt Jacob { MPI_FUNCTION_CONFIG,                       "Config" },
1429b631363SMatt Jacob { MPI_FUNCTION_PORT_FACTS,                   "Port Facts" },
1439b631363SMatt Jacob { MPI_FUNCTION_PORT_ENABLE,                  "Port Enable" },
1449b631363SMatt Jacob { MPI_FUNCTION_EVENT_NOTIFICATION,           "Event Notification" },
145b0a2fdeeSScott Long { MPI_FUNCTION_EVENT_ACK,                    "Event Ack" },
1469b631363SMatt Jacob { MPI_FUNCTION_FW_DOWNLOAD,                  "FW Download" },
1479b631363SMatt Jacob { MPI_FUNCTION_TARGET_CMD_BUFFER_POST,       "SCSI Target Command Buffer" },
1489b631363SMatt Jacob { MPI_FUNCTION_TARGET_ASSIST,                "Target Assist" },
1499b631363SMatt Jacob { MPI_FUNCTION_TARGET_STATUS_SEND,           "Target Status Send" },
1509b631363SMatt Jacob { MPI_FUNCTION_TARGET_MODE_ABORT,            "Target Mode Abort" },
1519b631363SMatt Jacob { -1, 0},
1529b631363SMatt Jacob };
1539b631363SMatt Jacob 
1549b631363SMatt Jacob static const struct Error_Map IOC_Event[] = {
1559b631363SMatt Jacob { MPI_EVENT_NONE,   	                "None" },
1569b631363SMatt Jacob { MPI_EVENT_LOG_DATA,                   "LogData" },
1579b631363SMatt Jacob { MPI_EVENT_STATE_CHANGE,               "State Change" },
1589b631363SMatt Jacob { MPI_EVENT_UNIT_ATTENTION,             "Unit Attention" },
1599b631363SMatt Jacob { MPI_EVENT_IOC_BUS_RESET,              "IOC Bus Reset" },
1609b631363SMatt Jacob { MPI_EVENT_EXT_BUS_RESET,              "External Bus Reset" },
1619b631363SMatt Jacob { MPI_EVENT_RESCAN,        	        "Rescan" },
1629b631363SMatt Jacob { MPI_EVENT_LINK_STATUS_CHANGE,	        "Link Status Change" },
1639b631363SMatt Jacob { MPI_EVENT_LOOP_STATE_CHANGE, 	        "Loop State Change" },
1649b631363SMatt Jacob { MPI_EVENT_LOGOUT,    	       		"Logout" },
1659b631363SMatt Jacob { MPI_EVENT_EVENT_CHANGE,               "EventChange" },
1669b631363SMatt Jacob { -1, 0},
1679b631363SMatt Jacob };
1689b631363SMatt Jacob 
1699b631363SMatt Jacob static const struct Error_Map IOC_SCSIState[] = {
1709b631363SMatt Jacob { MPI_SCSI_STATE_AUTOSENSE_VALID,	"AutoSense_Valid" },
1719b631363SMatt Jacob { MPI_SCSI_STATE_AUTOSENSE_FAILED,	"AutoSense_Failed" },
1729b631363SMatt Jacob { MPI_SCSI_STATE_NO_SCSI_STATUS,	"No_SCSI_Status" },
1739b631363SMatt Jacob { MPI_SCSI_STATE_TERMINATED,	   	"State_Terminated" },
1749b631363SMatt Jacob { MPI_SCSI_STATE_RESPONSE_INFO_VALID,	"Repsonse_Info_Valid" },
1759b631363SMatt Jacob { MPI_SCSI_STATE_QUEUE_TAG_REJECTED,	"Queue Tag Rejected" },
1769b631363SMatt Jacob { -1, 0},
1779b631363SMatt Jacob };
1789b631363SMatt Jacob 
1799b631363SMatt Jacob static const struct Error_Map IOC_SCSIStatus[] = {
1809b631363SMatt Jacob { SCSI_STATUS_OK,			"OK" },
1819b631363SMatt Jacob { SCSI_STATUS_CHECK_COND,		"Check Condition" },
1829b631363SMatt Jacob { SCSI_STATUS_COND_MET,			"Check Condition Met" },
1839b631363SMatt Jacob { SCSI_STATUS_BUSY,			"Busy" },
18400b0158dSGordon Bergling { SCSI_STATUS_INTERMED,			"Intermediate Condition" },
18500b0158dSGordon Bergling { SCSI_STATUS_INTERMED_COND_MET,	"Intermediate Condition Met" },
1869b631363SMatt Jacob { SCSI_STATUS_RESERV_CONFLICT,		"Reservation Conflict" },
1879b631363SMatt Jacob { SCSI_STATUS_CMD_TERMINATED,		"Command Terminated" },
1889b631363SMatt Jacob { SCSI_STATUS_QUEUE_FULL,		"Queue Full" },
1899b631363SMatt Jacob { -1, 0},
1909b631363SMatt Jacob };
1919b631363SMatt Jacob 
1929b631363SMatt Jacob static const struct Error_Map IOC_Diag[] = {
193b0a2fdeeSScott Long { MPI_DIAG_DRWE,		"DWE" },
194b0a2fdeeSScott Long { MPI_DIAG_FLASH_BAD_SIG,	"FLASH_Bad" },
195b0a2fdeeSScott Long { MPI_DIAGNOSTIC_OFFSET,	"Offset" },
196b0a2fdeeSScott Long { MPI_DIAG_RESET_ADAPTER,	"Reset" },
197b0a2fdeeSScott Long { MPI_DIAG_DISABLE_ARM,		"DisARM" },
198b0a2fdeeSScott Long { MPI_DIAG_MEM_ENABLE,		"DME" },
1999b631363SMatt Jacob { -1, 0 },
2009b631363SMatt Jacob };
2019b631363SMatt Jacob 
202b0a2fdeeSScott Long static const struct Error_Map IOC_SCSITMType[] = {
203b0a2fdeeSScott Long { MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,		"Abort Task" },
204b0a2fdeeSScott Long { MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET,	"Abort Task Set" },
205b0a2fdeeSScott Long { MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,	"Target Reset" },
206b0a2fdeeSScott Long { MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,		"Reset Bus" },
207b0a2fdeeSScott Long { MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET,	"Logical Unit Reset" },
208b0a2fdeeSScott Long { -1, 0 },
209b0a2fdeeSScott Long };
2109b631363SMatt Jacob 
2119b631363SMatt Jacob static char *
mpt_ioc_status(int code)2129b631363SMatt Jacob mpt_ioc_status(int code)
2139b631363SMatt Jacob {
2149b631363SMatt Jacob 	const struct Error_Map *status = IOC_Status;
2159b631363SMatt Jacob 	static char buf[64];
2169b631363SMatt Jacob 	while (status->Error_Code >= 0) {
2179b631363SMatt Jacob 		if (status->Error_Code == (code & MPI_IOCSTATUS_MASK))
2189b631363SMatt Jacob 			return status->Error_String;
2199b631363SMatt Jacob 		status++;
2209b631363SMatt Jacob 	}
2219b631363SMatt Jacob 	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
2229b631363SMatt Jacob 	return buf;
2239b631363SMatt Jacob }
2249b631363SMatt Jacob 
2259b631363SMatt Jacob char *
mpt_ioc_diag(u_int32_t code)2269b631363SMatt Jacob mpt_ioc_diag(u_int32_t code)
2279b631363SMatt Jacob {
2289b631363SMatt Jacob 	const struct Error_Map *status = IOC_Diag;
2299b631363SMatt Jacob 	static char buf[128];
2309b631363SMatt Jacob 	char *ptr = buf;
2319b631363SMatt Jacob 	char *end = &buf[128];
2329b631363SMatt Jacob 	buf[0] = '\0';
2339b631363SMatt Jacob 	ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
2349b631363SMatt Jacob 	while (status->Error_Code >= 0) {
2359b631363SMatt Jacob 		if ((status->Error_Code & code) != 0)
2369b631363SMatt Jacob 			ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
2379b631363SMatt Jacob 				status->Error_String);
2389b631363SMatt Jacob 		status++;
2399b631363SMatt Jacob 	}
2409b631363SMatt Jacob 	return buf;
2419b631363SMatt Jacob }
2429b631363SMatt Jacob 
2439b631363SMatt Jacob static char *
mpt_ioc_function(int code)2449b631363SMatt Jacob mpt_ioc_function(int code)
2459b631363SMatt Jacob {
2469b631363SMatt Jacob 	const struct Error_Map *status = IOC_Func;
2479b631363SMatt Jacob 	static char buf[64];
2489b631363SMatt Jacob 	while (status->Error_Code >= 0) {
2499b631363SMatt Jacob 		if (status->Error_Code == code)
2509b631363SMatt Jacob 			return status->Error_String;
2519b631363SMatt Jacob 		status++;
2529b631363SMatt Jacob 	}
2539b631363SMatt Jacob 	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
2549b631363SMatt Jacob 	return buf;
2559b631363SMatt Jacob }
2565e073106SMatt Jacob 
2579b631363SMatt Jacob static char *
mpt_ioc_event(int code)2589b631363SMatt Jacob mpt_ioc_event(int code)
2599b631363SMatt Jacob {
2609b631363SMatt Jacob 	const struct Error_Map *status = IOC_Event;
2619b631363SMatt Jacob 	static char buf[64];
2629b631363SMatt Jacob 	while (status->Error_Code >= 0) {
2639b631363SMatt Jacob 		if (status->Error_Code == code)
2649b631363SMatt Jacob 			return status->Error_String;
2659b631363SMatt Jacob 		status++;
2669b631363SMatt Jacob 	}
2679b631363SMatt Jacob 	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
2689b631363SMatt Jacob 	return buf;
2699b631363SMatt Jacob }
2705e073106SMatt Jacob 
2719b631363SMatt Jacob static char *
mpt_scsi_state(int code)2729b631363SMatt Jacob mpt_scsi_state(int code)
2739b631363SMatt Jacob {
2749b631363SMatt Jacob 	const struct Error_Map *status = IOC_SCSIState;
2759b631363SMatt Jacob 	static char buf[128];
2769b631363SMatt Jacob 	char *ptr = buf;
2779b631363SMatt Jacob 	char *end = &buf[128];
2789b631363SMatt Jacob 	buf[0] = '\0';
2799b631363SMatt Jacob 	ptr += snprintf(buf, sizeof buf, "(0x%08x)", code);
2809b631363SMatt Jacob 	while (status->Error_Code >= 0) {
2819b631363SMatt Jacob 		if ((status->Error_Code & code) != 0)
2829b631363SMatt Jacob 			ptr += snprintf(ptr, (size_t)(end-ptr), "%s ",
2839b631363SMatt Jacob 				status->Error_String);
2849b631363SMatt Jacob 		status++;
2859b631363SMatt Jacob 	}
2869b631363SMatt Jacob 	return buf;
2879b631363SMatt Jacob }
28887e255acSMarius Strobl 
2899b631363SMatt Jacob static char *
mpt_scsi_status(int code)2909b631363SMatt Jacob mpt_scsi_status(int code)
2919b631363SMatt Jacob {
2929b631363SMatt Jacob 	const struct Error_Map *status = IOC_SCSIStatus;
2939b631363SMatt Jacob 	static char buf[64];
2949b631363SMatt Jacob 	while (status->Error_Code >= 0) {
2959b631363SMatt Jacob 		if (status->Error_Code == code)
2969b631363SMatt Jacob 			return status->Error_String;
2979b631363SMatt Jacob 		status++;
2989b631363SMatt Jacob 	}
2999b631363SMatt Jacob 	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
3009b631363SMatt Jacob 	return buf;
3019b631363SMatt Jacob }
30287e255acSMarius Strobl 
30387e255acSMarius Strobl static const char *
mpt_who(int who_init)3049b631363SMatt Jacob mpt_who(int who_init)
3059b631363SMatt Jacob {
30687e255acSMarius Strobl 	const char *who;
3079b631363SMatt Jacob 
3089b631363SMatt Jacob 	switch (who_init) {
3099b631363SMatt Jacob 	case MPT_DB_INIT_NOONE:       who = "No One";        break;
3109b631363SMatt Jacob 	case MPT_DB_INIT_BIOS:        who = "BIOS";          break;
3119b631363SMatt Jacob 	case MPT_DB_INIT_ROMBIOS:     who = "ROM BIOS";      break;
3129b631363SMatt Jacob 	case MPT_DB_INIT_PCIPEER:     who = "PCI Peer";      break;
3139b631363SMatt Jacob 	case MPT_DB_INIT_HOST:        who = "Host Driver";   break;
3149b631363SMatt Jacob 	case MPT_DB_INIT_MANUFACTURE: who = "Manufacturing"; break;
3159b631363SMatt Jacob 	default:                      who = "Unknown";       break;
3169b631363SMatt Jacob 	}
3179b631363SMatt Jacob 	return who;
3189b631363SMatt Jacob }
3199b631363SMatt Jacob 
32087e255acSMarius Strobl static const char *
mpt_state(u_int32_t mb)3219b631363SMatt Jacob mpt_state(u_int32_t mb)
3229b631363SMatt Jacob {
32387e255acSMarius Strobl 	const char *text;
3249b631363SMatt Jacob 
3259b631363SMatt Jacob 	switch (MPT_STATE(mb)) {
3269b631363SMatt Jacob 		case MPT_DB_STATE_RESET:  text = "Reset";   break;
3279b631363SMatt Jacob 		case MPT_DB_STATE_READY:  text = "Ready";   break;
3289b631363SMatt Jacob 		case MPT_DB_STATE_RUNNING:text = "Running"; break;
3299b631363SMatt Jacob 		case MPT_DB_STATE_FAULT:  text = "Fault";   break;
3309b631363SMatt Jacob 		default: 		  text = "Unknown"; break;
3319b631363SMatt Jacob 	}
3329b631363SMatt Jacob 	return text;
333439dfb0cSStefan Farfeleder }
3349b631363SMatt Jacob 
335b0a2fdeeSScott Long static char *
mpt_scsi_tm_type(int code)336b0a2fdeeSScott Long mpt_scsi_tm_type(int code)
337b0a2fdeeSScott Long {
338b0a2fdeeSScott Long 	const struct Error_Map *status = IOC_SCSITMType;
339b0a2fdeeSScott Long 	static char buf[64];
340b0a2fdeeSScott Long 	while (status->Error_Code >= 0) {
341b0a2fdeeSScott Long 		if (status->Error_Code == code)
342b0a2fdeeSScott Long 			return status->Error_String;
343b0a2fdeeSScott Long 		status++;
344b0a2fdeeSScott Long 	}
345b0a2fdeeSScott Long 	snprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
346b0a2fdeeSScott Long 	return buf;
347b0a2fdeeSScott Long }
348b0a2fdeeSScott Long 
3499b631363SMatt Jacob void
mpt_print_db(u_int32_t mb)3509b631363SMatt Jacob mpt_print_db(u_int32_t mb)
3519b631363SMatt Jacob {
35287e255acSMarius Strobl 
3539b631363SMatt Jacob 	printf("mpt mailbox: (0x%x) State %s  WhoInit %s\n",
3549b631363SMatt Jacob 	    mb, mpt_state(mb), mpt_who(MPT_WHO(mb)));
3559b631363SMatt Jacob }
3569b631363SMatt Jacob 
3579b631363SMatt Jacob /*****************************************************************************/
3589b631363SMatt Jacob /*  Reply functions                                                          */
3599b631363SMatt Jacob /*****************************************************************************/
3609b631363SMatt Jacob static void
mpt_print_reply_hdr(MSG_DEFAULT_REPLY * msg)3619b631363SMatt Jacob mpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg)
3629b631363SMatt Jacob {
36387e255acSMarius Strobl 
3649b631363SMatt Jacob 	printf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg);
3659b631363SMatt Jacob 	printf("\tIOC Status    %s\n", mpt_ioc_status(msg->IOCStatus));
3666a9fa015SMatt Jacob 	printf("\tIOCLogInfo    0x%08x\n", msg->IOCLogInfo);
3679b631363SMatt Jacob 	printf("\tMsgLength     0x%02x\n", msg->MsgLength);
3689b631363SMatt Jacob 	printf("\tMsgFlags      0x%02x\n", msg->MsgFlags);
3696a9fa015SMatt Jacob 	printf("\tMsgContext    0x%08x\n", msg->MsgContext);
3709b631363SMatt Jacob }
3719b631363SMatt Jacob 
3729b631363SMatt Jacob static void
mpt_print_init_reply(MSG_IOC_INIT_REPLY * msg)3739b631363SMatt Jacob mpt_print_init_reply(MSG_IOC_INIT_REPLY *msg)
3749b631363SMatt Jacob {
37587e255acSMarius Strobl 
3769b631363SMatt Jacob 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
3779b631363SMatt Jacob 	printf("\tWhoInit       %s\n", mpt_who(msg->WhoInit));
3789b631363SMatt Jacob 	printf("\tMaxDevices    0x%02x\n", msg->MaxDevices);
3799b631363SMatt Jacob 	printf("\tMaxBuses     0x%02x\n", msg->MaxBuses);
3809b631363SMatt Jacob }
3819b631363SMatt Jacob 
3829b631363SMatt Jacob static void
mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY * msg)3839b631363SMatt Jacob mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg)
3849b631363SMatt Jacob {
38587e255acSMarius Strobl 
3869b631363SMatt Jacob 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
3879b631363SMatt Jacob 	printf("\tIOCNumber     %d\n",		msg->IOCNumber);
3889b631363SMatt Jacob 	printf("\tMaxChainDepth %d\n",		msg->MaxChainDepth);
3899b631363SMatt Jacob 	printf("\tWhoInit       %s\n",		mpt_who(msg->WhoInit));
3909b631363SMatt Jacob 	printf("\tBlockSize     %d\n",		msg->BlockSize);
3919b631363SMatt Jacob 	printf("\tFlags         %d\n",		msg->Flags);
3929b631363SMatt Jacob 	printf("\tReplyQueueDepth %d\n",	msg->ReplyQueueDepth);
3939b631363SMatt Jacob 	printf("\tReqFrameSize  0x%04x\n",	msg->RequestFrameSize);
3946a9fa015SMatt Jacob 	printf("\tFW Version    0x%08x\n",	msg->FWVersion.Word);
3959b631363SMatt Jacob 	printf("\tProduct ID    0x%04x\n",	msg->ProductID);
3969b631363SMatt Jacob 	printf("\tCredits       0x%04x\n",	msg->GlobalCredits);
3979b631363SMatt Jacob 	printf("\tPorts         %d\n",		msg->NumberOfPorts);
3989b631363SMatt Jacob 	printf("\tEventState    0x%02x\n",	msg->EventState);
3996a9fa015SMatt Jacob 	printf("\tHostMFA_HA    0x%08x\n",	msg->CurrentHostMfaHighAddr);
4006a9fa015SMatt Jacob 	printf("\tSenseBuf_HA   0x%08x\n",
4019b631363SMatt Jacob 	    msg->CurrentSenseBufferHighAddr);
4029b631363SMatt Jacob 	printf("\tRepFrameSize  0x%04x\n",	msg->CurReplyFrameSize);
4039b631363SMatt Jacob 	printf("\tMaxDevices    0x%02x\n",	msg->MaxDevices);
4049b631363SMatt Jacob 	printf("\tMaxBuses      0x%02x\n",	msg->MaxBuses);
4056a9fa015SMatt Jacob 	printf("\tFWImageSize   0x%04x\n",	msg->FWImageSize);
4069b631363SMatt Jacob }
4079b631363SMatt Jacob 
4089b631363SMatt Jacob static void
mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY * msg)4099b631363SMatt Jacob mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg)
4109b631363SMatt Jacob {
41187e255acSMarius Strobl 
4129b631363SMatt Jacob 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
4139b631363SMatt Jacob 	printf("\tPort:         %d\n", msg->PortNumber);
4149b631363SMatt Jacob }
4159b631363SMatt Jacob 
4169b631363SMatt Jacob static void
mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY * msg)4179b631363SMatt Jacob mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg)
4189b631363SMatt Jacob {
41987e255acSMarius Strobl 
4209b631363SMatt Jacob 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
4219b631363SMatt Jacob 	printf("\tBus:          %d\n", msg->Bus);
4229b631363SMatt Jacob 	printf("\tTargetID      %d\n", msg->TargetID);
4239b631363SMatt Jacob 	printf("\tCDBLength     %d\n", msg->CDBLength);
4249b631363SMatt Jacob 	printf("\tSCSI Status:  %s\n", mpt_scsi_status(msg->SCSIStatus));
4259b631363SMatt Jacob 	printf("\tSCSI State:   %s\n", mpt_scsi_state(msg->SCSIState));
4266a9fa015SMatt Jacob 	printf("\tTransferCnt   0x%04x\n", msg->TransferCount);
4276a9fa015SMatt Jacob 	printf("\tSenseCnt      0x%04x\n", msg->SenseCount);
4286a9fa015SMatt Jacob 	printf("\tResponseInfo  0x%08x\n", msg->ResponseInfo);
4299b631363SMatt Jacob }
4309b631363SMatt Jacob 
4319b631363SMatt Jacob static void
mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY * msg)4329b631363SMatt Jacob mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg)
4339b631363SMatt Jacob {
43487e255acSMarius Strobl 
4359b631363SMatt Jacob 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
4369b631363SMatt Jacob 	printf("\tEvent:        %s\n", mpt_ioc_event(msg->Event));
4376a9fa015SMatt Jacob 	printf("\tEventContext  0x%04x\n", msg->EventContext);
4389b631363SMatt Jacob 	printf("\tAckRequired     %d\n", msg->AckRequired);
4399b631363SMatt Jacob 	printf("\tEventDataLength %d\n", msg->EventDataLength);
4409b631363SMatt Jacob 	printf("\tContinuation    %d\n", msg->MsgFlags & 0x80);
4419b631363SMatt Jacob 	switch(msg->Event) {
4429b631363SMatt Jacob 	case MPI_EVENT_LOG_DATA:
4436a9fa015SMatt Jacob 		printf("\tEvtLogData:   0x%04x\n", msg->Data[0]);
4449b631363SMatt Jacob 		break;
4459b631363SMatt Jacob 
4469b631363SMatt Jacob 	case MPI_EVENT_UNIT_ATTENTION:
4476a9fa015SMatt Jacob 		printf("\tTargetID:     0x%04x\n",
4486a9fa015SMatt Jacob 			msg->Data[0] & 0xff);
4496a9fa015SMatt Jacob 		printf("\tBus:          0x%04x\n",
4506a9fa015SMatt Jacob 			(msg->Data[0] >> 8) & 0xff);
4519b631363SMatt Jacob 		break;
4529b631363SMatt Jacob 
4539b631363SMatt Jacob 	case MPI_EVENT_IOC_BUS_RESET:
4549b631363SMatt Jacob 	case MPI_EVENT_EXT_BUS_RESET:
4559b631363SMatt Jacob 	case MPI_EVENT_RESCAN:
4566a9fa015SMatt Jacob 		printf("\tPort:           %d\n",
4576a9fa015SMatt Jacob 			(msg->Data[0] >> 8) & 0xff);
4589b631363SMatt Jacob 		break;
4599b631363SMatt Jacob 
4609b631363SMatt Jacob 	case MPI_EVENT_LINK_STATUS_CHANGE:
4616a9fa015SMatt Jacob 		printf("\tLinkState:    %d\n",
4626a9fa015SMatt Jacob 			msg->Data[0] & 0xff);
4636a9fa015SMatt Jacob 		printf("\tPort:         %d\n",
4646a9fa015SMatt Jacob 			(msg->Data[1] >> 8) & 0xff);
4659b631363SMatt Jacob 		break;
4669b631363SMatt Jacob 
4679b631363SMatt Jacob 	case MPI_EVENT_LOOP_STATE_CHANGE:
4686a9fa015SMatt Jacob 		printf("\tType:         %d\n",
4696a9fa015SMatt Jacob 			(msg->Data[0] >> 16) & 0xff);
4706a9fa015SMatt Jacob 		printf("\tChar3:      0x%02x\n",
4716a9fa015SMatt Jacob 			(msg->Data[0] >> 8) & 0xff);
4726a9fa015SMatt Jacob 		printf("\tChar4:      0x%02x\n",
4736a9fa015SMatt Jacob 			(msg->Data[0]     ) & 0xff);
4746a9fa015SMatt Jacob 		printf("\tPort:         %d\n",
4756a9fa015SMatt Jacob 			(msg->Data[1] >> 8) & 0xff);
4769b631363SMatt Jacob 		break;
4779b631363SMatt Jacob 
4789b631363SMatt Jacob 	case MPI_EVENT_LOGOUT:
4796a9fa015SMatt Jacob 		printf("\tN_PortId:   0x%04x\n", msg->Data[0]);
4806a9fa015SMatt Jacob 		printf("\tPort:         %d\n",
4816a9fa015SMatt Jacob 			(msg->Data[1] >> 8) & 0xff);
4829b631363SMatt Jacob 		break;
4839b631363SMatt Jacob 	}
4849b631363SMatt Jacob 
4859b631363SMatt Jacob }
4869b631363SMatt Jacob 
4879b631363SMatt Jacob void
mpt_print_reply(void * vmsg)4889b631363SMatt Jacob mpt_print_reply(void *vmsg)
4899b631363SMatt Jacob {
4909b631363SMatt Jacob 	MSG_DEFAULT_REPLY *msg = vmsg;
4919b631363SMatt Jacob 
4929b631363SMatt Jacob 	switch (msg->Function) {
4939b631363SMatt Jacob 	case MPI_FUNCTION_EVENT_NOTIFICATION:
4949b631363SMatt Jacob 		mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg);
4959b631363SMatt Jacob 		break;
4969b631363SMatt Jacob 	case MPI_FUNCTION_PORT_ENABLE:
4979b631363SMatt Jacob 		mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg);
4989b631363SMatt Jacob 		break;
4999b631363SMatt Jacob 	case MPI_FUNCTION_IOC_FACTS:
5009b631363SMatt Jacob 		mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg);
5019b631363SMatt Jacob 		break;
5029b631363SMatt Jacob 	case MPI_FUNCTION_IOC_INIT:
5039b631363SMatt Jacob 		mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg);
5049b631363SMatt Jacob 		break;
5059b631363SMatt Jacob 	case MPI_FUNCTION_SCSI_IO_REQUEST:
506a3116b5aSMatt Jacob 	case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
5079b631363SMatt Jacob 		mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg);
5089b631363SMatt Jacob 		break;
5099b631363SMatt Jacob 	default:
5109b631363SMatt Jacob 		mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
5119b631363SMatt Jacob 		break;
5129b631363SMatt Jacob 	}
5139b631363SMatt Jacob }
5149b631363SMatt Jacob 
5159b631363SMatt Jacob /*****************************************************************************/
5169b631363SMatt Jacob /*  Request functions                                                        */
5179b631363SMatt Jacob /*****************************************************************************/
5189b631363SMatt Jacob static void
mpt_print_request_hdr(MSG_REQUEST_HEADER * req)5199b631363SMatt Jacob mpt_print_request_hdr(MSG_REQUEST_HEADER *req)
5209b631363SMatt Jacob {
5214b847ffaSMarius Strobl 
5229b631363SMatt Jacob 	printf("%s @ %p\n", mpt_ioc_function(req->Function), req);
5239b631363SMatt Jacob 	printf("\tChain Offset  0x%02x\n", req->ChainOffset);
5249b631363SMatt Jacob 	printf("\tMsgFlags      0x%02x\n", req->MsgFlags);
5256a9fa015SMatt Jacob 	printf("\tMsgContext    0x%08x\n", req->MsgContext);
5269b631363SMatt Jacob }
5279b631363SMatt Jacob 
52887e255acSMarius Strobl static void
mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST * orig_msg)5299b631363SMatt Jacob mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg)
5309b631363SMatt Jacob {
5319b631363SMatt Jacob 	MSG_SCSI_IO_REQUEST local, *msg = &local;
5329b631363SMatt Jacob 	int i;
5339b631363SMatt Jacob 
5349b631363SMatt Jacob 	bcopy(orig_msg, msg, sizeof (MSG_SCSI_IO_REQUEST));
5359b631363SMatt Jacob 	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
5369b631363SMatt Jacob 	printf("\tBus:                %d\n", msg->Bus);
5379b631363SMatt Jacob 	printf("\tTargetID            %d\n", msg->TargetID);
5389b631363SMatt Jacob 	printf("\tSenseBufferLength   %d\n", msg->SenseBufferLength);
539ead3ad6bSAlexander Motin 	printf("\tLUN:              0x%jx\n", (uintmax_t)be64dec(msg->LUN));
5406a9fa015SMatt Jacob 	printf("\tControl           0x%08x ", msg->Control);
5419b631363SMatt Jacob #define MPI_PRINT_FIELD(x)						\
5429b631363SMatt Jacob 	case MPI_SCSIIO_CONTROL_ ## x :					\
5439b631363SMatt Jacob 		printf(" " #x " ");					\
5449b631363SMatt Jacob 		break
5459b631363SMatt Jacob 
5469b631363SMatt Jacob 	switch (msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) {
5479b631363SMatt Jacob 	MPI_PRINT_FIELD(NODATATRANSFER);
5489b631363SMatt Jacob 	MPI_PRINT_FIELD(WRITE);
5499b631363SMatt Jacob 	MPI_PRINT_FIELD(READ);
5509b631363SMatt Jacob 	default:
5519b631363SMatt Jacob 		printf(" Invalid DIR! ");
5529b631363SMatt Jacob 		break;
5539b631363SMatt Jacob 	}
5549b631363SMatt Jacob 	switch (msg->Control & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) {
5559b631363SMatt Jacob 	MPI_PRINT_FIELD(SIMPLEQ);
5569b631363SMatt Jacob 	MPI_PRINT_FIELD(HEADOFQ);
5579b631363SMatt Jacob 	MPI_PRINT_FIELD(ORDEREDQ);
5589b631363SMatt Jacob 	MPI_PRINT_FIELD(ACAQ);
5599b631363SMatt Jacob 	MPI_PRINT_FIELD(UNTAGGED);
5609b631363SMatt Jacob 	MPI_PRINT_FIELD(NO_DISCONNECT);
5619b631363SMatt Jacob 	default:
5629b631363SMatt Jacob 		printf(" Unknown attribute! ");
5639b631363SMatt Jacob 		break;
5649b631363SMatt Jacob 	}
5659b631363SMatt Jacob 
5669b631363SMatt Jacob 	printf("\n");
5679b631363SMatt Jacob #undef MPI_PRINT_FIELD
5689b631363SMatt Jacob 
5696a9fa015SMatt Jacob 	printf("\tDataLength\t0x%08x\n", msg->DataLength);
5706a9fa015SMatt Jacob 	printf("\tSenseBufAddr\t0x%08x\n", msg->SenseBufferLowAddr);
5719b631363SMatt Jacob 	printf("\tCDB[0:%d]\t", msg->CDBLength);
5729b631363SMatt Jacob 	for (i = 0; i < msg->CDBLength; i++)
5739b631363SMatt Jacob 		printf("%02x ", msg->CDB[i]);
5749b631363SMatt Jacob 	printf("\n");
575444dd2b6SMatt Jacob 
576444dd2b6SMatt Jacob 	if ((msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) !=
577444dd2b6SMatt Jacob 	   MPI_SCSIIO_CONTROL_NODATATRANSFER ) {
578444dd2b6SMatt Jacob 		mpt_dump_sgl(&orig_msg->SGL,
579444dd2b6SMatt Jacob 		    ((char *)&orig_msg->SGL)-(char *)orig_msg);
580444dd2b6SMatt Jacob 	}
5819b631363SMatt Jacob }
5829b631363SMatt Jacob 
583b0a2fdeeSScott Long static void
mpt_print_scsi_tmf_request(MSG_SCSI_TASK_MGMT * msg)584b0a2fdeeSScott Long mpt_print_scsi_tmf_request(MSG_SCSI_TASK_MGMT *msg)
585b0a2fdeeSScott Long {
58687e255acSMarius Strobl 
587b0a2fdeeSScott Long 	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
588ead3ad6bSAlexander Motin 	printf("\tLun             0x%jx\n", (uintmax_t)be64dec(msg->LUN));
589b0a2fdeeSScott Long 	printf("\tTaskType        %s\n", mpt_scsi_tm_type(msg->TaskType));
5906a9fa015SMatt Jacob 	printf("\tTaskMsgContext  0x%08x\n", msg->TaskMsgContext);
591b0a2fdeeSScott Long }
592b0a2fdeeSScott Long 
593c87e3f83SMatt Jacob static void
mpt_print_scsi_target_assist_request(PTR_MSG_TARGET_ASSIST_REQUEST msg)594c87e3f83SMatt Jacob mpt_print_scsi_target_assist_request(PTR_MSG_TARGET_ASSIST_REQUEST msg)
595c87e3f83SMatt Jacob {
59687e255acSMarius Strobl 
597c87e3f83SMatt Jacob 	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
598c87e3f83SMatt Jacob 	printf("\tStatusCode    0x%02x\n", msg->StatusCode);
599c87e3f83SMatt Jacob 	printf("\tTargetAssist  0x%02x\n", msg->TargetAssistFlags);
600c87e3f83SMatt Jacob 	printf("\tQueueTag      0x%04x\n", msg->QueueTag);
601c87e3f83SMatt Jacob 	printf("\tReplyWord     0x%08x\n", msg->ReplyWord);
602ead3ad6bSAlexander Motin 	printf("\tLun           0x%jx\n", (uintmax_t)be64dec(msg->LUN));
603c87e3f83SMatt Jacob 	printf("\tRelativeOff   0x%08x\n", msg->RelativeOffset);
604c87e3f83SMatt Jacob 	printf("\tDataLength    0x%08x\n", msg->DataLength);
605c87e3f83SMatt Jacob 	mpt_dump_sgl(msg->SGL, 0);
606c87e3f83SMatt Jacob }
607c87e3f83SMatt Jacob 
608c87e3f83SMatt Jacob static void
mpt_print_scsi_target_status_send_request(MSG_TARGET_STATUS_SEND_REQUEST * msg)609c87e3f83SMatt Jacob mpt_print_scsi_target_status_send_request(MSG_TARGET_STATUS_SEND_REQUEST *msg)
610c87e3f83SMatt Jacob {
611c87e3f83SMatt Jacob 	SGE_IO_UNION x;
61287e255acSMarius Strobl 
613c87e3f83SMatt Jacob 	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
614c87e3f83SMatt Jacob 	printf("\tStatusCode    0x%02x\n", msg->StatusCode);
615c87e3f83SMatt Jacob 	printf("\tStatusFlags   0x%02x\n", msg->StatusFlags);
616c87e3f83SMatt Jacob 	printf("\tQueueTag      0x%04x\n", msg->QueueTag);
617c87e3f83SMatt Jacob 	printf("\tReplyWord     0x%08x\n", msg->ReplyWord);
618ead3ad6bSAlexander Motin 	printf("\tLun           0x%jx\n", (uintmax_t)be64dec(msg->LUN));
619c87e3f83SMatt Jacob 	x.u.Simple = msg->StatusDataSGE;
620c87e3f83SMatt Jacob 	mpt_dump_sgl(&x, 0);
621c87e3f83SMatt Jacob }
622c87e3f83SMatt Jacob 
6239b631363SMatt Jacob void
mpt_print_request(void * vreq)6249b631363SMatt Jacob mpt_print_request(void *vreq)
6259b631363SMatt Jacob {
6269b631363SMatt Jacob 	MSG_REQUEST_HEADER *req = vreq;
6279b631363SMatt Jacob 
6289b631363SMatt Jacob 	switch (req->Function) {
6299b631363SMatt Jacob 	case MPI_FUNCTION_SCSI_IO_REQUEST:
630a3116b5aSMatt Jacob 	case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
6319b631363SMatt Jacob 		mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req);
6329b631363SMatt Jacob 		break;
633b0a2fdeeSScott Long 	case MPI_FUNCTION_SCSI_TASK_MGMT:
634b0a2fdeeSScott Long 		mpt_print_scsi_tmf_request((MSG_SCSI_TASK_MGMT *)req);
635c87e3f83SMatt Jacob 		break;
636c87e3f83SMatt Jacob 	case MPI_FUNCTION_TARGET_ASSIST:
637c87e3f83SMatt Jacob 		mpt_print_scsi_target_assist_request(
638c87e3f83SMatt Jacob 		    (PTR_MSG_TARGET_ASSIST_REQUEST)req);
639c87e3f83SMatt Jacob 		break;
640c87e3f83SMatt Jacob 	case MPI_FUNCTION_TARGET_STATUS_SEND:
641c87e3f83SMatt Jacob 		mpt_print_scsi_target_status_send_request(
642c87e3f83SMatt Jacob 		    (MSG_TARGET_STATUS_SEND_REQUEST *)req);
643c87e3f83SMatt Jacob 		break;
6449b631363SMatt Jacob 	default:
6459b631363SMatt Jacob 		mpt_print_request_hdr(req);
6469b631363SMatt Jacob 		break;
6479b631363SMatt Jacob 	}
6489b631363SMatt Jacob }
6499b631363SMatt Jacob 
65087e255acSMarius Strobl #if 0
65187e255acSMarius Strobl typedef struct mpt_decode_entry {
65287e255acSMarius Strobl 	char    *name;
65387e255acSMarius Strobl 	u_int	 value;
65487e255acSMarius Strobl 	u_int	 mask;
65587e255acSMarius Strobl } mpt_decode_entry_t;
65687e255acSMarius Strobl 
65787e255acSMarius Strobl static int
658b0a2fdeeSScott Long mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries,
659b0a2fdeeSScott Long 		 const char *name, u_int value, u_int *cur_column,
660b0a2fdeeSScott Long 		 u_int wrap_point)
6619b631363SMatt Jacob {
662b0a2fdeeSScott Long         int     printed;
663b0a2fdeeSScott Long         u_int   printed_mask;
664b0a2fdeeSScott Long 	u_int	dummy_column;
6659b631363SMatt Jacob 
666b0a2fdeeSScott Long 	if (cur_column == NULL) {
667b0a2fdeeSScott Long 		dummy_column = 0;
668b0a2fdeeSScott Long 		cur_column = &dummy_column;
6699b631363SMatt Jacob 	}
670b0a2fdeeSScott Long 
671b0a2fdeeSScott Long 	if (*cur_column >= wrap_point) {
672b0a2fdeeSScott Long 		printf("\n");
673b0a2fdeeSScott Long 		*cur_column = 0;
674b0a2fdeeSScott Long 	}
675b0a2fdeeSScott Long 	printed = printf("%s[0x%x]", name, value);
676b0a2fdeeSScott Long 	if (table == NULL) {
677b0a2fdeeSScott Long 		printed += printf(" ");
678b0a2fdeeSScott Long 		*cur_column += printed;
679b0a2fdeeSScott Long 		return (printed);
680b0a2fdeeSScott Long 	}
681b0a2fdeeSScott Long 	printed_mask = 0;
682b0a2fdeeSScott Long 	while (printed_mask != 0xFF) {
683b0a2fdeeSScott Long 		int entry;
684b0a2fdeeSScott Long 
685b0a2fdeeSScott Long 		for (entry = 0; entry < num_entries; entry++) {
686b0a2fdeeSScott Long 			if (((value & table[entry].mask)
687b0a2fdeeSScott Long 			  != table[entry].value)
688b0a2fdeeSScott Long 			 || ((printed_mask & table[entry].mask)
689b0a2fdeeSScott Long 			  == table[entry].mask))
690b0a2fdeeSScott Long 				continue;
691b0a2fdeeSScott Long 
692b0a2fdeeSScott Long 			printed += printf("%s%s",
693b0a2fdeeSScott Long 					  printed_mask == 0 ? ":(" : "|",
694b0a2fdeeSScott Long 					  table[entry].name);
695b0a2fdeeSScott Long 			printed_mask |= table[entry].mask;
696b0a2fdeeSScott Long 			break;
697b0a2fdeeSScott Long                 }
698b0a2fdeeSScott Long 		if (entry >= num_entries)
699b0a2fdeeSScott Long 			break;
700b0a2fdeeSScott Long         }
701b0a2fdeeSScott Long         if (printed_mask != 0)
702b0a2fdeeSScott Long 		printed += printf(") ");
703b0a2fdeeSScott Long         else
704b0a2fdeeSScott Long 		printed += printf(" ");
705b0a2fdeeSScott Long 	*cur_column += printed;
706b0a2fdeeSScott Long 	return (printed);
707b0a2fdeeSScott Long }
708b0a2fdeeSScott Long 
70987e255acSMarius Strobl static const mpt_decode_entry_t req_state_parse_table[] = {
710b0a2fdeeSScott Long 	{ "REQ_FREE",		0x00, 0xff },
711b0a2fdeeSScott Long 	{ "REQ_ALLOCATED",	0x01, 0x01 },
712b0a2fdeeSScott Long 	{ "REQ_QUEUED",		0x02, 0x02 },
713b0a2fdeeSScott Long 	{ "REQ_DONE",		0x04, 0x04 },
714b0a2fdeeSScott Long 	{ "REQ_TIMEDOUT",	0x08, 0x08 },
715b0a2fdeeSScott Long 	{ "REQ_NEED_WAKEUP",	0x10, 0x10 }
716b0a2fdeeSScott Long };
717b0a2fdeeSScott Long 
71887e255acSMarius Strobl static void
719b0a2fdeeSScott Long mpt_req_state(mpt_req_state_t state)
720b0a2fdeeSScott Long {
72187e255acSMarius Strobl 
722b0a2fdeeSScott Long 	mpt_decode_value(req_state_parse_table,
723b0a2fdeeSScott Long 			 NUM_ELEMENTS(req_state_parse_table),
724b0a2fdeeSScott Long 			 "REQ_STATE", state, NULL, 80);
725439dfb0cSStefan Farfeleder }
72687e255acSMarius Strobl #endif
7279b631363SMatt Jacob 
728444dd2b6SMatt Jacob #define	LAST_SGE	(		\
729444dd2b6SMatt Jacob 	MPI_SGE_FLAGS_END_OF_LIST |	\
730444dd2b6SMatt Jacob 	MPI_SGE_FLAGS_END_OF_BUFFER|	\
731444dd2b6SMatt Jacob 	MPI_SGE_FLAGS_LAST_ELEMENT)
732444dd2b6SMatt Jacob void
mpt_dump_sgl(SGE_IO_UNION * su,int offset)733444dd2b6SMatt Jacob mpt_dump_sgl(SGE_IO_UNION *su, int offset)
7349b631363SMatt Jacob {
7359b631363SMatt Jacob 	SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su;
736444dd2b6SMatt Jacob 	const char allfox[4] = { 0xff, 0xff, 0xff, 0xff };
737444dd2b6SMatt Jacob 	void *nxtaddr = se;
738444dd2b6SMatt Jacob 	void *lim;
739444dd2b6SMatt Jacob 	int flags;
7409b631363SMatt Jacob 
741444dd2b6SMatt Jacob 	/*
742444dd2b6SMatt Jacob 	 * Can't be any bigger than this.
743444dd2b6SMatt Jacob 	 */
744444dd2b6SMatt Jacob 	lim = &((char *)se)[MPT_REQUEST_AREA - offset];
745444dd2b6SMatt Jacob 
7469b631363SMatt Jacob 	do {
7479b631363SMatt Jacob 		int iprt;
7489b631363SMatt Jacob 
7499b631363SMatt Jacob 		printf("\t");
750444dd2b6SMatt Jacob 		if (memcmp(se, allfox, 4) == 0) {
751444dd2b6SMatt Jacob 			uint32_t *nxt = (uint32_t *)se;
752444dd2b6SMatt Jacob 			printf("PAD  %p\n", se);
753444dd2b6SMatt Jacob 			nxtaddr = nxt + 1;
754444dd2b6SMatt Jacob 			se = nxtaddr;
755444dd2b6SMatt Jacob 			flags = 0;
756444dd2b6SMatt Jacob 			continue;
757444dd2b6SMatt Jacob 		}
758444dd2b6SMatt Jacob 		nxtaddr = se + 1;
7599b631363SMatt Jacob 		flags = MPI_SGE_GET_FLAGS(se->FlagsLength);
7609b631363SMatt Jacob 		switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) {
7619b631363SMatt Jacob 		case MPI_SGE_FLAGS_SIMPLE_ELEMENT:
762444dd2b6SMatt Jacob 			if (flags & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
763444dd2b6SMatt Jacob 				SGE_SIMPLE64 *se64 = (SGE_SIMPLE64 *)se;
7646a9fa015SMatt Jacob 				printf("SE64 %p: Addr=0x%08x%08x FlagsLength"
7656a9fa015SMatt Jacob 				    "=0x%0x\n", se64, se64->Address.High,
766444dd2b6SMatt Jacob 				    se64->Address.Low, se64->FlagsLength);
767444dd2b6SMatt Jacob 				nxtaddr = se64 + 1;
768444dd2b6SMatt Jacob 			} else {
7696a9fa015SMatt Jacob 				printf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x"
770444dd2b6SMatt Jacob 	                            "\n", se, se->Address, se->FlagsLength);
771444dd2b6SMatt Jacob 			}
7729b631363SMatt Jacob 			printf(" ");
7739b631363SMatt Jacob 			break;
7749b631363SMatt Jacob 		case MPI_SGE_FLAGS_CHAIN_ELEMENT:
775444dd2b6SMatt Jacob 			if (flags & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
776444dd2b6SMatt Jacob 				SGE_CHAIN64 *ce64 = (SGE_CHAIN64 *) se;
7776a9fa015SMatt Jacob 				printf("CE64 %p: Addr=0x%08x%08x NxtChnO=0x%x "
7786a9fa015SMatt Jacob 				    "Flgs=0x%x Len=0x%0x\n", ce64,
779444dd2b6SMatt Jacob 				    ce64->Address.High, ce64->Address.Low,
780444dd2b6SMatt Jacob 				    ce64->NextChainOffset,
781444dd2b6SMatt Jacob 				    ce64->Flags, ce64->Length);
782444dd2b6SMatt Jacob 				nxtaddr = ce64 + 1;
783444dd2b6SMatt Jacob 			} else {
7849b631363SMatt Jacob 				SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se;
7856a9fa015SMatt Jacob 				printf("CE32 %p: Addr=0x%0x NxtChnO=0x%x "
7866a9fa015SMatt Jacob 				    " Flgs=0x%x Len=0x%0x\n", ce, ce->Address,
787444dd2b6SMatt Jacob 				    ce->NextChainOffset, ce->Flags, ce->Length);
788444dd2b6SMatt Jacob 			}
7899b631363SMatt Jacob 			flags = 0;
7909b631363SMatt Jacob 			break;
7919b631363SMatt Jacob 		case MPI_SGE_FLAGS_TRANSACTION_ELEMENT:
7929b631363SMatt Jacob 			printf("TE32 @ %p\n", se);
7939b631363SMatt Jacob 			flags = 0;
7949b631363SMatt Jacob 			break;
7959b631363SMatt Jacob 		}
7969b631363SMatt Jacob 		iprt = 0;
7979b631363SMatt Jacob #define MPT_PRINT_FLAG(x)						\
7989b631363SMatt Jacob 		if (flags & MPI_SGE_FLAGS_ ## x ) { 			\
7999b631363SMatt Jacob 			if (iprt == 0) {				\
8009b631363SMatt Jacob 				printf("\t");				\
8019b631363SMatt Jacob 			}						\
8029b631363SMatt Jacob 			printf(" ");					\
8039b631363SMatt Jacob 			printf( #x );					\
8049b631363SMatt Jacob 			iprt++;						\
8059b631363SMatt Jacob 		}
8069b631363SMatt Jacob 		MPT_PRINT_FLAG(LOCAL_ADDRESS);
8079b631363SMatt Jacob 		MPT_PRINT_FLAG(HOST_TO_IOC);
8089b631363SMatt Jacob 		MPT_PRINT_FLAG(64_BIT_ADDRESSING);
8099b631363SMatt Jacob 		MPT_PRINT_FLAG(LAST_ELEMENT);
8109b631363SMatt Jacob 		MPT_PRINT_FLAG(END_OF_BUFFER);
8119b631363SMatt Jacob 		MPT_PRINT_FLAG(END_OF_LIST);
8129b631363SMatt Jacob #undef MPT_PRINT_FLAG
8139b631363SMatt Jacob 		if (iprt)
8149b631363SMatt Jacob 			printf("\n");
815444dd2b6SMatt Jacob 		se = nxtaddr;
816444dd2b6SMatt Jacob 		if ((flags & LAST_SGE) == LAST_SGE) {
817444dd2b6SMatt Jacob 			break;
818444dd2b6SMatt Jacob 		}
819444dd2b6SMatt Jacob 	} while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && nxtaddr < lim);
8209b631363SMatt Jacob }
821301472c2SMatt Jacob 
822a3116b5aSMatt Jacob void
mpt_dump_data(struct mpt_softc * mpt,const char * msg,void * addr,int len)823b4c618c0SMatt Jacob mpt_dump_data(struct mpt_softc *mpt, const char *msg, void *addr, int len)
824b4c618c0SMatt Jacob {
825b4c618c0SMatt Jacob 	int offset;
826b4c618c0SMatt Jacob 	uint8_t *cp = addr;
82787e255acSMarius Strobl 
828b4c618c0SMatt Jacob 	mpt_prt(mpt, "%s:", msg);
829b4c618c0SMatt Jacob 	for (offset = 0; offset < len; offset++) {
830b4c618c0SMatt Jacob 		if ((offset & 0xf) == 0) {
831b4c618c0SMatt Jacob 			mpt_prtc(mpt, "\n");
832b4c618c0SMatt Jacob 		}
833b4c618c0SMatt Jacob 		mpt_prtc(mpt, " %02x", cp[offset]);
834b4c618c0SMatt Jacob 	}
835b4c618c0SMatt Jacob 	mpt_prtc(mpt, "\n");
836b4c618c0SMatt Jacob }
837b4c618c0SMatt Jacob 
838b4c618c0SMatt Jacob void
mpt_dump_request(struct mpt_softc * mpt,request_t * req)839a3116b5aSMatt Jacob mpt_dump_request(struct mpt_softc *mpt, request_t *req)
840a3116b5aSMatt Jacob {
841a3116b5aSMatt Jacob         uint32_t *pReq = req->req_vbuf;
8420e0521a1SMatt Jacob 	int o;
84387e255acSMarius Strobl 
844a3116b5aSMatt Jacob 	mpt_prt(mpt, "Send Request %d (%jx):",
845a3116b5aSMatt Jacob 	    req->index, (uintmax_t) req->req_pbuf);
8460e0521a1SMatt Jacob 	for (o = 0; o < mpt->ioc_facts.RequestFrameSize; o++) {
8470e0521a1SMatt Jacob 		if ((o & 0x7) == 0) {
848a3116b5aSMatt Jacob 			mpt_prtc(mpt, "\n");
849a3116b5aSMatt Jacob 			mpt_prt(mpt, " ");
850a3116b5aSMatt Jacob 		}
8510e0521a1SMatt Jacob 		mpt_prtc(mpt, " %08x", pReq[o]);
852a3116b5aSMatt Jacob 	}
853a3116b5aSMatt Jacob 	mpt_prtc(mpt, "\n");
854a3116b5aSMatt Jacob }
855a3116b5aSMatt Jacob 
856301472c2SMatt Jacob void
mpt_prt(struct mpt_softc * mpt,const char * fmt,...)857b0a2fdeeSScott Long mpt_prt(struct mpt_softc *mpt, const char *fmt, ...)
858301472c2SMatt Jacob {
859301472c2SMatt Jacob 	va_list ap;
860b0a2fdeeSScott Long 
861301472c2SMatt Jacob 	printf("%s: ", device_get_nameunit(mpt->dev));
862301472c2SMatt Jacob 	va_start(ap, fmt);
863301472c2SMatt Jacob 	vprintf(fmt, ap);
864301472c2SMatt Jacob 	va_end(ap);
865b0a2fdeeSScott Long }
866b0a2fdeeSScott Long 
867b0a2fdeeSScott Long void
mpt_prtc(struct mpt_softc * mpt,const char * fmt,...)868b0a2fdeeSScott Long mpt_prtc(struct mpt_softc *mpt, const char *fmt, ...)
869b0a2fdeeSScott Long {
870b0a2fdeeSScott Long 	va_list ap;
871b0a2fdeeSScott Long 
872b0a2fdeeSScott Long 	va_start(ap, fmt);
873b0a2fdeeSScott Long 	vprintf(fmt, ap);
874b0a2fdeeSScott Long 	va_end(ap);
875301472c2SMatt Jacob }
876