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