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