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