xref: /freebsd/sys/dev/mps/mps_table.c (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
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 mpsvar */
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/mps/mpi/mpi2_type.h>
56 #include <dev/mps/mpi/mpi2.h>
57 #include <dev/mps/mpi/mpi2_ioc.h>
58 #include <dev/mps/mpi/mpi2_cnfg.h>
59 #include <dev/mps/mpi/mpi2_init.h>
60 #include <dev/mps/mpi/mpi2_tool.h>
61 #include <dev/mps/mps_ioctl.h>
62 #include <dev/mps/mpsvar.h>
63 #include <dev/mps/mps_table.h>
64 
65 char *
66 mps_describe_table(struct mps_table_lookup *table, u_int code)
67 {
68 	int i;
69 
70 	for (i = 0; table[i].string != NULL; i++) {
71 		if (table[i].code == code)
72 			return(table[i].string);
73 	}
74 	return(table[i+1].string);
75 }
76 
77 struct mps_table_lookup mps_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 	{NULL, 0},
99 	{"Unknown Event", 0}
100 };
101 
102 struct mps_table_lookup mps_phystatus_names[] = {
103 	{"NewTargetAdded",		0x01},
104 	{"TargetGone",			0x02},
105 	{"PHYLinkStatusChange",		0x03},
106 	{"PHYLinkStatusUnchanged",	0x04},
107 	{"TargetMissing",		0x05},
108 	{NULL, 0},
109 	{"Unknown Status", 0}
110 };
111 
112 struct mps_table_lookup mps_linkrate_names[] = {
113 	{"PHY disabled",		0x01},
114 	{"Speed Negotiation Failed",	0x02},
115 	{"SATA OOB Complete",		0x03},
116 	{"SATA Port Selector",		0x04},
117 	{"SMP Reset in Progress",	0x05},
118 	{"1.5Gbps",			0x08},
119 	{"3.0Gbps",			0x09},
120 	{"6.0Gbps",			0x0a},
121 	{NULL, 0},
122 	{"LinkRate Unknown",		0x00}
123 };
124 
125 struct mps_table_lookup mps_sasdev0_devtype[] = {
126 	{"End Device",			0x01},
127 	{"Edge Expander",		0x02},
128 	{"Fanout Expander",		0x03},
129 	{NULL, 0},
130 	{"No Device",			0x00}
131 };
132 
133 struct mps_table_lookup mps_phyinfo_reason_names[] = {
134 	{"Power On",			0x01},
135 	{"Hard Reset",			0x02},
136 	{"SMP Phy Control Link Reset",	0x03},
137 	{"Loss DWORD Sync",		0x04},
138 	{"Multiplex Sequence",		0x05},
139 	{"I-T Nexus Loss Timer",	0x06},
140 	{"Break Timeout Timer",		0x07},
141 	{"PHY Test Function",		0x08},
142 	{NULL, 0},
143 	{"Unknown Reason",		0x00}
144 };
145 
146 struct mps_table_lookup mps_whoinit_names[] = {
147 	{"System BIOS",			0x01},
148 	{"ROM BIOS",			0x02},
149 	{"PCI Peer",			0x03},
150 	{"Host Driver",			0x04},
151 	{"Manufacturing",		0x05},
152 	{NULL, 0},
153 	{"Not Initialized",		0x00}
154 };
155 
156 struct mps_table_lookup mps_sasdisc_reason[] = {
157 	{"Discovery Started",		0x01},
158 	{"Discovery Complete",		0x02},
159 	{NULL, 0},
160 	{"Unknown",			0x00}
161 };
162 
163 struct mps_table_lookup mps_sastopo_exp[] = {
164 	{"Added",			0x01},
165 	{"Not Responding",		0x02},
166 	{"Responding",			0x03},
167 	{"Delay Not Responding",	0x04},
168 	{NULL, 0},
169 	{"Unknown",			0x00}
170 };
171 
172 struct mps_table_lookup mps_sasdev_reason[] = {
173 	{"SMART Data",			0x05},
174 	{"Unsupported",			0x07},
175 	{"Internal Device Reset",	0x08},
176 	{"Task Abort Internal",		0x09},
177 	{"Abort Task Set Internal",	0x0a},
178 	{"Clear Task Set Internal",	0x0b},
179 	{"Query Task Internal",		0x0c},
180 	{"Async Notification",		0x0d},
181 	{"Cmp Internal Device Reset",	0x0e},
182 	{"Cmp Task Abort Internal",	0x0f},
183 	{"Sata Init Failure",		0x10},
184 	{NULL, 0},
185 	{"Unknown",			0x00}
186 };
187 
188 void
189 mps_describe_devinfo(uint32_t devinfo, char *string, int len)
190 {
191 	snprintf(string, len, "%b,%s", devinfo,
192 	    "\20" "\4SataHost" "\5SmpInit" "\6StpInit" "\7SspInit"
193 	    "\10SataDev" "\11SmpTarg" "\12StpTarg" "\13SspTarg" "\14Direct"
194 	    "\15LsiDev" "\16AtapiDev" "\17SepDev",
195 	    mps_describe_table(mps_sasdev0_devtype, devinfo & 0x03));
196 }
197 
198 void
199 mps_print_iocfacts(struct mps_softc *sc, MPI2_IOC_FACTS_REPLY *facts)
200 {
201 
202 	MPS_PRINTFIELD_START(sc, "IOCFacts");
203 	MPS_PRINTFIELD(sc, facts, MsgVersion, 0x%x);
204 	MPS_PRINTFIELD(sc, facts, HeaderVersion, 0x%x);
205 	MPS_PRINTFIELD(sc, facts, IOCNumber, %d);
206 	MPS_PRINTFIELD(sc, facts, IOCExceptions, 0x%x);
207 	MPS_PRINTFIELD(sc, facts, MaxChainDepth, %d);
208 	mps_dprint_field(sc, MPS_XINFO, "WhoInit: %s\n",
209 	    mps_describe_table(mps_whoinit_names, facts->WhoInit));
210 	MPS_PRINTFIELD(sc, facts, NumberOfPorts, %d);
211 	MPS_PRINTFIELD(sc, facts, RequestCredit, %d);
212 	MPS_PRINTFIELD(sc, facts, ProductID, 0x%x);
213 	mps_dprint_field(sc, MPS_XINFO, "IOCCapabilities: %b\n",
214 	    facts->IOCCapabilities, "\20" "\3ScsiTaskFull" "\4DiagTrace"
215 	    "\5SnapBuf" "\6ExtBuf" "\7EEDP" "\10BiDirTarg" "\11Multicast"
216 	    "\14TransRetry" "\15IR" "\16EventReplay" "\17RaidAccel"
217 	    "\20MSIXIndex" "\21HostDisc");
218 	mps_dprint_field(sc, MPS_XINFO, "FWVersion= %d-%d-%d-%d\n",
219 	    facts->FWVersion.Struct.Major,
220 	    facts->FWVersion.Struct.Minor,
221 	    facts->FWVersion.Struct.Unit,
222 	    facts->FWVersion.Struct.Dev);
223 	MPS_PRINTFIELD(sc, facts, IOCRequestFrameSize, %d);
224 	MPS_PRINTFIELD(sc, facts, MaxInitiators, %d);
225 	MPS_PRINTFIELD(sc, facts, MaxTargets, %d);
226 	MPS_PRINTFIELD(sc, facts, MaxSasExpanders, %d);
227 	MPS_PRINTFIELD(sc, facts, MaxEnclosures, %d);
228 	mps_dprint_field(sc, MPS_XINFO, "ProtocolFlags: %b\n",
229 	    facts->ProtocolFlags, "\20" "\1ScsiTarg" "\2ScsiInit");
230 	MPS_PRINTFIELD(sc, facts, HighPriorityCredit, %d);
231 	MPS_PRINTFIELD(sc, facts, MaxReplyDescriptorPostQueueDepth, %d);
232 	MPS_PRINTFIELD(sc, facts, ReplyFrameSize, %d);
233 	MPS_PRINTFIELD(sc, facts, MaxVolumes, %d);
234 	MPS_PRINTFIELD(sc, facts, MaxDevHandle, %d);
235 	MPS_PRINTFIELD(sc, facts, MaxPersistentEntries, %d);
236 }
237 
238 void
239 mps_print_portfacts(struct mps_softc *sc, MPI2_PORT_FACTS_REPLY *facts)
240 {
241 
242 	MPS_PRINTFIELD_START(sc, "PortFacts");
243 	MPS_PRINTFIELD(sc, facts, PortNumber, %d);
244 	MPS_PRINTFIELD(sc, facts, PortType, 0x%x);
245 	MPS_PRINTFIELD(sc, facts, MaxPostedCmdBuffers, %d);
246 }
247 
248 void
249 mps_print_event(struct mps_softc *sc, MPI2_EVENT_NOTIFICATION_REPLY *event)
250 {
251 
252 	MPS_EVENTFIELD_START(sc, "EventReply");
253 	MPS_EVENTFIELD(sc, event, EventDataLength, %d);
254 	MPS_EVENTFIELD(sc, event, AckRequired, %d);
255 	mps_dprint_field(sc, MPS_EVENT, "Event: %s (0x%x)\n",
256 	    mps_describe_table(mps_event_names, event->Event), event->Event);
257 	MPS_EVENTFIELD(sc, event, EventContext, 0x%x);
258 }
259 
260 void
261 mps_print_sasdev0(struct mps_softc *sc, MPI2_CONFIG_PAGE_SAS_DEV_0 *buf)
262 {
263 	MPS_PRINTFIELD_START(sc, "SAS Device Page 0");
264 	MPS_PRINTFIELD(sc, buf, Slot, %d);
265 	MPS_PRINTFIELD(sc, buf, EnclosureHandle, 0x%x);
266 	mps_dprint_field(sc, MPS_XINFO, "SASAddress: 0x%jx\n",
267 	    mps_to_u64(&buf->SASAddress));
268 	MPS_PRINTFIELD(sc, buf, ParentDevHandle, 0x%x);
269 	MPS_PRINTFIELD(sc, buf, PhyNum, %d);
270 	MPS_PRINTFIELD(sc, buf, AccessStatus, 0x%x);
271 	MPS_PRINTFIELD(sc, buf, DevHandle, 0x%x);
272 	MPS_PRINTFIELD(sc, buf, AttachedPhyIdentifier, 0x%x);
273 	MPS_PRINTFIELD(sc, buf, ZoneGroup, %d);
274 	mps_dprint_field(sc, MPS_XINFO, "DeviceInfo: %b,%s\n", buf->DeviceInfo,
275 	    "\20" "\4SataHost" "\5SmpInit" "\6StpInit" "\7SspInit"
276 	    "\10SataDev" "\11SmpTarg" "\12StpTarg" "\13SspTarg" "\14Direct"
277 	    "\15LsiDev" "\16AtapiDev" "\17SepDev",
278 	    mps_describe_table(mps_sasdev0_devtype, buf->DeviceInfo & 0x03));
279 	MPS_PRINTFIELD(sc, buf, Flags, 0x%x);
280 	MPS_PRINTFIELD(sc, buf, PhysicalPort, %d);
281 	MPS_PRINTFIELD(sc, buf, MaxPortConnections, %d);
282 	mps_dprint_field(sc, MPS_XINFO, "DeviceName: 0x%jx\n",
283 	    mps_to_u64(&buf->DeviceName));
284 	MPS_PRINTFIELD(sc, buf, PortGroups, %d);
285 	MPS_PRINTFIELD(sc, buf, DmaGroup, %d);
286 	MPS_PRINTFIELD(sc, buf, ControlGroup, %d);
287 }
288 
289 void
290 mps_print_evt_sas(struct mps_softc *sc, MPI2_EVENT_NOTIFICATION_REPLY *event)
291 {
292 
293 	mps_print_event(sc, event);
294 
295 	switch(event->Event) {
296 	case MPI2_EVENT_SAS_DISCOVERY:
297 	{
298 		MPI2_EVENT_DATA_SAS_DISCOVERY *data;
299 
300 		data = (MPI2_EVENT_DATA_SAS_DISCOVERY *)&event->EventData;
301 		mps_dprint_field(sc, MPS_EVENT, "Flags: %b\n", data->Flags,
302 		    "\20" "\1InProgress" "\2DeviceChange");
303 		mps_dprint_field(sc, MPS_EVENT, "ReasonCode: %s\n",
304 		    mps_describe_table(mps_sasdisc_reason, data->ReasonCode));
305 		MPS_EVENTFIELD(sc, data, PhysicalPort, %d);
306 		mps_dprint_field(sc, MPS_EVENT, "DiscoveryStatus: %b\n",
307 		    data->DiscoveryStatus,  "\20"
308 		    "\1Loop" "\2UnaddressableDev" "\3DupSasAddr" "\5SmpTimeout"
309 		    "\6ExpRouteFull" "\7RouteIndexError" "\10SmpFailed"
310 		    "\11SmpCrcError" "\12SubSubLink" "\13TableTableLink"
311 		    "\14UnsupDevice" "\15TableSubLink" "\16MultiDomain"
312 		    "\17MultiSub" "\20MultiSubSub" "\34DownstreamInit"
313 		    "\35MaxPhys" "\36MaxTargs" "\37MaxExpanders"
314 		    "\40MaxEnclosures");
315 		break;
316 	}
317 	case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
318 	{
319 		MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *data;
320 		MPI2_EVENT_SAS_TOPO_PHY_ENTRY *phy;
321 		int i, phynum;
322 
323 		data = (MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *)
324 		    &event->EventData;
325 		MPS_EVENTFIELD(sc, data, EnclosureHandle, 0x%x);
326 		MPS_EVENTFIELD(sc, data, ExpanderDevHandle, 0x%x);
327 		MPS_EVENTFIELD(sc, data, NumPhys, %d);
328 		MPS_EVENTFIELD(sc, data, NumEntries, %d);
329 		MPS_EVENTFIELD(sc, data, StartPhyNum, %d);
330 		mps_dprint_field(sc, MPS_EVENT, "ExpStatus: %s (0x%x)\n",
331 		    mps_describe_table(mps_sastopo_exp, data->ExpStatus),
332 		    data->ExpStatus);
333 		MPS_EVENTFIELD(sc, data, PhysicalPort, %d);
334 		for (i = 0; i < data->NumEntries; i++) {
335 			phy = &data->PHY[i];
336 			phynum = data->StartPhyNum + i;
337 			mps_dprint_field(sc, MPS_EVENT,
338 			    "PHY[%d].AttachedDevHandle: 0x%04x\n", phynum,
339 			    phy->AttachedDevHandle);
340 			mps_dprint_field(sc, MPS_EVENT,
341 			    "PHY[%d].LinkRate: %s (0x%x)\n", phynum,
342 			    mps_describe_table(mps_linkrate_names,
343 			    (phy->LinkRate >> 4) & 0xf), phy->LinkRate);
344 			mps_dprint_field(sc,MPS_EVENT,"PHY[%d].PhyStatus: %s\n",
345 			    phynum, mps_describe_table(mps_phystatus_names,
346 			    phy->PhyStatus));
347 		}
348 		break;
349 	}
350 	case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
351 	{
352 		MPI2_EVENT_DATA_SAS_ENCL_DEV_STATUS_CHANGE *data;
353 
354 		data = (MPI2_EVENT_DATA_SAS_ENCL_DEV_STATUS_CHANGE *)
355 		    &event->EventData;
356 		MPS_EVENTFIELD(sc, data, EnclosureHandle, 0x%x);
357 		mps_dprint_field(sc, MPS_EVENT, "ReasonCode: %s\n",
358 		    mps_describe_table(mps_sastopo_exp, data->ReasonCode));
359 		MPS_EVENTFIELD(sc, data, PhysicalPort, %d);
360 		MPS_EVENTFIELD(sc, data, NumSlots, %d);
361 		MPS_EVENTFIELD(sc, data, StartSlot, %d);
362 		MPS_EVENTFIELD(sc, data, PhyBits, 0x%x);
363 		break;
364 	}
365 	case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
366 	{
367 		MPI2_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *data;
368 
369 		data = (MPI2_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
370 		    &event->EventData;
371 		MPS_EVENTFIELD(sc, data, TaskTag, 0x%x);
372 		mps_dprint_field(sc, MPS_EVENT, "ReasonCode: %s\n",
373 		    mps_describe_table(mps_sasdev_reason, data->ReasonCode));
374 		MPS_EVENTFIELD(sc, data, ASC, 0x%x);
375 		MPS_EVENTFIELD(sc, data, ASCQ, 0x%x);
376 		MPS_EVENTFIELD(sc, data, DevHandle, 0x%x);
377 		mps_dprint_field(sc, MPS_EVENT, "SASAddress: 0x%jx\n",
378 		    mps_to_u64(&data->SASAddress));
379 	}
380 	default:
381 		break;
382 	}
383 }
384 
385 void
386 mps_print_expander1(struct mps_softc *sc, MPI2_CONFIG_PAGE_EXPANDER_1 *buf)
387 {
388 	MPS_PRINTFIELD_START(sc, "SAS Expander Page 1 #%d", buf->Phy);
389 	MPS_PRINTFIELD(sc, buf, PhysicalPort, %d);
390 	MPS_PRINTFIELD(sc, buf, NumPhys, %d);
391 	MPS_PRINTFIELD(sc, buf, Phy, %d);
392 	MPS_PRINTFIELD(sc, buf, NumTableEntriesProgrammed, %d);
393 	mps_dprint_field(sc, MPS_XINFO, "ProgrammedLinkRate: %s (0x%x)\n",
394 	    mps_describe_table(mps_linkrate_names,
395 	    (buf->ProgrammedLinkRate >> 4) & 0xf), buf->ProgrammedLinkRate);
396 	mps_dprint_field(sc, MPS_XINFO, "HwLinkRate: %s (0x%x)\n",
397 	    mps_describe_table(mps_linkrate_names,
398 	    (buf->HwLinkRate >> 4) & 0xf), buf->HwLinkRate);
399 	MPS_PRINTFIELD(sc, buf, AttachedDevHandle, 0x%04x);
400 	mps_dprint_field(sc, MPS_XINFO, "PhyInfo Reason: %s (0x%x)\n",
401 	    mps_describe_table(mps_phyinfo_reason_names,
402 	    (buf->PhyInfo >> 16) & 0xf), buf->PhyInfo);
403 	mps_dprint_field(sc, MPS_XINFO, "AttachedDeviceInfo: %b,%s\n",
404 	    buf->AttachedDeviceInfo, "\20" "\4SATAhost" "\5SMPinit" "\6STPinit"
405 	    "\7SSPinit" "\10SATAdev" "\11SMPtarg" "\12STPtarg" "\13SSPtarg"
406 	    "\14Direct" "\15LSIdev" "\16ATAPIdev" "\17SEPdev",
407 	    mps_describe_table(mps_sasdev0_devtype,
408 	    buf->AttachedDeviceInfo & 0x03));
409 	MPS_PRINTFIELD(sc, buf, ExpanderDevHandle, 0x%04x);
410 	MPS_PRINTFIELD(sc, buf, ChangeCount, %d);
411 	mps_dprint_field(sc, MPS_XINFO, "NegotiatedLinkRate: %s (0x%x)\n",
412 	    mps_describe_table(mps_linkrate_names,
413 	    buf->NegotiatedLinkRate & 0xf), buf->NegotiatedLinkRate);
414 	MPS_PRINTFIELD(sc, buf, PhyIdentifier, %d);
415 	MPS_PRINTFIELD(sc, buf, AttachedPhyIdentifier, %d);
416 	MPS_PRINTFIELD(sc, buf, DiscoveryInfo, 0x%x);
417 	MPS_PRINTFIELD(sc, buf, AttachedPhyInfo, 0x%x);
418 	mps_dprint_field(sc, MPS_XINFO, "AttachedPhyInfo Reason: %s (0x%x)\n",
419 	    mps_describe_table(mps_phyinfo_reason_names,
420 	    buf->AttachedPhyInfo & 0xf), buf->AttachedPhyInfo);
421 	MPS_PRINTFIELD(sc, buf, ZoneGroup, %d);
422 	MPS_PRINTFIELD(sc, buf, SelfConfigStatus, 0x%x);
423 }
424 
425 void
426 mps_print_sasphy0(struct mps_softc *sc, MPI2_CONFIG_PAGE_SAS_PHY_0 *buf)
427 {
428 	MPS_PRINTFIELD_START(sc, "SAS PHY Page 0");
429 	MPS_PRINTFIELD(sc, buf, OwnerDevHandle, 0x%04x);
430 	MPS_PRINTFIELD(sc, buf, AttachedDevHandle, 0x%04x);
431 	MPS_PRINTFIELD(sc, buf, AttachedPhyIdentifier, %d);
432 	mps_dprint_field(sc, MPS_XINFO, "AttachedPhyInfo Reason: %s (0x%x)\n",
433 	    mps_describe_table(mps_phyinfo_reason_names,
434 	    buf->AttachedPhyInfo & 0xf), buf->AttachedPhyInfo);
435 	mps_dprint_field(sc, MPS_XINFO, "ProgrammedLinkRate: %s (0x%x)\n",
436 	    mps_describe_table(mps_linkrate_names,
437 	    (buf->ProgrammedLinkRate >> 4) & 0xf), buf->ProgrammedLinkRate);
438 	mps_dprint_field(sc, MPS_XINFO, "HwLinkRate: %s (0x%x)\n",
439 	    mps_describe_table(mps_linkrate_names,
440 	    (buf->HwLinkRate >> 4) & 0xf), buf->HwLinkRate);
441 	MPS_PRINTFIELD(sc, buf, ChangeCount, %d);
442 	MPS_PRINTFIELD(sc, buf, Flags, 0x%x);
443 	mps_dprint_field(sc, MPS_XINFO, "PhyInfo Reason: %s (0x%x)\n",
444 	    mps_describe_table(mps_phyinfo_reason_names,
445 	    (buf->PhyInfo >> 16) & 0xf), buf->PhyInfo);
446 	mps_dprint_field(sc, MPS_XINFO, "NegotiatedLinkRate: %s (0x%x)\n",
447 	    mps_describe_table(mps_linkrate_names,
448 	    buf->NegotiatedLinkRate & 0xf), buf->NegotiatedLinkRate);
449 }
450 
451 void
452 mps_print_sgl(struct mps_softc *sc, struct mps_command *cm, int offset)
453 {
454 	MPI2_SGE_SIMPLE64 *sge;
455 	MPI2_SGE_CHAIN32 *sgc;
456 	MPI2_REQUEST_HEADER *req;
457 	struct mps_chain *chain = NULL;
458 	char *frame;
459 	u_int i = 0, flags;
460 
461 	req = (MPI2_REQUEST_HEADER *)cm->cm_req;
462 	frame = (char *)cm->cm_req;
463 	sge = (MPI2_SGE_SIMPLE64 *)&frame[offset * 4];
464 	printf("SGL for command %p\n", cm);
465 
466 	hexdump(frame, 128, NULL, 0);
467 	while (frame != NULL) {
468 		flags = le32toh(sge->FlagsLength) >> MPI2_SGE_FLAGS_SHIFT;
469 		printf("seg%d flags=0x%02x len=0x%06x addr=0x%016jx\n",
470 		    i, flags, le32toh(sge->FlagsLength) & 0xffffff,
471 		    mps_to_u64(&sge->Address));
472 		if (flags & (MPI2_SGE_FLAGS_END_OF_LIST |
473 		    MPI2_SGE_FLAGS_END_OF_BUFFER))
474 			break;
475 		sge++;
476 		i++;
477 		if (flags & MPI2_SGE_FLAGS_LAST_ELEMENT) {
478 			sgc = (MPI2_SGE_CHAIN32 *)sge;
479 			printf("chain flags=0x%x len=0x%x Offset=0x%x "
480 			    "Address=0x%x\n", sgc->Flags, le16toh(sgc->Length),
481 			    sgc->NextChainOffset, le32toh(sgc->Address));
482 			if (chain == NULL)
483 				chain = TAILQ_FIRST(&cm->cm_chain_list);
484 			else
485 				chain = TAILQ_NEXT(chain, chain_link);
486 			frame = (char *)chain->chain;
487 			sge = (MPI2_SGE_SIMPLE64 *)frame;
488 			hexdump(frame, 128, NULL, 0);
489 		}
490 	}
491 }
492 
493 void
494 mps_print_scsiio_cmd(struct mps_softc *sc, struct mps_command *cm)
495 {
496 	MPI2_SCSI_IO_REQUEST *req;
497 
498 	req = (MPI2_SCSI_IO_REQUEST *)cm->cm_req;
499 	mps_print_sgl(sc, cm, req->SGLOffset0);
500 }
501 
502