Home | History | Annotate | Line # | Download | only in ic
      1  1.13    andvar /*	$NetBSD: mpt_debug.c,v 1.13 2024/02/09 22:08:34 andvar 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.13    andvar __KERNEL_RCSID(0, "$NetBSD: mpt_debug.c,v 1.13 2024/02/09 22:08:34 andvar 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.3  christos 	const 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.8   mbalmer { MPI_IOCSTATUS_TARGET_FC_RX_ID_INVALID,  "FC: Receive ID Invalid" },
     85   1.8   mbalmer { MPI_IOCSTATUS_TARGET_FC_DID_INVALID,    "FC: Receive 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.8   mbalmer { MPI_IOCSTATUS_LAN_RECEIVE_ERROR,        "LAN: Receive Error" },
     92   1.8   mbalmer { MPI_IOCSTATUS_LAN_RECEIVE_ABORTED,      "LAN: Receive 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.8   mbalmer { MPI_FUNCTION_LAN_RECEIVE,                  "LAN Receive" },
    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.11     palle { MPI_EVENT_INTEGRATED_RAID,            "Integrated RAID" },
    135  1.11     palle { MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE,  "SCSI Device Status Change" },
    136  1.11     palle { MPI_EVENT_ON_BUS_TIMER_EXPIRED,       "On Bus Timer Expired" },
    137  1.11     palle { MPI_EVENT_QUEUE_FULL,                 "Queue Full" },
    138  1.11     palle { MPI_EVENT_SAS_DEVICE_STATUS_CHANGE,   "SAS Device Status Change" },
    139  1.11     palle { MPI_EVENT_SAS_SES,                    "SAS Ses" },
    140  1.11     palle { MPI_EVENT_PERSISTENT_TABLE_FULL,      "Persistent Table Full" },
    141  1.11     palle { MPI_EVENT_SAS_PHY_LINK_STATUS,        "SAS Phy Link Status" },
    142  1.11     palle { MPI_EVENT_SAS_DISCOVERY_ERROR,        "SAS Discovery Error" },
    143  1.11     palle { MPI_EVENT_IR_RESYNC_UPDATE,           "IR Resync Update" },
    144  1.11     palle { MPI_EVENT_IR2,                        "IR2", },
    145  1.11     palle { MPI_EVENT_SAS_DISCOVERY,              "Sas Discovery" },
    146   1.1   thorpej { -1, 0},
    147   1.1   thorpej };
    148   1.1   thorpej 
    149   1.1   thorpej static const struct Error_Map IOC_SCSIState[] = {
    150   1.1   thorpej { MPI_SCSI_STATE_AUTOSENSE_VALID,	"AutoSense_Valid" },
    151   1.1   thorpej { MPI_SCSI_STATE_AUTOSENSE_FAILED,	"AutoSense_Failed" },
    152   1.1   thorpej { MPI_SCSI_STATE_NO_SCSI_STATUS,	"No_SCSI_Status" },
    153   1.1   thorpej { MPI_SCSI_STATE_TERMINATED,	   	"State_Terminated" },
    154  1.13    andvar { MPI_SCSI_STATE_RESPONSE_INFO_VALID,	"Response_Info_Valid" },
    155   1.1   thorpej { MPI_SCSI_STATE_QUEUE_TAG_REJECTED,	"Queue Tag Rejected" },
    156   1.1   thorpej { -1, 0},
    157   1.1   thorpej };
    158   1.1   thorpej 
    159   1.1   thorpej static const struct Error_Map IOC_SCSIStatus[] = {
    160   1.1   thorpej { SCSI_OK,				"OK" },
    161   1.1   thorpej { SCSI_CHECK,			"Check Condition" },
    162   1.1   thorpej #if 0
    163   1.1   thorpej { SCSI_STATUS_COND_MET,			"Check Condition Met" },
    164   1.1   thorpej #endif
    165   1.1   thorpej { SCSI_BUSY,				"Busy" },
    166  1.12    andvar { SCSI_INTERM,				"Intermediate Condition" },
    167   1.1   thorpej #if 0
    168  1.12    andvar { SCSI_STATUS_INTERMED_COND_MET,	"Intermediate Condition Met" },
    169   1.1   thorpej #endif
    170   1.1   thorpej { SCSI_RESV_CONFLICT,			"Reservation Conflict" },
    171   1.1   thorpej #if 0
    172   1.1   thorpej { SCSI_STATUS_CMD_TERMINATED,		"Command Terminated" },
    173   1.1   thorpej #endif
    174   1.1   thorpej { SCSI_QUEUE_FULL,			"Queue Full" },
    175   1.1   thorpej { -1, 0},
    176   1.1   thorpej };
    177   1.1   thorpej 
    178   1.1   thorpej static const struct Error_Map IOC_Diag[] = {
    179   1.1   thorpej { MPT_DIAG_ENABLED,	"DWE" },
    180   1.1   thorpej { MPT_DIAG_FLASHBAD,	"FLASH_Bad" },
    181   1.1   thorpej { MPT_DIAG_TTLI,	"TTLI" },
    182   1.1   thorpej { MPT_DIAG_RESET_IOC,	"Reset" },
    183   1.1   thorpej { MPT_DIAG_ARM_DISABLE,	"DisARM" },
    184   1.1   thorpej { MPT_DIAG_DME,		"DME" },
    185   1.1   thorpej { -1, 0 },
    186   1.1   thorpej };
    187   1.1   thorpej 
    188   1.1   thorpej 
    189   1.1   thorpej static void mpt_dump_sgl(SGE_IO_UNION *sgl);
    190   1.1   thorpej 
    191   1.3  christos static const char *
    192   1.1   thorpej mpt_ioc_status(int code)
    193   1.1   thorpej {
    194   1.1   thorpej 	const struct Error_Map *status = IOC_Status;
    195   1.3  christos 	static char tbuf[64];
    196   1.1   thorpej 	while (status->Error_Code >= 0) {
    197   1.1   thorpej 		if (status->Error_Code == (code & MPI_IOCSTATUS_MASK))
    198   1.1   thorpej 			return status->Error_String;
    199   1.1   thorpej 		status++;
    200   1.1   thorpej 	}
    201   1.3  christos 	snprintf(tbuf, sizeof tbuf, "Unknown (0x%08x)", code);
    202   1.3  christos 	return tbuf;
    203   1.1   thorpej }
    204   1.1   thorpej 
    205   1.1   thorpej char *
    206   1.1   thorpej mpt_ioc_diag(u_int32_t code)
    207   1.1   thorpej {
    208   1.1   thorpej 	const struct Error_Map *status = IOC_Diag;
    209   1.3  christos 	static char tbuf[128];
    210   1.9  christos 	size_t len;
    211   1.9  christos 	len = snprintf(tbuf, sizeof(tbuf), "(0x%08x)", code);
    212   1.9  christos 	if (len > sizeof(tbuf))
    213   1.9  christos 		return tbuf;
    214   1.1   thorpej 	while (status->Error_Code >= 0) {
    215   1.9  christos 		if ((status->Error_Code & code) != 0) {
    216  1.10  christos 			if (len >= sizeof(tbuf))
    217  1.10  christos 				return tbuf;
    218   1.9  christos 			len += snprintf(tbuf + len, sizeof(tbuf) - len, "%s ",
    219   1.9  christos 			    status->Error_String);
    220   1.9  christos 		}
    221   1.1   thorpej 		status++;
    222   1.1   thorpej 	}
    223   1.3  christos 	return tbuf;
    224   1.1   thorpej }
    225   1.1   thorpej 
    226   1.3  christos static const char *
    227   1.1   thorpej mpt_ioc_function(int code)
    228   1.1   thorpej {
    229   1.1   thorpej 	const struct Error_Map *status = IOC_Func;
    230   1.3  christos 	static char tbuf[64];
    231   1.1   thorpej 	while (status->Error_Code >= 0) {
    232   1.1   thorpej 		if (status->Error_Code == code)
    233   1.1   thorpej 			return status->Error_String;
    234   1.1   thorpej 		status++;
    235   1.1   thorpej 	}
    236   1.3  christos 	snprintf(tbuf, sizeof tbuf, "Unknown (0x%08x)", code);
    237   1.3  christos 	return tbuf;
    238   1.1   thorpej }
    239   1.3  christos static const char *
    240   1.1   thorpej mpt_ioc_event(int code)
    241   1.1   thorpej {
    242   1.1   thorpej 	const struct Error_Map *status = IOC_Event;
    243   1.3  christos 	static char tbuf[64];
    244   1.1   thorpej 	while (status->Error_Code >= 0) {
    245   1.1   thorpej 		if (status->Error_Code == code)
    246   1.1   thorpej 			return status->Error_String;
    247   1.1   thorpej 		status++;
    248   1.1   thorpej 	}
    249   1.3  christos 	snprintf(tbuf, sizeof tbuf, "Unknown (0x%08x)", code);
    250   1.3  christos 	return tbuf;
    251   1.1   thorpej }
    252   1.1   thorpej static char *
    253   1.1   thorpej mpt_scsi_state(int code)
    254   1.1   thorpej {
    255   1.1   thorpej 	const struct Error_Map *status = IOC_SCSIState;
    256   1.3  christos 	static char tbuf[128];
    257   1.9  christos 	size_t len;
    258   1.9  christos 	len = snprintf(tbuf, sizeof(tbuf), "(0x%08x)", code);
    259   1.9  christos 	if (len > sizeof(tbuf))
    260   1.9  christos 		return tbuf;
    261   1.1   thorpej 	while (status->Error_Code >= 0) {
    262   1.9  christos 		if ((status->Error_Code & code) != 0) {
    263  1.10  christos 			if (len >= sizeof(tbuf))
    264  1.10  christos 				return tbuf;
    265   1.9  christos 			len += snprintf(tbuf + len, sizeof(tbuf) - len, "%s ",
    266   1.1   thorpej 				status->Error_String);
    267   1.9  christos 		}
    268   1.1   thorpej 		status++;
    269   1.1   thorpej 	}
    270   1.3  christos 	return tbuf;
    271   1.1   thorpej }
    272   1.3  christos static const char *
    273   1.1   thorpej mpt_scsi_status(int code)
    274   1.1   thorpej {
    275   1.1   thorpej 	const struct Error_Map *status = IOC_SCSIStatus;
    276   1.3  christos 	static char tbuf[64];
    277   1.1   thorpej 	while (status->Error_Code >= 0) {
    278   1.1   thorpej 		if (status->Error_Code == code)
    279   1.1   thorpej 			return status->Error_String;
    280   1.1   thorpej 		status++;
    281   1.1   thorpej 	}
    282   1.3  christos 	snprintf(tbuf, sizeof tbuf, "Unknown (0x%08x)", code);
    283   1.3  christos 	return tbuf;
    284   1.1   thorpej }
    285   1.3  christos static const char *
    286   1.1   thorpej mpt_who(int who_init)
    287   1.1   thorpej {
    288   1.3  christos 	const char *who;
    289   1.1   thorpej 
    290   1.1   thorpej 	switch (who_init) {
    291   1.1   thorpej 	case MPT_DB_INIT_NOONE:       who = "No One";        break;
    292   1.1   thorpej 	case MPT_DB_INIT_BIOS:        who = "BIOS";          break;
    293   1.1   thorpej 	case MPT_DB_INIT_ROMBIOS:     who = "ROM BIOS";      break;
    294   1.1   thorpej 	case MPT_DB_INIT_PCIPEER:     who = "PCI Peer";      break;
    295   1.1   thorpej 	case MPT_DB_INIT_HOST:        who = "Host Driver";   break;
    296   1.1   thorpej 	case MPT_DB_INIT_MANUFACTURE: who = "Manufacturing"; break;
    297   1.1   thorpej 	default:                      who = "Unknown";       break;
    298   1.1   thorpej 	}
    299   1.1   thorpej 	return who;
    300   1.1   thorpej }
    301   1.1   thorpej 
    302   1.3  christos static const char *
    303   1.1   thorpej mpt_state(u_int32_t mb)
    304   1.1   thorpej {
    305   1.3  christos 	const char *text;
    306   1.1   thorpej 
    307   1.1   thorpej 	switch (MPT_STATE(mb)) {
    308   1.1   thorpej 		case MPT_DB_STATE_RESET:  text = "Reset";   break;
    309   1.1   thorpej 		case MPT_DB_STATE_READY:  text = "Ready";   break;
    310   1.1   thorpej 		case MPT_DB_STATE_RUNNING:text = "Running"; break;
    311   1.1   thorpej 		case MPT_DB_STATE_FAULT:  text = "Fault";   break;
    312   1.1   thorpej 		default: 		  text = "Unknown"; break;
    313   1.1   thorpej 	}
    314   1.1   thorpej 	return text;
    315   1.1   thorpej };
    316   1.1   thorpej 
    317   1.1   thorpej void
    318   1.1   thorpej mpt_print_db(u_int32_t mb)
    319   1.1   thorpej {
    320   1.1   thorpej 	printf("mpt mailbox: (0x%x) State %s  WhoInit %s\n",
    321   1.1   thorpej 	    mb, mpt_state(mb), mpt_who(MPT_WHO(mb)));
    322   1.1   thorpej }
    323   1.1   thorpej 
    324   1.1   thorpej /*****************************************************************************/
    325   1.1   thorpej /*  Reply functions                                                          */
    326   1.1   thorpej /*****************************************************************************/
    327   1.1   thorpej static void
    328   1.1   thorpej mpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg)
    329   1.1   thorpej {
    330   1.1   thorpej 	printf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg);
    331   1.7       chs 	printf("\tIOC Status    %s\n", mpt_ioc_status(le16toh(msg->IOCStatus)));
    332   1.1   thorpej 	printf("\tIOCLogInfo    0x%08x\n", msg->IOCLogInfo);
    333   1.1   thorpej 	printf("\tMsgLength     0x%02x\n", msg->MsgLength);
    334   1.1   thorpej 	printf("\tMsgFlags      0x%02x\n", msg->MsgFlags);
    335   1.7       chs 	printf("\tMsgContext    0x%08x\n", le32toh(msg->MsgContext));
    336   1.1   thorpej }
    337   1.1   thorpej 
    338   1.1   thorpej static void
    339   1.1   thorpej mpt_print_init_reply(MSG_IOC_INIT_REPLY *msg)
    340   1.1   thorpej {
    341   1.1   thorpej 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
    342   1.1   thorpej 	printf("\tWhoInit       %s\n", mpt_who(msg->WhoInit));
    343   1.1   thorpej 	printf("\tMaxDevices    0x%02x\n", msg->MaxDevices);
    344   1.1   thorpej 	printf("\tMaxBuses     0x%02x\n", msg->MaxBuses);
    345   1.1   thorpej }
    346   1.1   thorpej 
    347   1.1   thorpej static void
    348   1.1   thorpej mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg)
    349   1.1   thorpej {
    350   1.1   thorpej 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
    351   1.1   thorpej 	printf("\tIOCNumber     %d\n",		msg->IOCNumber);
    352   1.1   thorpej 	printf("\tMaxChainDepth %d\n",		msg->MaxChainDepth);
    353   1.1   thorpej 	printf("\tWhoInit       %s\n",		mpt_who(msg->WhoInit));
    354   1.1   thorpej 	printf("\tBlockSize     %d\n",		msg->BlockSize);
    355   1.1   thorpej 	printf("\tFlags         %d\n",		msg->Flags);
    356   1.7       chs 	printf("\tReplyQueueDepth %d\n",	le16toh(msg->ReplyQueueDepth));
    357   1.7       chs 	printf("\tReqFrameSize  0x%04x\n",	le16toh(msg->RequestFrameSize));
    358   1.1   thorpej 	printf("\tFW Version    0x%08x\n",	msg->FWVersion.Word);
    359   1.7       chs 	printf("\tProduct ID    0x%04x\n",	le16toh(msg->ProductID));
    360   1.7       chs 	printf("\tCredits       0x%04x\n",	le16toh(msg->GlobalCredits));
    361   1.1   thorpej 	printf("\tPorts         %d\n",		msg->NumberOfPorts);
    362   1.1   thorpej 	printf("\tEventState    0x%02x\n",	msg->EventState);
    363   1.7       chs 	printf("\tHostMFA_HA    0x%08x\n",
    364   1.7       chs 	    le32toh(msg->CurrentHostMfaHighAddr));
    365   1.1   thorpej 	printf("\tSenseBuf_HA   0x%08x\n",
    366   1.7       chs 	    le32toh(msg->CurrentSenseBufferHighAddr));
    367   1.7       chs 	printf("\tRepFrameSize  0x%04x\n",
    368   1.7       chs 	    le16toh(msg->CurReplyFrameSize));
    369   1.1   thorpej 	printf("\tMaxDevices    0x%02x\n",	msg->MaxDevices);
    370   1.1   thorpej 	printf("\tMaxBuses      0x%02x\n",	msg->MaxBuses);
    371   1.7       chs 	printf("\tFWImageSize   0x%04x\n",	le32toh(msg->FWImageSize));
    372   1.1   thorpej }
    373   1.1   thorpej 
    374   1.1   thorpej static void
    375   1.1   thorpej mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg)
    376   1.1   thorpej {
    377   1.1   thorpej 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
    378   1.1   thorpej 	printf("\tPort:         %d\n", msg->PortNumber);
    379   1.1   thorpej }
    380   1.1   thorpej 
    381   1.1   thorpej static void
    382   1.1   thorpej mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg)
    383   1.1   thorpej {
    384   1.1   thorpej 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
    385   1.1   thorpej 	printf("\tBus:          %d\n", msg->Bus);
    386   1.1   thorpej 	printf("\tTargetID      %d\n", msg->TargetID);
    387   1.1   thorpej 	printf("\tCDBLength     %d\n", msg->CDBLength);
    388   1.1   thorpej 	printf("\tSCSI Status:  %s\n", mpt_scsi_status(msg->SCSIStatus));
    389   1.1   thorpej 	printf("\tSCSI State:   %s\n", mpt_scsi_state(msg->SCSIState));
    390   1.7       chs 	printf("\tTransferCnt   0x%04x\n", le32toh(msg->TransferCount));
    391   1.7       chs 	printf("\tSenseCnt      0x%04x\n", le32toh(msg->SenseCount));
    392   1.7       chs 	printf("\tResponseInfo  0x%08x\n", le32toh(msg->ResponseInfo));
    393   1.1   thorpej }
    394   1.1   thorpej 
    395   1.1   thorpej 
    396   1.1   thorpej 
    397   1.1   thorpej static void
    398   1.1   thorpej mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg)
    399   1.1   thorpej {
    400   1.1   thorpej 	mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
    401   1.7       chs 	printf("\tEvent:        %s\n", mpt_ioc_event(le32toh(msg->Event)));
    402   1.7       chs 	printf("\tEventContext  0x%04x\n", le32toh(msg->EventContext));
    403   1.1   thorpej 	printf("\tAckRequired     %d\n", msg->AckRequired);
    404   1.7       chs 	printf("\tEventDataLength %d\n", le16toh(msg->EventDataLength));
    405   1.1   thorpej 	printf("\tContinuation    %d\n", msg->MsgFlags & 0x80);
    406   1.1   thorpej 	switch(msg->Event) {
    407   1.1   thorpej 	case MPI_EVENT_LOG_DATA:
    408   1.7       chs 		printf("\tEvtLogData:   0x%04x\n", le32toh(msg->Data[0]));
    409   1.1   thorpej 		break;
    410   1.1   thorpej 
    411   1.1   thorpej 	case MPI_EVENT_UNIT_ATTENTION:
    412   1.1   thorpej 		printf("\tTargetID:     0x%04x\n",
    413   1.1   thorpej 			msg->Data[0] & 0xff);
    414   1.1   thorpej 		printf("\tBus:          0x%04x\n",
    415   1.1   thorpej 			(msg->Data[0] >> 8) & 0xff);
    416   1.1   thorpej 		break;
    417   1.1   thorpej 
    418   1.1   thorpej 	case MPI_EVENT_IOC_BUS_RESET:
    419   1.1   thorpej 	case MPI_EVENT_EXT_BUS_RESET:
    420   1.1   thorpej 	case MPI_EVENT_RESCAN:
    421   1.1   thorpej 		printf("\tPort:           %d\n",
    422   1.1   thorpej 			(msg->Data[0] >> 8) & 0xff);
    423   1.1   thorpej 		break;
    424   1.1   thorpej 
    425   1.1   thorpej 	case MPI_EVENT_LINK_STATUS_CHANGE:
    426   1.1   thorpej 		printf("\tLinkState:    %d\n",
    427   1.1   thorpej 			msg->Data[0] & 0xff);
    428   1.1   thorpej 		printf("\tPort:         %d\n",
    429   1.1   thorpej 			(msg->Data[1] >> 8) & 0xff);
    430   1.1   thorpej 		break;
    431   1.1   thorpej 
    432   1.1   thorpej 	case MPI_EVENT_LOOP_STATE_CHANGE:
    433   1.1   thorpej 		printf("\tType:         %d\n",
    434   1.1   thorpej 			(msg->Data[0] >> 16) & 0xff);
    435   1.1   thorpej 		printf("\tChar3:      0x%02x\n",
    436   1.1   thorpej 			(msg->Data[0] >> 8) & 0xff);
    437   1.1   thorpej 		printf("\tChar4:      0x%02x\n",
    438   1.1   thorpej 			(msg->Data[0]     ) & 0xff);
    439   1.1   thorpej 		printf("\tPort:         %d\n",
    440   1.1   thorpej 			(msg->Data[1] >> 8) & 0xff);
    441   1.1   thorpej 		break;
    442   1.1   thorpej 
    443   1.1   thorpej 	case MPI_EVENT_LOGOUT:
    444   1.1   thorpej 		printf("\tN_PortId:   0x%04x\n", msg->Data[0]);
    445   1.1   thorpej 		printf("\tPort:         %d\n",
    446   1.1   thorpej 			(msg->Data[1] >> 8) & 0xff);
    447   1.1   thorpej 		break;
    448   1.1   thorpej 	}
    449   1.1   thorpej 
    450   1.1   thorpej }
    451   1.1   thorpej 
    452   1.1   thorpej void
    453   1.1   thorpej mpt_print_reply(void *vmsg)
    454   1.1   thorpej {
    455   1.1   thorpej 	MSG_DEFAULT_REPLY *msg = vmsg;
    456   1.1   thorpej 
    457   1.1   thorpej 	switch (msg->Function) {
    458   1.1   thorpej 	case MPI_FUNCTION_EVENT_NOTIFICATION:
    459   1.1   thorpej 		mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg);
    460   1.1   thorpej 		break;
    461   1.1   thorpej 	case MPI_FUNCTION_PORT_ENABLE:
    462   1.1   thorpej 		mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg);
    463   1.1   thorpej 		break;
    464   1.1   thorpej 	case MPI_FUNCTION_IOC_FACTS:
    465   1.1   thorpej 		mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg);
    466   1.1   thorpej 		break;
    467   1.1   thorpej 	case MPI_FUNCTION_IOC_INIT:
    468   1.1   thorpej 		mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg);
    469   1.1   thorpej 		break;
    470   1.1   thorpej 	case MPI_FUNCTION_SCSI_IO_REQUEST:
    471   1.1   thorpej 		mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg);
    472   1.1   thorpej 		break;
    473   1.1   thorpej 	default:
    474   1.1   thorpej 		mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
    475   1.1   thorpej 		break;
    476   1.1   thorpej 	}
    477   1.1   thorpej }
    478   1.1   thorpej 
    479   1.1   thorpej /*****************************************************************************/
    480   1.1   thorpej /*  Request functions                                                        */
    481   1.1   thorpej /*****************************************************************************/
    482   1.1   thorpej static void
    483   1.1   thorpej mpt_print_request_hdr(MSG_REQUEST_HEADER *req)
    484   1.1   thorpej {
    485   1.1   thorpej 	printf("%s @ %p\n", mpt_ioc_function(req->Function), req);
    486   1.1   thorpej 	printf("\tChain Offset  0x%02x\n", req->ChainOffset);
    487   1.1   thorpej 	printf("\tMsgFlags      0x%02x\n", req->MsgFlags);
    488   1.7       chs 	printf("\tMsgContext    0x%08x\n", le32toh(req->MsgContext));
    489   1.1   thorpej }
    490   1.1   thorpej 
    491   1.1   thorpej void
    492   1.1   thorpej mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg)
    493   1.1   thorpej {
    494   1.1   thorpej 	MSG_SCSI_IO_REQUEST local, *msg = &local;
    495   1.1   thorpej 	int i;
    496   1.1   thorpej 
    497   1.6   tsutsui 	memcpy(msg, orig_msg, sizeof (MSG_SCSI_IO_REQUEST));
    498   1.1   thorpej 	mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
    499   1.1   thorpej 	printf("\tBus:                %d\n", msg->Bus);
    500   1.1   thorpej 	printf("\tTargetID            %d\n", msg->TargetID);
    501   1.1   thorpej 	printf("\tSenseBufferLength   %d\n", msg->SenseBufferLength);
    502   1.1   thorpej 	printf("\tLUN:              0x%0x\n", msg->LUN[1]);
    503   1.7       chs 	printf("\tControl           0x%08x ", le32toh(msg->Control));
    504   1.1   thorpej #define MPI_PRINT_FIELD(x)						\
    505   1.1   thorpej 	case MPI_SCSIIO_CONTROL_ ## x :					\
    506   1.1   thorpej 		printf(" " #x " ");					\
    507   1.1   thorpej 		break
    508   1.1   thorpej 
    509   1.7       chs 	switch (le32toh(msg->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) {
    510   1.1   thorpej 	MPI_PRINT_FIELD(NODATATRANSFER);
    511   1.1   thorpej 	MPI_PRINT_FIELD(WRITE);
    512   1.1   thorpej 	MPI_PRINT_FIELD(READ);
    513   1.1   thorpej 	default:
    514   1.1   thorpej 		printf(" Invalid DIR! ");
    515   1.1   thorpej 		break;
    516   1.1   thorpej 	}
    517   1.7       chs 	switch (le32toh(msg->Control) & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) {
    518   1.1   thorpej 	MPI_PRINT_FIELD(SIMPLEQ);
    519   1.1   thorpej 	MPI_PRINT_FIELD(HEADOFQ);
    520   1.1   thorpej 	MPI_PRINT_FIELD(ORDEREDQ);
    521   1.1   thorpej 	MPI_PRINT_FIELD(ACAQ);
    522   1.1   thorpej 	MPI_PRINT_FIELD(UNTAGGED);
    523   1.1   thorpej 	MPI_PRINT_FIELD(NO_DISCONNECT);
    524   1.1   thorpej 	default:
    525   1.1   thorpej 		printf(" Unknown attribute! ");
    526   1.1   thorpej 		break;
    527   1.1   thorpej 	}
    528   1.1   thorpej 
    529   1.1   thorpej 	printf("\n");
    530   1.1   thorpej #undef MPI_PRINT_FIELD
    531   1.1   thorpej 
    532   1.7       chs 	printf("\tDataLength\t0x%08x\n", le32toh(msg->DataLength));
    533   1.7       chs 	printf("\tSenseBufAddr\t0x%08x\n", le32toh(msg->SenseBufferLowAddr));
    534   1.1   thorpej 	printf("\tCDB[0:%d]\t", msg->CDBLength);
    535   1.1   thorpej 	for (i = 0; i < msg->CDBLength; i++)
    536   1.1   thorpej 		printf("%02x ", msg->CDB[i]);
    537   1.1   thorpej 	printf("\n");
    538   1.1   thorpej 	mpt_dump_sgl(&orig_msg->SGL);
    539   1.1   thorpej }
    540   1.1   thorpej 
    541   1.1   thorpej void
    542   1.1   thorpej mpt_print_request(void *vreq)
    543   1.1   thorpej {
    544   1.1   thorpej 	MSG_REQUEST_HEADER *req = vreq;
    545   1.1   thorpej 
    546   1.1   thorpej 	switch (req->Function) {
    547   1.1   thorpej 	case MPI_FUNCTION_SCSI_IO_REQUEST:
    548   1.1   thorpej 		mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req);
    549   1.1   thorpej 		break;
    550   1.1   thorpej 	default:
    551   1.1   thorpej 		mpt_print_request_hdr(req);
    552   1.1   thorpej 		break;
    553   1.1   thorpej 	}
    554   1.1   thorpej }
    555   1.1   thorpej 
    556   1.3  christos const char *
    557   1.1   thorpej mpt_req_state(enum mpt_req_state state)
    558   1.1   thorpej {
    559   1.3  christos 	const char *text;
    560   1.1   thorpej 
    561   1.1   thorpej 	switch (state) {
    562   1.1   thorpej 	case REQ_FREE:         text = "Free";         break;
    563   1.1   thorpej 	case REQ_IN_PROGRESS:  text = "In Progress";  break;
    564   1.1   thorpej 	case REQ_ON_CHIP:      text = "On Chip";      break;
    565   1.1   thorpej 	case REQ_TIMEOUT:      text = "Timeout";      break;
    566   1.1   thorpej 	default: 	       text = "Unknown";      break;
    567   1.1   thorpej 	}
    568   1.1   thorpej 	return text;
    569   1.1   thorpej };
    570   1.1   thorpej 
    571   1.1   thorpej static void
    572   1.1   thorpej mpt_dump_sgl(SGE_IO_UNION *su)
    573   1.1   thorpej {
    574   1.1   thorpej 	SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su;
    575   1.1   thorpej 	int iCount, flags;
    576   1.1   thorpej 
    577   1.1   thorpej 	iCount = MPT_SGL_MAX;
    578   1.1   thorpej 	do {
    579   1.1   thorpej 		int iprt;
    580   1.1   thorpej 
    581   1.1   thorpej 		printf("\t");
    582   1.7       chs 		flags = MPI_SGE_GET_FLAGS(le32toh(se->FlagsLength));
    583   1.1   thorpej 		switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) {
    584   1.1   thorpej 		case MPI_SGE_FLAGS_SIMPLE_ELEMENT:
    585   1.1   thorpej 		{
    586   1.1   thorpej 			printf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x\n",
    587   1.7       chs 			    se, le32toh(se->Address), le32toh(se->FlagsLength));
    588   1.1   thorpej 			printf(" ");
    589   1.1   thorpej 			break;
    590   1.1   thorpej 		}
    591   1.1   thorpej 		case MPI_SGE_FLAGS_CHAIN_ELEMENT:
    592   1.1   thorpej 		{
    593   1.1   thorpej 			SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se;
    594   1.1   thorpej 			printf("CE32 %p: Addr=0x%0x NxtChnO=0x%x Flgs=0x%x "
    595   1.7       chs 			    "Len=0x%0x\n", ce, le32toh(ce->Address),
    596   1.7       chs 			    ce->NextChainOffset, ce->Flags,
    597   1.7       chs 			    le16toh(ce->Length));
    598   1.1   thorpej 			flags = 0;
    599   1.1   thorpej 			break;
    600   1.1   thorpej 		}
    601   1.1   thorpej 		case MPI_SGE_FLAGS_TRANSACTION_ELEMENT:
    602   1.1   thorpej 			printf("TE32 @ %p\n", se);
    603   1.1   thorpej 			flags = 0;
    604   1.1   thorpej 			break;
    605   1.1   thorpej 		}
    606   1.1   thorpej 		iprt = 0;
    607   1.1   thorpej #define MPT_PRINT_FLAG(x)						\
    608   1.1   thorpej 		if (flags & MPI_SGE_FLAGS_ ## x ) { 			\
    609   1.1   thorpej 			if (iprt == 0) {				\
    610   1.1   thorpej 				printf("\t");				\
    611   1.1   thorpej 			}						\
    612   1.1   thorpej 			printf(" ");					\
    613   1.1   thorpej 			printf( #x );					\
    614   1.1   thorpej 			iprt++;						\
    615   1.1   thorpej 		}
    616   1.1   thorpej 		MPT_PRINT_FLAG(LOCAL_ADDRESS);
    617   1.1   thorpej 		MPT_PRINT_FLAG(HOST_TO_IOC);
    618   1.1   thorpej 		MPT_PRINT_FLAG(64_BIT_ADDRESSING);
    619   1.1   thorpej 		MPT_PRINT_FLAG(LAST_ELEMENT);
    620   1.1   thorpej 		MPT_PRINT_FLAG(END_OF_BUFFER);
    621   1.1   thorpej 		MPT_PRINT_FLAG(END_OF_LIST);
    622   1.1   thorpej #undef MPT_PRINT_FLAG
    623   1.1   thorpej 		if (iprt)
    624   1.1   thorpej 			printf("\n");
    625   1.1   thorpej 		se++;
    626   1.1   thorpej 		iCount -= 1;
    627   1.1   thorpej 	} while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && iCount != 0);
    628   1.1   thorpej }
    629