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