mpt(4): Sync with FreeBSD.
[dragonfly.git] / sys / dev / disk / mpt / mpt_debug.c
CommitLineData
d751f32e 1/*-
984263bc
MD
2 * Debug routines for LSI '909 FC adapters.
3 * FreeBSD Version.
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.
d751f32e 27 *
984263bc 28 */
d751f32e
MD
29/*-
30 * Copyright (c) 2002, 2006 by Matthew Jacob
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions are
35 * met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
39 * substantially similar to the "NO WARRANTY" disclaimer below
40 * ("Disclaimer") and any redistribution must be conditioned upon including
41 * a substantially similar Disclaimer requirement for further binary
42 * redistribution.
43 * 3. Neither the names of the above listed copyright holders nor the names
44 * of any contributors may be used to endorse or promote products derived
45 * from this software without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
51 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
57 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 *
59 * Support from Chris Ellsworth in order to make SAS adapters work
60 * is gratefully acknowledged.
61 *
62 * Support from LSI-Logic has also gone a great deal toward making this a
63 * workable subsystem and is gratefully acknowledged.
32af04f7 64 *
4c42baf4 65 * $FreeBSD: src/sys/dev/mpt/mpt_debug.c,v 1.20 2011/07/29 18:35:10 marius Exp $
984263bc
MD
66 */
67
2545bca0 68#include <dev/disk/mpt/mpt.h>
d751f32e 69
2545bca0
MD
70#include <dev/disk/mpt/mpilib/mpi_ioc.h>
71#include <dev/disk/mpt/mpilib/mpi_init.h>
72#include <dev/disk/mpt/mpilib/mpi_fc.h>
73#include <dev/disk/mpt/mpilib/mpi_targ.h>
d751f32e 74
2545bca0 75#include <bus/cam/scsi/scsi_all.h>
d751f32e
MD
76
77#include <machine/stdarg.h> /* for use by mpt_prt below */
984263bc
MD
78
79struct Error_Map {
80 int Error_Code;
81 char *Error_String;
82};
83
84static const struct Error_Map IOC_Status[] = {
85{ MPI_IOCSTATUS_SUCCESS, "Success" },
86{ MPI_IOCSTATUS_INVALID_FUNCTION, "IOC: Invalid Function" },
87{ MPI_IOCSTATUS_BUSY, "IOC: Busy" },
88{ MPI_IOCSTATUS_INVALID_SGL, "IOC: Invalid SGL" },
89{ MPI_IOCSTATUS_INTERNAL_ERROR, "IOC: Internal Error" },
90{ MPI_IOCSTATUS_RESERVED, "IOC: Reserved" },
91{ MPI_IOCSTATUS_INSUFFICIENT_RESOURCES, "IOC: Insufficient Resources" },
92{ MPI_IOCSTATUS_INVALID_FIELD, "IOC: Invalid Field" },
93{ MPI_IOCSTATUS_INVALID_STATE, "IOC: Invalid State" },
94{ MPI_IOCSTATUS_CONFIG_INVALID_ACTION, "Invalid Action" },
95{ MPI_IOCSTATUS_CONFIG_INVALID_TYPE, "Invalid Type" },
96{ MPI_IOCSTATUS_CONFIG_INVALID_PAGE, "Invalid Page" },
97{ MPI_IOCSTATUS_CONFIG_INVALID_DATA, "Invalid Data" },
98{ MPI_IOCSTATUS_CONFIG_NO_DEFAULTS, "No Defaults" },
99{ MPI_IOCSTATUS_CONFIG_CANT_COMMIT, "Can't Commit" },
d751f32e 100{ MPI_IOCSTATUS_SCSI_RECOVERED_ERROR, "SCSI: Recoverd Error" },
984263bc
MD
101{ MPI_IOCSTATUS_SCSI_INVALID_BUS, "SCSI: Invalid Bus" },
102{ MPI_IOCSTATUS_SCSI_INVALID_TARGETID, "SCSI: Invalid Target ID" },
103{ MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE, "SCSI: Device Not There" },
104{ MPI_IOCSTATUS_SCSI_DATA_OVERRUN, "SCSI: Data Overrun" },
105{ MPI_IOCSTATUS_SCSI_DATA_UNDERRUN, "SCSI: Data Underrun" },
106{ MPI_IOCSTATUS_SCSI_IO_DATA_ERROR, "SCSI: Data Error" },
107{ MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR, "SCSI: Protocol Error" },
108{ MPI_IOCSTATUS_SCSI_TASK_TERMINATED, "SCSI: Task Terminated" },
109{ MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH, "SCSI: Residual Mismatch" },
110{ MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED, "SCSI: Task Management Failed" },
111{ MPI_IOCSTATUS_SCSI_IOC_TERMINATED, "SCSI: IOC Bus Reset" },
112{ MPI_IOCSTATUS_SCSI_EXT_TERMINATED, "SCSI: External Bus Reset" },
113{ MPI_IOCSTATUS_TARGET_PRIORITY_IO, "SCSI Target: Priority I/O" },
114{ MPI_IOCSTATUS_TARGET_INVALID_PORT, "SCSI Target: Invalid Port" },
115{ MPI_IOCSTATUS_TARGET_INVALID_IOCINDEX, "SCSI Target: Invalid IOC Index" },
116{ MPI_IOCSTATUS_TARGET_ABORTED, "SCSI Target: Aborted" },
117{ MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE, "SCSI Target: No Connection (Retryable)" },
118{ MPI_IOCSTATUS_TARGET_NO_CONNECTION, "SCSI Target: No Connection" },
119{ MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH,"SCSI Target: Transfer Count Mismatch" },
120{ MPI_IOCSTATUS_TARGET_FC_ABORTED, "FC: Aborted" },
1de3c21d
SW
121{ MPI_IOCSTATUS_TARGET_FC_RX_ID_INVALID, "FC: Receive ID Invalid" },
122{ MPI_IOCSTATUS_TARGET_FC_DID_INVALID, "FC: Receive DID Invalid" },
984263bc
MD
123{ MPI_IOCSTATUS_TARGET_FC_NODE_LOGGED_OUT,"FC: Node Logged Out" },
124{ MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND, "LAN: Device Not Found" },
125{ MPI_IOCSTATUS_LAN_DEVICE_FAILURE, "LAN: Device Not Failure" },
126{ MPI_IOCSTATUS_LAN_TRANSMIT_ERROR, "LAN: Transmit Error" },
127{ MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED, "LAN: Transmit Aborted" },
1de3c21d
SW
128{ MPI_IOCSTATUS_LAN_RECEIVE_ERROR, "LAN: Receive Error" },
129{ MPI_IOCSTATUS_LAN_RECEIVE_ABORTED, "LAN: Receive Aborted" },
984263bc
MD
130{ MPI_IOCSTATUS_LAN_PARTIAL_PACKET, "LAN: Partial Packet" },
131{ MPI_IOCSTATUS_LAN_CANCELED, "LAN: Canceled" },
132{ -1, 0},
133};
134
135static const struct Error_Map IOC_Func[] = {
136{ MPI_FUNCTION_SCSI_IO_REQUEST, "SCSI IO Request" },
137{ MPI_FUNCTION_SCSI_TASK_MGMT, "SCSI Task Management" },
138{ MPI_FUNCTION_IOC_INIT, "IOC Init" },
139{ MPI_FUNCTION_IOC_FACTS, "IOC Facts" },
140{ MPI_FUNCTION_CONFIG, "Config" },
141{ MPI_FUNCTION_PORT_FACTS, "Port Facts" },
142{ MPI_FUNCTION_PORT_ENABLE, "Port Enable" },
143{ MPI_FUNCTION_EVENT_NOTIFICATION, "Event Notification" },
d751f32e 144{ MPI_FUNCTION_EVENT_ACK, "Event Ack" },
984263bc
MD
145{ MPI_FUNCTION_FW_DOWNLOAD, "FW Download" },
146{ MPI_FUNCTION_TARGET_CMD_BUFFER_POST, "SCSI Target Command Buffer" },
147{ MPI_FUNCTION_TARGET_ASSIST, "Target Assist" },
148{ MPI_FUNCTION_TARGET_STATUS_SEND, "Target Status Send" },
149{ MPI_FUNCTION_TARGET_MODE_ABORT, "Target Mode Abort" },
984263bc
MD
150{ -1, 0},
151};
152
153static const struct Error_Map IOC_Event[] = {
154{ MPI_EVENT_NONE, "None" },
155{ MPI_EVENT_LOG_DATA, "LogData" },
156{ MPI_EVENT_STATE_CHANGE, "State Change" },
157{ MPI_EVENT_UNIT_ATTENTION, "Unit Attention" },
158{ MPI_EVENT_IOC_BUS_RESET, "IOC Bus Reset" },
159{ MPI_EVENT_EXT_BUS_RESET, "External Bus Reset" },
160{ MPI_EVENT_RESCAN, "Rescan" },
161{ MPI_EVENT_LINK_STATUS_CHANGE, "Link Status Change" },
162{ MPI_EVENT_LOOP_STATE_CHANGE, "Loop State Change" },
163{ MPI_EVENT_LOGOUT, "Logout" },
164{ MPI_EVENT_EVENT_CHANGE, "EventChange" },
165{ -1, 0},
166};
167
168static const struct Error_Map IOC_SCSIState[] = {
169{ MPI_SCSI_STATE_AUTOSENSE_VALID, "AutoSense_Valid" },
170{ MPI_SCSI_STATE_AUTOSENSE_FAILED, "AutoSense_Failed" },
171{ MPI_SCSI_STATE_NO_SCSI_STATUS, "No_SCSI_Status" },
172{ MPI_SCSI_STATE_TERMINATED, "State_Terminated" },
173{ MPI_SCSI_STATE_RESPONSE_INFO_VALID, "Repsonse_Info_Valid" },
174{ MPI_SCSI_STATE_QUEUE_TAG_REJECTED, "Queue Tag Rejected" },
175{ -1, 0},
176};
177
178static const struct Error_Map IOC_SCSIStatus[] = {
179{ SCSI_STATUS_OK, "OK" },
180{ SCSI_STATUS_CHECK_COND, "Check Condition" },
181{ SCSI_STATUS_COND_MET, "Check Condition Met" },
182{ SCSI_STATUS_BUSY, "Busy" },
183{ SCSI_STATUS_INTERMED, "Intermidiate Condition" },
184{ SCSI_STATUS_INTERMED_COND_MET, "Intermidiate Condition Met" },
185{ SCSI_STATUS_RESERV_CONFLICT, "Reservation Conflict" },
186{ SCSI_STATUS_CMD_TERMINATED, "Command Terminated" },
187{ SCSI_STATUS_QUEUE_FULL, "Queue Full" },
188{ -1, 0},
189};
190
191static const struct Error_Map IOC_Diag[] = {
d751f32e
MD
192{ MPI_DIAG_DRWE, "DWE" },
193{ MPI_DIAG_FLASH_BAD_SIG, "FLASH_Bad" },
194{ MPI_DIAGNOSTIC_OFFSET, "Offset" },
195{ MPI_DIAG_RESET_ADAPTER, "Reset" },
196{ MPI_DIAG_DISABLE_ARM, "DisARM" },
197{ MPI_DIAG_MEM_ENABLE, "DME" },
984263bc
MD
198{ -1, 0 },
199};
200
d751f32e
MD
201static const struct Error_Map IOC_SCSITMType[] = {
202{ MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK, "Abort Task" },
203{ MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, "Abort Task Set" },
204{ MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, "Target Reset" },
205{ MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, "Reset Bus" },
206{ MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, "Logical Unit Reset" },
207{ -1, 0 },
208};
984263bc
MD
209
210static char *
211mpt_ioc_status(int code)
212{
213 const struct Error_Map *status = IOC_Status;
214 static char buf[64];
215 while (status->Error_Code >= 0) {
216 if (status->Error_Code == (code & MPI_IOCSTATUS_MASK))
217 return status->Error_String;
218 status++;
219 }
2545bca0 220 ksnprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
984263bc
MD
221 return buf;
222}
223
224char *
225mpt_ioc_diag(u_int32_t code)
226{
227 const struct Error_Map *status = IOC_Diag;
228 static char buf[128];
229 char *ptr = buf;
230 char *end = &buf[128];
231 buf[0] = '\0';
2545bca0 232 ptr += ksnprintf(buf, sizeof buf, "(0x%08x)", code);
984263bc
MD
233 while (status->Error_Code >= 0) {
234 if ((status->Error_Code & code) != 0)
2545bca0 235 ptr += ksnprintf(ptr, (size_t)(end-ptr), "%s ",
984263bc
MD
236 status->Error_String);
237 status++;
238 }
239 return buf;
240}
241
242static char *
243mpt_ioc_function(int code)
244{
245 const struct Error_Map *status = IOC_Func;
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 }
2545bca0 252 ksnprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
984263bc
MD
253 return buf;
254}
d751f32e 255
984263bc
MD
256static char *
257mpt_ioc_event(int code)
258{
259 const struct Error_Map *status = IOC_Event;
260 static char buf[64];
261 while (status->Error_Code >= 0) {
262 if (status->Error_Code == code)
263 return status->Error_String;
264 status++;
265 }
2545bca0 266 ksnprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
984263bc
MD
267 return buf;
268}
d751f32e 269
984263bc
MD
270static char *
271mpt_scsi_state(int code)
272{
273 const struct Error_Map *status = IOC_SCSIState;
274 static char buf[128];
275 char *ptr = buf;
276 char *end = &buf[128];
277 buf[0] = '\0';
2545bca0 278 ptr += ksnprintf(buf, sizeof buf, "(0x%08x)", code);
984263bc
MD
279 while (status->Error_Code >= 0) {
280 if ((status->Error_Code & code) != 0)
2545bca0 281 ptr += ksnprintf(ptr, (size_t)(end-ptr), "%s ",
984263bc
MD
282 status->Error_String);
283 status++;
284 }
285 return buf;
286}
4c42baf4 287
984263bc
MD
288static char *
289mpt_scsi_status(int code)
290{
291 const struct Error_Map *status = IOC_SCSIStatus;
292 static char buf[64];
293 while (status->Error_Code >= 0) {
294 if (status->Error_Code == code)
295 return status->Error_String;
296 status++;
297 }
2545bca0 298 ksnprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
984263bc
MD
299 return buf;
300}
4c42baf4
SW
301
302static const char *
984263bc
MD
303mpt_who(int who_init)
304{
4c42baf4 305 const char *who;
984263bc
MD
306
307 switch (who_init) {
308 case MPT_DB_INIT_NOONE: who = "No One"; break;
309 case MPT_DB_INIT_BIOS: who = "BIOS"; break;
310 case MPT_DB_INIT_ROMBIOS: who = "ROM BIOS"; break;
311 case MPT_DB_INIT_PCIPEER: who = "PCI Peer"; break;
312 case MPT_DB_INIT_HOST: who = "Host Driver"; break;
313 case MPT_DB_INIT_MANUFACTURE: who = "Manufacturing"; break;
314 default: who = "Unknown"; break;
315 }
316 return who;
317}
318
4c42baf4 319static const char *
984263bc
MD
320mpt_state(u_int32_t mb)
321{
4c42baf4 322 const char *text;
984263bc
MD
323
324 switch (MPT_STATE(mb)) {
325 case MPT_DB_STATE_RESET: text = "Reset"; break;
326 case MPT_DB_STATE_READY: text = "Ready"; break;
327 case MPT_DB_STATE_RUNNING:text = "Running"; break;
328 case MPT_DB_STATE_FAULT: text = "Fault"; break;
329 default: text = "Unknown"; break;
330 }
331 return text;
d751f32e
MD
332}
333
334static char *
335mpt_scsi_tm_type(int code)
336{
337 const struct Error_Map *status = IOC_SCSITMType;
338 static char buf[64];
339 while (status->Error_Code >= 0) {
340 if (status->Error_Code == code)
341 return status->Error_String;
342 status++;
343 }
2545bca0 344 ksnprintf(buf, sizeof buf, "Unknown (0x%08x)", code);
d751f32e
MD
345 return buf;
346}
984263bc
MD
347
348void
349mpt_print_db(u_int32_t mb)
350{
4c42baf4 351
2545bca0 352 kprintf("mpt mailbox: (0x%x) State %s WhoInit %s\n",
984263bc
MD
353 mb, mpt_state(mb), mpt_who(MPT_WHO(mb)));
354}
355
356/*****************************************************************************/
357/* Reply functions */
358/*****************************************************************************/
359static void
360mpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg)
361{
4c42baf4 362
2545bca0
MD
363 kprintf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg);
364 kprintf("\tIOC Status %s\n", mpt_ioc_status(msg->IOCStatus));
6d259fc1 365 kprintf("\tIOCLogInfo 0x%08x\n", msg->IOCLogInfo);
2545bca0
MD
366 kprintf("\tMsgLength 0x%02x\n", msg->MsgLength);
367 kprintf("\tMsgFlags 0x%02x\n", msg->MsgFlags);
6d259fc1 368 kprintf("\tMsgContext 0x%08x\n", msg->MsgContext);
984263bc
MD
369}
370
371static void
372mpt_print_init_reply(MSG_IOC_INIT_REPLY *msg)
373{
4c42baf4 374
984263bc 375 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
2545bca0
MD
376 kprintf("\tWhoInit %s\n", mpt_who(msg->WhoInit));
377 kprintf("\tMaxDevices 0x%02x\n", msg->MaxDevices);
378 kprintf("\tMaxBuses 0x%02x\n", msg->MaxBuses);
984263bc
MD
379}
380
381static void
382mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg)
383{
4c42baf4 384
984263bc 385 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
2545bca0
MD
386 kprintf("\tIOCNumber %d\n", msg->IOCNumber);
387 kprintf("\tMaxChainDepth %d\n", msg->MaxChainDepth);
388 kprintf("\tWhoInit %s\n", mpt_who(msg->WhoInit));
389 kprintf("\tBlockSize %d\n", msg->BlockSize);
390 kprintf("\tFlags %d\n", msg->Flags);
391 kprintf("\tReplyQueueDepth %d\n", msg->ReplyQueueDepth);
392 kprintf("\tReqFrameSize 0x%04x\n", msg->RequestFrameSize);
6d259fc1 393 kprintf("\tFW Version 0x%08x\n", msg->FWVersion.Word);
2545bca0
MD
394 kprintf("\tProduct ID 0x%04x\n", msg->ProductID);
395 kprintf("\tCredits 0x%04x\n", msg->GlobalCredits);
396 kprintf("\tPorts %d\n", msg->NumberOfPorts);
397 kprintf("\tEventState 0x%02x\n", msg->EventState);
6d259fc1 398 kprintf("\tHostMFA_HA 0x%08x\n", msg->CurrentHostMfaHighAddr);
2545bca0 399 kprintf("\tSenseBuf_HA 0x%08x\n",
6d259fc1 400 msg->CurrentSenseBufferHighAddr);
2545bca0
MD
401 kprintf("\tRepFrameSize 0x%04x\n", msg->CurReplyFrameSize);
402 kprintf("\tMaxDevices 0x%02x\n", msg->MaxDevices);
403 kprintf("\tMaxBuses 0x%02x\n", msg->MaxBuses);
6d259fc1 404 kprintf("\tFWImageSize 0x%04x\n", msg->FWImageSize);
984263bc
MD
405}
406
407static void
408mpt_print_enable_reply(MSG_PORT_ENABLE_REPLY *msg)
409{
4c42baf4 410
984263bc 411 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
2545bca0 412 kprintf("\tPort: %d\n", msg->PortNumber);
984263bc
MD
413}
414
415static void
416mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg)
417{
4c42baf4 418
984263bc 419 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
2545bca0
MD
420 kprintf("\tBus: %d\n", msg->Bus);
421 kprintf("\tTargetID %d\n", msg->TargetID);
422 kprintf("\tCDBLength %d\n", msg->CDBLength);
423 kprintf("\tSCSI Status: %s\n", mpt_scsi_status(msg->SCSIStatus));
424 kprintf("\tSCSI State: %s\n", mpt_scsi_state(msg->SCSIState));
6d259fc1
SW
425 kprintf("\tTransferCnt 0x%04x\n", msg->TransferCount);
426 kprintf("\tSenseCnt 0x%04x\n", msg->SenseCount);
427 kprintf("\tResponseInfo 0x%08x\n", msg->ResponseInfo);
984263bc
MD
428}
429
984263bc
MD
430static void
431mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg)
432{
4c42baf4 433
984263bc 434 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
2545bca0 435 kprintf("\tEvent: %s\n", mpt_ioc_event(msg->Event));
6d259fc1 436 kprintf("\tEventContext 0x%04x\n", msg->EventContext);
2545bca0
MD
437 kprintf("\tAckRequired %d\n", msg->AckRequired);
438 kprintf("\tEventDataLength %d\n", msg->EventDataLength);
439 kprintf("\tContinuation %d\n", msg->MsgFlags & 0x80);
984263bc
MD
440 switch(msg->Event) {
441 case MPI_EVENT_LOG_DATA:
6d259fc1 442 kprintf("\tEvtLogData: 0x%04x\n", msg->Data[0]);
984263bc
MD
443 break;
444
445 case MPI_EVENT_UNIT_ATTENTION:
2545bca0 446 kprintf("\tTargetID: 0x%04x\n",
6d259fc1 447 msg->Data[0] & 0xff);
2545bca0 448 kprintf("\tBus: 0x%04x\n",
6d259fc1 449 (msg->Data[0] >> 8) & 0xff);
984263bc
MD
450 break;
451
452 case MPI_EVENT_IOC_BUS_RESET:
453 case MPI_EVENT_EXT_BUS_RESET:
454 case MPI_EVENT_RESCAN:
6d259fc1 455 kprintf("\tPort: %d\n",
984263bc
MD
456 (msg->Data[0] >> 8) & 0xff);
457 break;
458
459 case MPI_EVENT_LINK_STATUS_CHANGE:
6d259fc1 460 kprintf("\tLinkState: %d\n",
984263bc 461 msg->Data[0] & 0xff);
6d259fc1 462 kprintf("\tPort: %d\n",
984263bc
MD
463 (msg->Data[1] >> 8) & 0xff);
464 break;
465
466 case MPI_EVENT_LOOP_STATE_CHANGE:
6d259fc1 467 kprintf("\tType: %d\n",
984263bc 468 (msg->Data[0] >> 16) & 0xff);
aaa82ca4 469 kprintf("\tChar3: 0x%02x\n",
984263bc 470 (msg->Data[0] >> 8) & 0xff);
aaa82ca4 471 kprintf("\tChar4: 0x%02x\n",
984263bc 472 (msg->Data[0] ) & 0xff);
6d259fc1 473 kprintf("\tPort: %d\n",
984263bc
MD
474 (msg->Data[1] >> 8) & 0xff);
475 break;
476
477 case MPI_EVENT_LOGOUT:
aaa82ca4 478 kprintf("\tN_PortId: 0x%04x\n", msg->Data[0]);
6d259fc1 479 kprintf("\tPort: %d\n",
984263bc
MD
480 (msg->Data[1] >> 8) & 0xff);
481 break;
482 }
483
484}
485
486void
487mpt_print_reply(void *vmsg)
488{
489 MSG_DEFAULT_REPLY *msg = vmsg;
490
491 switch (msg->Function) {
492 case MPI_FUNCTION_EVENT_NOTIFICATION:
493 mpt_print_event_notice((MSG_EVENT_NOTIFY_REPLY *)msg);
494 break;
495 case MPI_FUNCTION_PORT_ENABLE:
496 mpt_print_enable_reply((MSG_PORT_ENABLE_REPLY *)msg);
497 break;
498 case MPI_FUNCTION_IOC_FACTS:
499 mpt_print_ioc_facts((MSG_IOC_FACTS_REPLY *)msg);
500 break;
501 case MPI_FUNCTION_IOC_INIT:
502 mpt_print_init_reply((MSG_IOC_INIT_REPLY *)msg);
503 break;
504 case MPI_FUNCTION_SCSI_IO_REQUEST:
d751f32e 505 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
984263bc
MD
506 mpt_print_scsi_io_reply((MSG_SCSI_IO_REPLY *)msg);
507 break;
508 default:
509 mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg);
510 break;
511 }
512}
513
514/*****************************************************************************/
515/* Request functions */
516/*****************************************************************************/
517static void
518mpt_print_request_hdr(MSG_REQUEST_HEADER *req)
519{
2545bca0
MD
520 kprintf("%s @ %p\n", mpt_ioc_function(req->Function), req);
521 kprintf("\tChain Offset 0x%02x\n", req->ChainOffset);
6d259fc1
SW
522 kprintf("\tMsgFlags 0x%02x\n", req->MsgFlags);
523 kprintf("\tMsgContext 0x%08x\n", req->MsgContext);
984263bc
MD
524}
525
4c42baf4 526static void
984263bc
MD
527mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg)
528{
529 MSG_SCSI_IO_REQUEST local, *msg = &local;
530 int i;
531
532 bcopy(orig_msg, msg, sizeof (MSG_SCSI_IO_REQUEST));
533 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
2545bca0
MD
534 kprintf("\tBus: %d\n", msg->Bus);
535 kprintf("\tTargetID %d\n", msg->TargetID);
536 kprintf("\tSenseBufferLength %d\n", msg->SenseBufferLength);
537 kprintf("\tLUN: 0x%0x\n", msg->LUN[1]);
6d259fc1 538 kprintf("\tControl 0x%08x ", msg->Control);
984263bc
MD
539#define MPI_PRINT_FIELD(x) \
540 case MPI_SCSIIO_CONTROL_ ## x : \
2545bca0 541 kprintf(" " #x " "); \
984263bc
MD
542 break
543
544 switch (msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) {
545 MPI_PRINT_FIELD(NODATATRANSFER);
546 MPI_PRINT_FIELD(WRITE);
547 MPI_PRINT_FIELD(READ);
548 default:
2545bca0 549 kprintf(" Invalid DIR! ");
984263bc
MD
550 break;
551 }
552 switch (msg->Control & MPI_SCSIIO_CONTROL_TASKATTRIBUTE_MASK) {
553 MPI_PRINT_FIELD(SIMPLEQ);
554 MPI_PRINT_FIELD(HEADOFQ);
555 MPI_PRINT_FIELD(ORDEREDQ);
556 MPI_PRINT_FIELD(ACAQ);
557 MPI_PRINT_FIELD(UNTAGGED);
558 MPI_PRINT_FIELD(NO_DISCONNECT);
559 default:
2545bca0 560 kprintf(" Unknown attribute! ");
984263bc
MD
561 break;
562 }
563
2545bca0 564 kprintf("\n");
984263bc
MD
565#undef MPI_PRINT_FIELD
566
6d259fc1
SW
567 kprintf("\tDataLength\t0x%08x\n", msg->DataLength);
568 kprintf("\tSenseBufAddr\t0x%08x\n", msg->SenseBufferLowAddr);
2545bca0 569 kprintf("\tCDB[0:%d]\t", msg->CDBLength);
984263bc 570 for (i = 0; i < msg->CDBLength; i++)
2545bca0
MD
571 kprintf("%02x ", msg->CDB[i]);
572 kprintf("\n");
d751f32e
MD
573
574 if ((msg->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK) !=
575 MPI_SCSIIO_CONTROL_NODATATRANSFER ) {
576 mpt_dump_sgl(&orig_msg->SGL,
577 ((char *)&orig_msg->SGL)-(char *)orig_msg);
578 }
579}
580
581static void
582mpt_print_scsi_tmf_request(MSG_SCSI_TASK_MGMT *msg)
583{
4c42baf4 584
d751f32e 585 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
2545bca0
MD
586 kprintf("\tLun 0x%02x\n", msg->LUN[1]);
587 kprintf("\tTaskType %s\n", mpt_scsi_tm_type(msg->TaskType));
6d259fc1 588 kprintf("\tTaskMsgContext 0x%08x\n", msg->TaskMsgContext);
d751f32e
MD
589}
590
591
592static void
593mpt_print_scsi_target_assist_request(PTR_MSG_TARGET_ASSIST_REQUEST msg)
594{
4c42baf4 595
d751f32e 596 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
2545bca0
MD
597 kprintf("\tStatusCode 0x%02x\n", msg->StatusCode);
598 kprintf("\tTargetAssist 0x%02x\n", msg->TargetAssistFlags);
599 kprintf("\tQueueTag 0x%04x\n", msg->QueueTag);
6d259fc1 600 kprintf("\tReplyWord 0x%08x\n", msg->ReplyWord);
2545bca0 601 kprintf("\tLun 0x%02x\n", msg->LUN[1]);
6d259fc1
SW
602 kprintf("\tRelativeOff 0x%08x\n", msg->RelativeOffset);
603 kprintf("\tDataLength 0x%08x\n", msg->DataLength);
d751f32e
MD
604 mpt_dump_sgl(msg->SGL, 0);
605}
606
607static void
608mpt_print_scsi_target_status_send_request(MSG_TARGET_STATUS_SEND_REQUEST *msg)
609{
610 SGE_IO_UNION x;
4c42baf4 611
d751f32e 612 mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg);
2545bca0
MD
613 kprintf("\tStatusCode 0x%02x\n", msg->StatusCode);
614 kprintf("\tStatusFlags 0x%02x\n", msg->StatusFlags);
615 kprintf("\tQueueTag 0x%04x\n", msg->QueueTag);
6d259fc1 616 kprintf("\tReplyWord 0x%08x\n", msg->ReplyWord);
2545bca0 617 kprintf("\tLun 0x%02x\n", msg->LUN[1]);
d751f32e
MD
618 x.u.Simple = msg->StatusDataSGE;
619 mpt_dump_sgl(&x, 0);
984263bc
MD
620}
621
622void
623mpt_print_request(void *vreq)
624{
625 MSG_REQUEST_HEADER *req = vreq;
626
627 switch (req->Function) {
628 case MPI_FUNCTION_SCSI_IO_REQUEST:
d751f32e 629 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
984263bc
MD
630 mpt_print_scsi_io_request((MSG_SCSI_IO_REQUEST *)req);
631 break;
d751f32e
MD
632 case MPI_FUNCTION_SCSI_TASK_MGMT:
633 mpt_print_scsi_tmf_request((MSG_SCSI_TASK_MGMT *)req);
634 break;
635 case MPI_FUNCTION_TARGET_ASSIST:
636 mpt_print_scsi_target_assist_request(
637 (PTR_MSG_TARGET_ASSIST_REQUEST)req);
638 break;
639 case MPI_FUNCTION_TARGET_STATUS_SEND:
640 mpt_print_scsi_target_status_send_request(
641 (MSG_TARGET_STATUS_SEND_REQUEST *)req);
642 break;
984263bc
MD
643 default:
644 mpt_print_request_hdr(req);
645 break;
646 }
647}
648
4c42baf4
SW
649#if 0
650typedef struct mpt_decode_entry {
651 char *name;
652 u_int value;
653 u_int mask;
654} mpt_decode_entry_t;
655
656static int
d751f32e
MD
657mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries,
658 const char *name, u_int value, u_int *cur_column,
659 u_int wrap_point)
984263bc 660{
d751f32e
MD
661 int printed;
662 u_int printed_mask;
663 u_int dummy_column;
984263bc 664
d751f32e
MD
665 if (cur_column == NULL) {
666 dummy_column = 0;
667 cur_column = &dummy_column;
984263bc 668 }
d751f32e
MD
669
670 if (*cur_column >= wrap_point) {
2545bca0 671 kprintf("\n");
d751f32e
MD
672 *cur_column = 0;
673 }
2545bca0 674 printed = kprintf("%s[0x%x]", name, value);
d751f32e 675 if (table == NULL) {
2545bca0 676 printed += kprintf(" ");
d751f32e
MD
677 *cur_column += printed;
678 return (printed);
679 }
680 printed_mask = 0;
681 while (printed_mask != 0xFF) {
682 int entry;
683
684 for (entry = 0; entry < num_entries; entry++) {
685 if (((value & table[entry].mask)
686 != table[entry].value)
687 || ((printed_mask & table[entry].mask)
688 == table[entry].mask))
689 continue;
690
2545bca0 691 printed += kprintf("%s%s",
d751f32e
MD
692 printed_mask == 0 ? ":(" : "|",
693 table[entry].name);
694 printed_mask |= table[entry].mask;
695 break;
696 }
697 if (entry >= num_entries)
698 break;
699 }
700 if (printed_mask != 0)
2545bca0 701 printed += kprintf(") ");
d751f32e 702 else
2545bca0 703 printed += kprintf(" ");
d751f32e
MD
704 *cur_column += printed;
705 return (printed);
706}
707
4c42baf4 708static const mpt_decode_entry_t req_state_parse_table[] = {
d751f32e
MD
709 { "REQ_FREE", 0x00, 0xff },
710 { "REQ_ALLOCATED", 0x01, 0x01 },
711 { "REQ_QUEUED", 0x02, 0x02 },
712 { "REQ_DONE", 0x04, 0x04 },
713 { "REQ_TIMEDOUT", 0x08, 0x08 },
714 { "REQ_NEED_WAKEUP", 0x10, 0x10 }
984263bc
MD
715};
716
4c42baf4 717static void
d751f32e
MD
718mpt_req_state(mpt_req_state_t state)
719{
4c42baf4 720
d751f32e
MD
721 mpt_decode_value(req_state_parse_table,
722 NUM_ELEMENTS(req_state_parse_table),
723 "REQ_STATE", state, NULL, 80);
724}
4c42baf4 725#endif
d751f32e
MD
726
727#define LAST_SGE ( \
728 MPI_SGE_FLAGS_END_OF_LIST | \
729 MPI_SGE_FLAGS_END_OF_BUFFER| \
730 MPI_SGE_FLAGS_LAST_ELEMENT)
731void
732mpt_dump_sgl(SGE_IO_UNION *su, int offset)
984263bc
MD
733{
734 SGE_SIMPLE32 *se = (SGE_SIMPLE32 *) su;
d751f32e
MD
735 const char allfox[4] = { 0xff, 0xff, 0xff, 0xff };
736 void *nxtaddr = se;
737 void *lim;
738 int flags;
739
740 /*
741 * Can't be any bigger than this.
742 */
743 lim = &((char *)se)[MPT_REQUEST_AREA - offset];
984263bc 744
984263bc
MD
745 do {
746 int iprt;
747
2545bca0 748 kprintf("\t");
d751f32e
MD
749 if (memcmp(se, allfox, 4) == 0) {
750 uint32_t *nxt = (uint32_t *)se;
2545bca0 751 kprintf("PAD %p\n", se);
d751f32e
MD
752 nxtaddr = nxt + 1;
753 se = nxtaddr;
754 flags = 0;
755 continue;
756 }
757 nxtaddr = se + 1;
984263bc
MD
758 flags = MPI_SGE_GET_FLAGS(se->FlagsLength);
759 switch (flags & MPI_SGE_FLAGS_ELEMENT_MASK) {
760 case MPI_SGE_FLAGS_SIMPLE_ELEMENT:
d751f32e
MD
761 if (flags & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
762 SGE_SIMPLE64 *se64 = (SGE_SIMPLE64 *)se;
2545bca0 763 kprintf("SE64 %p: Addr=0x%08x%08x FlagsLength"
6d259fc1
SW
764 "=0x%0x\n", se64, se64->Address.High,
765 se64->Address.Low, se64->FlagsLength);
d751f32e
MD
766 nxtaddr = se64 + 1;
767 } else {
2545bca0 768 kprintf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x"
6d259fc1 769 "\n", se, se->Address, se->FlagsLength);
d751f32e 770 }
2545bca0 771 kprintf(" ");
984263bc 772 break;
984263bc 773 case MPI_SGE_FLAGS_CHAIN_ELEMENT:
d751f32e
MD
774 if (flags & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
775 SGE_CHAIN64 *ce64 = (SGE_CHAIN64 *) se;
2545bca0 776 kprintf("CE64 %p: Addr=0x%08x%08x NxtChnO=0x%x "
d751f32e 777 "Flgs=0x%x Len=0x%0x\n", ce64,
6d259fc1 778 ce64->Address.High, ce64->Address.Low,
d751f32e 779 ce64->NextChainOffset,
6d259fc1 780 ce64->Flags, ce64->Length);
d751f32e
MD
781 nxtaddr = ce64 + 1;
782 } else {
783 SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se;
2545bca0 784 kprintf("CE32 %p: Addr=0x%0x NxtChnO=0x%x "
6d259fc1
SW
785 " Flgs=0x%x Len=0x%0x\n", ce, ce->Address,
786 ce->NextChainOffset, ce->Flags, ce->Length);
d751f32e 787 }
984263bc
MD
788 flags = 0;
789 break;
984263bc 790 case MPI_SGE_FLAGS_TRANSACTION_ELEMENT:
2545bca0 791 kprintf("TE32 @ %p\n", se);
984263bc
MD
792 flags = 0;
793 break;
794 }
795 iprt = 0;
796#define MPT_PRINT_FLAG(x) \
797 if (flags & MPI_SGE_FLAGS_ ## x ) { \
798 if (iprt == 0) { \
2545bca0 799 kprintf("\t"); \
984263bc 800 } \
2545bca0
MD
801 kprintf(" "); \
802 kprintf( #x ); \
984263bc
MD
803 iprt++; \
804 }
805 MPT_PRINT_FLAG(LOCAL_ADDRESS);
806 MPT_PRINT_FLAG(HOST_TO_IOC);
807 MPT_PRINT_FLAG(64_BIT_ADDRESSING);
808 MPT_PRINT_FLAG(LAST_ELEMENT);
809 MPT_PRINT_FLAG(END_OF_BUFFER);
810 MPT_PRINT_FLAG(END_OF_LIST);
811#undef MPT_PRINT_FLAG
812 if (iprt)
2545bca0 813 kprintf("\n");
d751f32e
MD
814 se = nxtaddr;
815 if ((flags & LAST_SGE) == LAST_SGE) {
816 break;
817 }
818 } while ((flags & MPI_SGE_FLAGS_END_OF_LIST) == 0 && nxtaddr < lim);
819}
820
821void
822mpt_dump_data(struct mpt_softc *mpt, const char *msg, void *addr, int len)
823{
824 int offset;
825 uint8_t *cp = addr;
4c42baf4 826
d751f32e
MD
827 mpt_prt(mpt, "%s:", msg);
828 for (offset = 0; offset < len; offset++) {
829 if ((offset & 0xf) == 0) {
830 mpt_prtc(mpt, "\n");
831 }
832 mpt_prtc(mpt, " %02x", cp[offset]);
833 }
834 mpt_prtc(mpt, "\n");
835}
836
837void
838mpt_dump_request(struct mpt_softc *mpt, request_t *req)
839{
840 uint32_t *pReq = req->req_vbuf;
841 int o;
4c42baf4 842
d751f32e
MD
843 mpt_prt(mpt, "Send Request %d (%jx):",
844 req->index, (uintmax_t) req->req_pbuf);
d751f32e
MD
845 for (o = 0; o < mpt->ioc_facts.RequestFrameSize; o++) {
846 if ((o & 0x7) == 0) {
847 mpt_prtc(mpt, "\n");
848 mpt_prt(mpt, " ");
849 }
850 mpt_prtc(mpt, " %08x", pReq[o]);
851 }
852 mpt_prtc(mpt, "\n");
853}
854
d751f32e
MD
855void
856mpt_prt(struct mpt_softc *mpt, const char *fmt, ...)
857{
2545bca0 858 __va_list ap;
d751f32e 859
2545bca0
MD
860 kprintf("%s: ", device_get_nameunit(mpt->dev));
861 __va_start(ap, fmt);
862 kvprintf(fmt, ap);
863 __va_end(ap);
d751f32e
MD
864}
865
866void
867mpt_prtc(struct mpt_softc *mpt, const char *fmt, ...)
868{
2545bca0 869 __va_list ap;
d751f32e 870
2545bca0
MD
871 __va_start(ap, fmt);
872 kvprintf(fmt, ap);
873 __va_end(ap);
984263bc 874}