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