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