xref: /freebsd/sys/dev/mpr/mpr_table.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1 /*-
2  * Copyright (c) 2009 Yahoo! Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 /* Debugging tables for MPT2 */
29 
30 /* TODO Move headers to mprvar */
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/selinfo.h>
36 #include <sys/module.h>
37 #include <sys/bus.h>
38 #include <sys/conf.h>
39 #include <sys/bio.h>
40 #include <sys/malloc.h>
41 #include <sys/uio.h>
42 #include <sys/sysctl.h>
43 #include <sys/queue.h>
44 #include <sys/kthread.h>
45 #include <sys/taskqueue.h>
46 
47 #include <machine/bus.h>
48 #include <machine/resource.h>
49 #include <sys/rman.h>
50 
51 #include <cam/scsi/scsi_all.h>
52 
53 #include <dev/mpr/mpi/mpi2_type.h>
54 #include <dev/mpr/mpi/mpi2.h>
55 #include <dev/mpr/mpi/mpi2_ioc.h>
56 #include <dev/mpr/mpi/mpi2_cnfg.h>
57 #include <dev/mpr/mpi/mpi2_init.h>
58 #include <dev/mpr/mpi/mpi2_tool.h>
59 #include <dev/mpr/mpi/mpi2_pci.h>
60 #include <dev/mpr/mpr_ioctl.h>
61 #include <dev/mpr/mprvar.h>
62 #include <dev/mpr/mpr_table.h>
63 
64 char *
65 mpr_describe_table(struct mpr_table_lookup *table, u_int code)
66 {
67 	int i;
68 
69 	for (i = 0; table[i].string != NULL; i++) {
70 		if (table[i].code == code)
71 			return(table[i].string);
72 	}
73 	return(table[i+1].string);
74 }
75 
76 //SLM-Add new PCIe info to all of these tables
77 struct mpr_table_lookup mpr_event_names[] = {
78 	{"LogData",			0x01},
79 	{"StateChange",			0x02},
80 	{"HardResetReceived",		0x05},
81 	{"EventChange",			0x0a},
82 	{"TaskSetFull",			0x0e},
83 	{"SasDeviceStatusChange",	0x0f},
84 	{"IrOperationStatus",		0x14},
85 	{"SasDiscovery",		0x16},
86 	{"SasBroadcastPrimitive",	0x17},
87 	{"SasInitDeviceStatusChange",	0x18},
88 	{"SasInitTableOverflow",	0x19},
89 	{"SasTopologyChangeList",	0x1c},
90 	{"SasEnclDeviceStatusChange",	0x1d},
91 	{"IrVolume",			0x1e},
92 	{"IrPhysicalDisk",		0x1f},
93 	{"IrConfigurationChangeList",	0x20},
94 	{"LogEntryAdded",		0x21},
95 	{"SasPhyCounter",		0x22},
96 	{"GpioInterrupt",		0x23},
97 	{"HbdPhyEvent",			0x24},
98 	{"SasQuiesce",			0x25},
99 	{"SasNotifyPrimitive",		0x26},
100 	{"TempThreshold",		0x27},
101 	{"HostMessage",			0x28},
102 	{"PowerPerformanceChange",	0x29},
103 	{"PCIeDeviceStatusChange",	0x30},
104 	{"PCIeEnumeration",		0x31},
105 	{"PCIeTopologyChangeList",	0x32},
106 	{"PCIeLinkCounter",		0x33},
107 	{"CableEvent",			0x34},
108 	{NULL, 0},
109 	{"Unknown Event", 0}
110 };
111 
112 struct mpr_table_lookup mpr_phystatus_names[] = {
113 	{"NewTargetAdded",		0x01},
114 	{"TargetGone",			0x02},
115 	{"PHYLinkStatusChange",		0x03},
116 	{"PHYLinkStatusUnchanged",	0x04},
117 	{"TargetMissing",		0x05},
118 	{NULL, 0},
119 	{"Unknown Status", 0}
120 };
121 
122 struct mpr_table_lookup mpr_linkrate_names[] = {
123 	{"PHY disabled",		0x01},
124 	{"Speed Negotiation Failed",	0x02},
125 	{"SATA OOB Complete",		0x03},
126 	{"SATA Port Selector",		0x04},
127 	{"SMP Reset in Progress",	0x05},
128 	{"1.5Gbps",			0x08},
129 	{"3.0Gbps",			0x09},
130 	{"6.0Gbps",			0x0a},
131 	{"12.0Gbps",			0x0b},
132 	{NULL, 0},
133 	{"LinkRate Unknown",		0x00}
134 };
135 
136 struct mpr_table_lookup mpr_sasdev0_devtype[] = {
137 	{"End Device",			0x01},
138 	{"Edge Expander",		0x02},
139 	{"Fanout Expander",		0x03},
140 	{NULL, 0},
141 	{"No Device",			0x00}
142 };
143 
144 struct mpr_table_lookup mpr_phyinfo_reason_names[] = {
145 	{"Power On",			0x01},
146 	{"Hard Reset",			0x02},
147 	{"SMP Phy Control Link Reset",	0x03},
148 	{"Loss DWORD Sync",		0x04},
149 	{"Multiplex Sequence",		0x05},
150 	{"I-T Nexus Loss Timer",	0x06},
151 	{"Break Timeout Timer",		0x07},
152 	{"PHY Test Function",		0x08},
153 	{NULL, 0},
154 	{"Unknown Reason",		0x00}
155 };
156 
157 struct mpr_table_lookup mpr_whoinit_names[] = {
158 	{"System BIOS",			0x01},
159 	{"ROM BIOS",			0x02},
160 	{"PCI Peer",			0x03},
161 	{"Host Driver",			0x04},
162 	{"Manufacturing",		0x05},
163 	{NULL, 0},
164 	{"Not Initialized",		0x00}
165 };
166 
167 struct mpr_table_lookup mpr_sasdisc_reason[] = {
168 	{"Discovery Started",		0x01},
169 	{"Discovery Complete",		0x02},
170 	{NULL, 0},
171 	{"Unknown",			0x00}
172 };
173 
174 struct mpr_table_lookup mpr_sastopo_exp[] = {
175 	{"Added",			0x01},
176 	{"Not Responding",		0x02},
177 	{"Responding",			0x03},
178 	{"Delay Not Responding",	0x04},
179 	{NULL, 0},
180 	{"Unknown",			0x00}
181 };
182 
183 struct mpr_table_lookup mpr_sasdev_reason[] = {
184 	{"SMART Data",			0x05},
185 	{"Unsupported",			0x07},
186 	{"Internal Device Reset",	0x08},
187 	{"Task Abort Internal",		0x09},
188 	{"Abort Task Set Internal",	0x0a},
189 	{"Clear Task Set Internal",	0x0b},
190 	{"Query Task Internal",		0x0c},
191 	{"Async Notification",		0x0d},
192 	{"Cmp Internal Device Reset",	0x0e},
193 	{"Cmp Task Abort Internal",	0x0f},
194 	{"Sata Init Failure",		0x10},
195 	{NULL, 0},
196 	{"Unknown",			0x00}
197 };
198 
199 struct mpr_table_lookup mpr_pcie_linkrate_names[] = {
200 	{"Port disabled",		0x01},
201 	{"2.5GT/sec",			0x02},
202 	{"5.0GT/sec",			0x03},
203 	{"8.0GT/sec",			0x04},
204 	{"16.0GT/sec",			0x05},
205 	{NULL, 0},
206 	{"LinkRate Unknown",		0x00}
207 };
208 
209 struct mpr_table_lookup mpr_iocstatus_string[] = {
210 	{"success",			MPI2_IOCSTATUS_SUCCESS},
211 	{"invalid function",		MPI2_IOCSTATUS_INVALID_FUNCTION},
212 	{"scsi recovered error",	MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR},
213 	{"scsi invalid dev handle",	MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE},
214 	{"scsi device not there",	MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE},
215 	{"scsi data overrun",		MPI2_IOCSTATUS_SCSI_DATA_OVERRUN},
216 	{"scsi data underrun",		MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN},
217 	{"scsi io data error",		MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR},
218 	{"scsi protocol error",		MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR},
219 	{"scsi task terminated",	MPI2_IOCSTATUS_SCSI_TASK_TERMINATED},
220 	{"scsi residual mismatch",	MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH},
221 	{"scsi task mgmt failed",	MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED},
222 	{"scsi ioc terminated",		MPI2_IOCSTATUS_SCSI_IOC_TERMINATED},
223 	{"scsi ext terminated",		MPI2_IOCSTATUS_SCSI_EXT_TERMINATED},
224 	{"eedp guard error",		MPI2_IOCSTATUS_EEDP_GUARD_ERROR},
225 	{"eedp ref tag error",		MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR},
226 	{"eedp app tag error",		MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR},
227 	{NULL, 0},
228 	{"unknown",			0x00}
229 };
230 
231 struct mpr_table_lookup mpr_scsi_status_string[] = {
232 	{"good",			MPI2_SCSI_STATUS_GOOD},
233 	{"check condition",		MPI2_SCSI_STATUS_CHECK_CONDITION},
234 	{"condition met",		MPI2_SCSI_STATUS_CONDITION_MET},
235 	{"busy",			MPI2_SCSI_STATUS_BUSY},
236 	{"intermediate",		MPI2_SCSI_STATUS_INTERMEDIATE},
237 	{"intermediate condmet",	MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET},
238 	{"reservation conflict",	MPI2_SCSI_STATUS_RESERVATION_CONFLICT},
239 	{"command terminated",		MPI2_SCSI_STATUS_COMMAND_TERMINATED},
240 	{"task set full",		MPI2_SCSI_STATUS_TASK_SET_FULL},
241 	{"aca active",			MPI2_SCSI_STATUS_ACA_ACTIVE},
242 	{"task aborted",		MPI2_SCSI_STATUS_TASK_ABORTED},
243 	{NULL, 0},
244 	{"unknown",			0x00}
245 };
246 
247 struct mpr_table_lookup mpr_scsi_taskmgmt_string[] = {
248 	{"task mgmt request completed",	MPI2_SCSITASKMGMT_RSP_TM_COMPLETE},
249 	{"invalid frame",		MPI2_SCSITASKMGMT_RSP_INVALID_FRAME},
250 	{"task mgmt request not supp",	MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED},
251 	{"task mgmt request failed",	MPI2_SCSITASKMGMT_RSP_TM_FAILED},
252 	{"task mgmt request_succeeded",	MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED},
253 	{"invalid lun",			MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN},
254 	{"overlapped tag attempt",	0xA},
255 	{"task queued on IOC",		MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC},
256 	{NULL, 0},
257 	{"unknown",			0x00}
258 };
259 
260 void
261 mpr_describe_devinfo(uint32_t devinfo, char *string, int len)
262 {
263 	snprintf(string, len, "%b,%s", devinfo,
264 	    "\20" "\4SataHost" "\5SmpInit" "\6StpInit" "\7SspInit"
265 	    "\10SataDev" "\11SmpTarg" "\12StpTarg" "\13SspTarg" "\14Direct"
266 	    "\15LsiDev" "\16AtapiDev" "\17SepDev",
267 	    mpr_describe_table(mpr_sasdev0_devtype, devinfo & 0x03));
268 }
269 
270 void
271 mpr_print_iocfacts(struct mpr_softc *sc, MPI2_IOC_FACTS_REPLY *facts)
272 {
273 	MPR_PRINTFIELD_START(sc, "IOCFacts");
274 	MPR_PRINTFIELD(sc, facts, MsgVersion, 0x%x);
275 	MPR_PRINTFIELD(sc, facts, HeaderVersion, 0x%x);
276 	MPR_PRINTFIELD(sc, facts, IOCNumber, %d);
277 	MPR_PRINTFIELD(sc, facts, IOCExceptions, 0x%x);
278 	MPR_PRINTFIELD(sc, facts, MaxChainDepth, %d);
279 	mpr_print_field(sc, "WhoInit: %s\n",
280 	    mpr_describe_table(mpr_whoinit_names, facts->WhoInit));
281 	MPR_PRINTFIELD(sc, facts, NumberOfPorts, %d);
282 	MPR_PRINTFIELD(sc, facts, MaxMSIxVectors, %d);
283 	MPR_PRINTFIELD(sc, facts, RequestCredit, %d);
284 	MPR_PRINTFIELD(sc, facts, ProductID, 0x%x);
285 	mpr_print_field(sc, "IOCCapabilities: %b\n",
286 	    facts->IOCCapabilities, "\20" "\3ScsiTaskFull" "\4DiagTrace"
287 	    "\5SnapBuf" "\6ExtBuf" "\7EEDP" "\10BiDirTarg" "\11Multicast"
288 	    "\14TransRetry" "\15IR" "\16EventReplay" "\17RaidAccel"
289 	    "\20MSIXIndex" "\21HostDisc");
290 	mpr_print_field(sc, "FWVersion= %d-%d-%d-%d\n",
291 	    facts->FWVersion.Struct.Major,
292 	    facts->FWVersion.Struct.Minor,
293 	    facts->FWVersion.Struct.Unit,
294 	    facts->FWVersion.Struct.Dev);
295 	MPR_PRINTFIELD(sc, facts, IOCRequestFrameSize, %d);
296 	MPR_PRINTFIELD(sc, facts, MaxInitiators, %d);
297 	MPR_PRINTFIELD(sc, facts, MaxTargets, %d);
298 	MPR_PRINTFIELD(sc, facts, MaxSasExpanders, %d);
299 	MPR_PRINTFIELD(sc, facts, MaxEnclosures, %d);
300 	mpr_print_field(sc, "ProtocolFlags: %b\n",
301 	    facts->ProtocolFlags, "\20" "\1ScsiTarg" "\2ScsiInit");
302 	MPR_PRINTFIELD(sc, facts, HighPriorityCredit, %d);
303 	MPR_PRINTFIELD(sc, facts, MaxReplyDescriptorPostQueueDepth, %d);
304 	MPR_PRINTFIELD(sc, facts, ReplyFrameSize, %d);
305 	MPR_PRINTFIELD(sc, facts, MaxVolumes, %d);
306 	MPR_PRINTFIELD(sc, facts, MaxDevHandle, %d);
307 	MPR_PRINTFIELD(sc, facts, MaxPersistentEntries, %d);
308 }
309 
310 void
311 mpr_print_portfacts(struct mpr_softc *sc, MPI2_PORT_FACTS_REPLY *facts)
312 {
313 
314 	MPR_PRINTFIELD_START(sc, "PortFacts");
315 	MPR_PRINTFIELD(sc, facts, PortNumber, %d);
316 	MPR_PRINTFIELD(sc, facts, PortType, 0x%x);
317 	MPR_PRINTFIELD_16(sc, facts, MaxPostedCmdBuffers, %d);
318 }
319 
320 void
321 mpr_print_evt_generic(struct mpr_softc *sc, MPI2_EVENT_NOTIFICATION_REPLY *event)
322 {
323 
324 	MPR_PRINTFIELD_START(sc, "EventReply");
325 	MPR_PRINTFIELD_16(sc, event, EventDataLength, %d);
326 	MPR_PRINTFIELD(sc, event, AckRequired, %d);
327 	mpr_print_field(sc, "Event: %s (0x%x)\n",
328 	    mpr_describe_table(mpr_event_names, le16toh(event->Event)), le16toh(event->Event));
329 	MPR_PRINTFIELD_32(sc, event, EventContext, 0x%x);
330 }
331 
332 void
333 mpr_print_sasdev0(struct mpr_softc *sc, MPI2_CONFIG_PAGE_SAS_DEV_0 *buf)
334 {
335 	MPR_PRINTFIELD_START(sc, "SAS Device Page 0");
336 	MPR_PRINTFIELD_16(sc, buf, Slot, %d);
337 	MPR_PRINTFIELD_16(sc, buf, EnclosureHandle, 0x%x);
338 	mpr_print_field(sc, "SASAddress: 0x%jx\n",
339 	    mpr_to_u64(&buf->SASAddress));
340 	MPR_PRINTFIELD_16(sc, buf, ParentDevHandle, 0x%x);
341 	MPR_PRINTFIELD(sc, buf, PhyNum, %d);
342 	MPR_PRINTFIELD(sc, buf, AccessStatus, 0x%x);
343 	MPR_PRINTFIELD_16(sc, buf, DevHandle, 0x%x);
344 	MPR_PRINTFIELD(sc, buf, AttachedPhyIdentifier, 0x%x);
345 	MPR_PRINTFIELD(sc, buf, ZoneGroup, %d);
346 	mpr_print_field(sc, "DeviceInfo: %b,%s\n", le32toh(buf->DeviceInfo),
347 	    "\20" "\4SataHost" "\5SmpInit" "\6StpInit" "\7SspInit"
348 	    "\10SataDev" "\11SmpTarg" "\12StpTarg" "\13SspTarg" "\14Direct"
349 	    "\15LsiDev" "\16AtapiDev" "\17SepDev",
350 	    mpr_describe_table(mpr_sasdev0_devtype, buf->DeviceInfo & 0x03));
351 	MPR_PRINTFIELD_16(sc, buf, Flags, 0x%x);
352 	MPR_PRINTFIELD(sc, buf, PhysicalPort, %d);
353 	MPR_PRINTFIELD(sc, buf, MaxPortConnections, %d);
354 	mpr_print_field(sc, "DeviceName: 0x%jx\n",
355 	    mpr_to_u64(&buf->DeviceName));
356 	MPR_PRINTFIELD(sc, buf, PortGroups, %d);
357 	MPR_PRINTFIELD(sc, buf, DmaGroup, %d);
358 	MPR_PRINTFIELD(sc, buf, ControlGroup, %d);
359 }
360 
361 void
362 mpr_print_evt_sas(struct mpr_softc *sc, MPI2_EVENT_NOTIFICATION_REPLY *event)
363 {
364 
365 	mpr_print_evt_generic(sc, event);
366 
367 	switch(le16toh(event->Event)) {
368 	case MPI2_EVENT_SAS_DISCOVERY:
369 	{
370 		MPI2_EVENT_DATA_SAS_DISCOVERY *data;
371 
372 		data = (MPI2_EVENT_DATA_SAS_DISCOVERY *)&event->EventData;
373 		mpr_print_field(sc, "Flags: %b\n", data->Flags,
374 		    "\20" "\1InProgress" "\2DeviceChange");
375 		mpr_print_field(sc, "ReasonCode: %s\n",
376 		    mpr_describe_table(mpr_sasdisc_reason, data->ReasonCode));
377 		MPR_PRINTFIELD(sc, data, PhysicalPort, %d);
378 		mpr_print_field(sc, "DiscoveryStatus: %b\n",
379 		    le32toh(data->DiscoveryStatus),  "\20"
380 		    "\1Loop" "\2UnaddressableDev" "\3DupSasAddr" "\5SmpTimeout"
381 		    "\6ExpRouteFull" "\7RouteIndexError" "\10SmpFailed"
382 		    "\11SmpCrcError" "\12SubSubLink" "\13TableTableLink"
383 		    "\14UnsupDevice" "\15TableSubLink" "\16MultiDomain"
384 		    "\17MultiSub" "\20MultiSubSub" "\34DownstreamInit"
385 		    "\35MaxPhys" "\36MaxTargs" "\37MaxExpanders"
386 		    "\40MaxEnclosures");
387 		break;
388 	}
389 //SLM-add for PCIE EVENT too
390 	case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
391 	{
392 		MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *data;
393 		MPI2_EVENT_SAS_TOPO_PHY_ENTRY *phy;
394 		int i, phynum;
395 
396 		data = (MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *)
397 		    &event->EventData;
398 		MPR_PRINTFIELD_16(sc, data, EnclosureHandle, 0x%x);
399 		MPR_PRINTFIELD_16(sc, data, ExpanderDevHandle, 0x%x);
400 		MPR_PRINTFIELD(sc, data, NumPhys, %d);
401 		MPR_PRINTFIELD(sc, data, NumEntries, %d);
402 		MPR_PRINTFIELD(sc, data, StartPhyNum, %d);
403 		mpr_print_field(sc, "ExpStatus: %s (0x%x)\n",
404 		    mpr_describe_table(mpr_sastopo_exp, data->ExpStatus),
405 		    data->ExpStatus);
406 		MPR_PRINTFIELD(sc, data, PhysicalPort, %d);
407 		for (i = 0; i < data->NumEntries; i++) {
408 			phy = &data->PHY[i];
409 			phynum = data->StartPhyNum + i;
410 			mpr_print_field(sc,
411 			    "PHY[%d].AttachedDevHandle: 0x%04x\n", phynum,
412 			    le16toh(phy->AttachedDevHandle));
413 			mpr_print_field(sc,
414 			    "PHY[%d].LinkRate: %s (0x%x)\n", phynum,
415 			    mpr_describe_table(mpr_linkrate_names,
416 			    (phy->LinkRate >> 4) & 0xf), phy->LinkRate);
417 			mpr_print_field(sc, "PHY[%d].PhyStatus: %s\n",
418 			    phynum, mpr_describe_table(mpr_phystatus_names,
419 			    phy->PhyStatus));
420 		}
421 		break;
422 	}
423 	case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
424 	{
425 		MPI2_EVENT_DATA_SAS_ENCL_DEV_STATUS_CHANGE *data;
426 
427 		data = (MPI2_EVENT_DATA_SAS_ENCL_DEV_STATUS_CHANGE *)
428 		    &event->EventData;
429 		MPR_PRINTFIELD_16(sc, data, EnclosureHandle, 0x%x);
430 		mpr_print_field(sc, "ReasonCode: %s\n",
431 		    mpr_describe_table(mpr_sastopo_exp, data->ReasonCode));
432 		MPR_PRINTFIELD(sc, data, PhysicalPort, %d);
433 		MPR_PRINTFIELD_16(sc, data, NumSlots, %d);
434 		MPR_PRINTFIELD_16(sc, data, StartSlot, %d);
435 		MPR_PRINTFIELD_32(sc, data, PhyBits, 0x%x);
436 		break;
437 	}
438 	case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
439 	{
440 		MPI2_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *data;
441 
442 		data = (MPI2_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
443 		    &event->EventData;
444 		MPR_PRINTFIELD_16(sc, data, TaskTag, 0x%x);
445 		mpr_print_field(sc, "ReasonCode: %s\n",
446 		    mpr_describe_table(mpr_sasdev_reason, data->ReasonCode));
447 		MPR_PRINTFIELD(sc, data, ASC, 0x%x);
448 		MPR_PRINTFIELD(sc, data, ASCQ, 0x%x);
449 		MPR_PRINTFIELD_16(sc, data, DevHandle, 0x%x);
450 		mpr_print_field(sc, "SASAddress: 0x%jx\n",
451 		    mpr_to_u64(&data->SASAddress));
452 		break;
453 	}
454 	case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
455 	{
456 		MPI2_EVENT_DATA_SAS_BROADCAST_PRIMITIVE *data;
457 
458 		data = (MPI2_EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)&event->EventData;
459 		MPR_PRINTFIELD(sc, data, PhyNum, %d);
460 		MPR_PRINTFIELD(sc, data, Port, %d);
461 		MPR_PRINTFIELD(sc, data, PortWidth, %d);
462 		MPR_PRINTFIELD(sc, data, Primitive, 0x%x);
463 		break;
464 	}
465 	default:
466 		break;
467 	}
468 }
469 
470 void
471 mpr_print_expander1(struct mpr_softc *sc, MPI2_CONFIG_PAGE_EXPANDER_1 *buf)
472 {
473 	MPR_PRINTFIELD_START(sc, "SAS Expander Page 1 #%d", buf->Phy);
474 	MPR_PRINTFIELD(sc, buf, PhysicalPort, %d);
475 	MPR_PRINTFIELD(sc, buf, NumPhys, %d);
476 	MPR_PRINTFIELD(sc, buf, Phy, %d);
477 	MPR_PRINTFIELD_16(sc, buf, NumTableEntriesProgrammed, %d);
478 	mpr_print_field(sc, "ProgrammedLinkRate: %s (0x%x)\n",
479 	    mpr_describe_table(mpr_linkrate_names,
480 	    (buf->ProgrammedLinkRate >> 4) & 0xf), buf->ProgrammedLinkRate);
481 	mpr_print_field(sc, "HwLinkRate: %s (0x%x)\n",
482 	    mpr_describe_table(mpr_linkrate_names,
483 	    (buf->HwLinkRate >> 4) & 0xf), buf->HwLinkRate);
484 	MPR_PRINTFIELD_16(sc, buf, AttachedDevHandle, 0x%04x);
485 	mpr_print_field(sc, "PhyInfo Reason: %s (0x%x)\n",
486 	    mpr_describe_table(mpr_phyinfo_reason_names,
487 	    (le32toh(buf->PhyInfo) >> 16) & 0xf), le32toh(buf->PhyInfo));
488 	mpr_print_field(sc, "AttachedDeviceInfo: %b,%s\n",
489 	    le32toh(buf->AttachedDeviceInfo), "\20" "\4SATAhost" "\5SMPinit" "\6STPinit"
490 	    "\7SSPinit" "\10SATAdev" "\11SMPtarg" "\12STPtarg" "\13SSPtarg"
491 	    "\14Direct" "\15LSIdev" "\16ATAPIdev" "\17SEPdev",
492 	    mpr_describe_table(mpr_sasdev0_devtype,
493 	    le32toh(buf->AttachedDeviceInfo) & 0x03));
494 	MPR_PRINTFIELD_16(sc, buf, ExpanderDevHandle, 0x%04x);
495 	MPR_PRINTFIELD(sc, buf, ChangeCount, %d);
496 	mpr_print_field(sc, "NegotiatedLinkRate: %s (0x%x)\n",
497 	    mpr_describe_table(mpr_linkrate_names,
498 	    buf->NegotiatedLinkRate & 0xf), buf->NegotiatedLinkRate);
499 	MPR_PRINTFIELD(sc, buf, PhyIdentifier, %d);
500 	MPR_PRINTFIELD(sc, buf, AttachedPhyIdentifier, %d);
501 	MPR_PRINTFIELD(sc, buf, DiscoveryInfo, 0x%x);
502 	MPR_PRINTFIELD_32(sc, buf, AttachedPhyInfo, 0x%x);
503 	mpr_print_field(sc, "AttachedPhyInfo Reason: %s (0x%x)\n",
504 	    mpr_describe_table(mpr_phyinfo_reason_names,
505 	    le32toh(buf->AttachedPhyInfo) & 0xf), le32toh(buf->AttachedPhyInfo));
506 	MPR_PRINTFIELD(sc, buf, ZoneGroup, %d);
507 	MPR_PRINTFIELD(sc, buf, SelfConfigStatus, 0x%x);
508 }
509 
510 void
511 mpr_print_sasphy0(struct mpr_softc *sc, MPI2_CONFIG_PAGE_SAS_PHY_0 *buf)
512 {
513 	MPR_PRINTFIELD_START(sc, "SAS PHY Page 0");
514 	MPR_PRINTFIELD_16(sc, buf, OwnerDevHandle, 0x%04x);
515 	MPR_PRINTFIELD_16(sc, buf, AttachedDevHandle, 0x%04x);
516 	MPR_PRINTFIELD(sc, buf, AttachedPhyIdentifier, %d);
517 	mpr_print_field(sc, "AttachedPhyInfo Reason: %s (0x%x)\n",
518 	    mpr_describe_table(mpr_phyinfo_reason_names,
519 	    le32toh(buf->AttachedPhyInfo) & 0xf), le32toh(buf->AttachedPhyInfo));
520 	mpr_print_field(sc, "ProgrammedLinkRate: %s (0x%x)\n",
521 	    mpr_describe_table(mpr_linkrate_names,
522 	    (buf->ProgrammedLinkRate >> 4) & 0xf), buf->ProgrammedLinkRate);
523 	mpr_print_field(sc, "HwLinkRate: %s (0x%x)\n",
524 	    mpr_describe_table(mpr_linkrate_names,
525 	    (buf->HwLinkRate >> 4) & 0xf), buf->HwLinkRate);
526 	MPR_PRINTFIELD(sc, buf, ChangeCount, %d);
527 	MPR_PRINTFIELD(sc, buf, Flags, 0x%x);
528 	mpr_print_field(sc, "PhyInfo Reason: %s (0x%x)\n",
529 	    mpr_describe_table(mpr_phyinfo_reason_names,
530 	    (le32toh(buf->PhyInfo) >> 16) & 0xf), le32toh(buf->PhyInfo));
531 	mpr_print_field(sc, "NegotiatedLinkRate: %s (0x%x)\n",
532 	    mpr_describe_table(mpr_linkrate_names,
533 	    buf->NegotiatedLinkRate & 0xf), buf->NegotiatedLinkRate);
534 }
535 
536 void
537 mpr_print_sgl(struct mpr_softc *sc, struct mpr_command *cm, int offset)
538 {
539 	MPI2_IEEE_SGE_SIMPLE64 *ieee_sge;
540 	MPI25_IEEE_SGE_CHAIN64 *ieee_sgc;
541 	MPI2_SGE_SIMPLE64 *sge;
542 	struct mpr_chain *chain = NULL;
543 	char *frame;
544 	u_int i = 0, flags, length;
545 
546 	frame = (char *)cm->cm_req;
547 	ieee_sge = (MPI2_IEEE_SGE_SIMPLE64 *)&frame[offset * 4];
548 	sge = (MPI2_SGE_SIMPLE64 *)&frame[offset * 4];
549 	printf("SGL for command %p\n", cm);
550 
551 	hexdump(frame, 128, NULL, 0);
552 	while ((frame != NULL) && (!(cm->cm_flags & MPR_CM_FLAGS_SGE_SIMPLE))) {
553 		flags = ieee_sge->Flags;
554 		length = le32toh(ieee_sge->Length);
555 		printf("IEEE seg%d flags=0x%02x len=0x%08x addr=0x%016jx\n", i,
556 		    flags, length, mpr_to_u64(&ieee_sge->Address));
557 		if (flags & MPI25_IEEE_SGE_FLAGS_END_OF_LIST)
558 			break;
559 		ieee_sge++;
560 		i++;
561 		if (flags & MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT) {
562 			ieee_sgc = (MPI25_IEEE_SGE_CHAIN64 *)ieee_sge;
563 			printf("IEEE chain flags=0x%x len=0x%x Offset=0x%x "
564 			    "Address=0x%016jx\n", ieee_sgc->Flags,
565 			    le32toh(ieee_sgc->Length),
566 			    ieee_sgc->NextChainOffset,
567 			    mpr_to_u64(&ieee_sgc->Address));
568 			if (chain == NULL)
569 				chain = TAILQ_FIRST(&cm->cm_chain_list);
570 			else
571 				chain = TAILQ_NEXT(chain, chain_link);
572 			frame = (char *)chain->chain;
573 			ieee_sge = (MPI2_IEEE_SGE_SIMPLE64 *)frame;
574 			hexdump(frame, 128, NULL, 0);
575 		}
576 	}
577 	while ((frame != NULL) && (cm->cm_flags & MPR_CM_FLAGS_SGE_SIMPLE)) {
578 		flags = le32toh(sge->FlagsLength) >> MPI2_SGE_FLAGS_SHIFT;
579 		printf("seg%d flags=0x%02x len=0x%06x addr=0x%016jx\n", i,
580 		    flags, le32toh(sge->FlagsLength) & 0xffffff,
581 		    mpr_to_u64(&sge->Address));
582 		if (flags & (MPI2_SGE_FLAGS_END_OF_LIST |
583 		    MPI2_SGE_FLAGS_END_OF_BUFFER))
584 			break;
585 		sge++;
586 		i++;
587 	}
588 }
589 
590 void
591 mpr_print_scsiio_cmd(struct mpr_softc *sc, struct mpr_command *cm)
592 {
593 	MPI2_SCSI_IO_REQUEST *req;
594 
595 	req = (MPI2_SCSI_IO_REQUEST *)cm->cm_req;
596 	mpr_print_sgl(sc, cm, req->SGLOffset0);
597 }
598