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