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