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