1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
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 /* 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/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 #include <sys/queue.h>
45 #include <sys/kthread.h>
46 #include <sys/taskqueue.h>
47
48 #include <machine/bus.h>
49 #include <machine/resource.h>
50 #include <sys/rman.h>
51
52 #include <cam/scsi/scsi_all.h>
53
54 #include <dev/mps/mpi/mpi2_type.h>
55 #include <dev/mps/mpi/mpi2.h>
56 #include <dev/mps/mpi/mpi2_ioc.h>
57 #include <dev/mps/mpi/mpi2_cnfg.h>
58 #include <dev/mps/mpi/mpi2_init.h>
59 #include <dev/mps/mpi/mpi2_tool.h>
60 #include <dev/mps/mps_ioctl.h>
61 #include <dev/mps/mpsvar.h>
62 #include <dev/mps/mps_table.h>
63
64 char *
mps_describe_table(struct mps_table_lookup * table,u_int code)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 struct mps_table_lookup mps_iocstatus_string[] = {
188 {"success", MPI2_IOCSTATUS_SUCCESS},
189 {"invalid function", MPI2_IOCSTATUS_INVALID_FUNCTION},
190 {"scsi recovered error", MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR},
191 {"scsi invalid dev handle", MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE},
192 {"scsi device not there", MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE},
193 {"scsi data overrun", MPI2_IOCSTATUS_SCSI_DATA_OVERRUN},
194 {"scsi data underrun", MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN},
195 {"scsi io data error", MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR},
196 {"scsi protocol error", MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR},
197 {"scsi task terminated", MPI2_IOCSTATUS_SCSI_TASK_TERMINATED},
198 {"scsi residual mismatch", MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH},
199 {"scsi task mgmt failed", MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED},
200 {"scsi ioc terminated", MPI2_IOCSTATUS_SCSI_IOC_TERMINATED},
201 {"scsi ext terminated", MPI2_IOCSTATUS_SCSI_EXT_TERMINATED},
202 {"eedp guard error", MPI2_IOCSTATUS_EEDP_GUARD_ERROR},
203 {"eedp ref tag error", MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR},
204 {"eedp app tag error", MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR},
205 {NULL, 0},
206 {"unknown", 0x00}
207 };
208
209 struct mps_table_lookup mps_scsi_status_string[] = {
210 {"good", MPI2_SCSI_STATUS_GOOD},
211 {"check condition", MPI2_SCSI_STATUS_CHECK_CONDITION},
212 {"condition met", MPI2_SCSI_STATUS_CONDITION_MET},
213 {"busy", MPI2_SCSI_STATUS_BUSY},
214 {"intermediate", MPI2_SCSI_STATUS_INTERMEDIATE},
215 {"intermediate condmet", MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET},
216 {"reservation conflict", MPI2_SCSI_STATUS_RESERVATION_CONFLICT},
217 {"command terminated", MPI2_SCSI_STATUS_COMMAND_TERMINATED},
218 {"task set full", MPI2_SCSI_STATUS_TASK_SET_FULL},
219 {"aca active", MPI2_SCSI_STATUS_ACA_ACTIVE},
220 {"task aborted", MPI2_SCSI_STATUS_TASK_ABORTED},
221 {NULL, 0},
222 {"unknown", 0x00}
223 };
224
225 struct mps_table_lookup mps_scsi_taskmgmt_string[] = {
226 {"task mgmt request completed", MPI2_SCSITASKMGMT_RSP_TM_COMPLETE},
227 {"invalid frame", MPI2_SCSITASKMGMT_RSP_INVALID_FRAME},
228 {"task mgmt request not supp", MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED},
229 {"task mgmt request failed", MPI2_SCSITASKMGMT_RSP_TM_FAILED},
230 {"task mgmt request_succeeded", MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED},
231 {"invalid lun", MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN},
232 {"overlapped tag attempt", 0xA},
233 {"task queued on IOC", MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC},
234 {NULL, 0},
235 {"unknown", 0x00}
236 };
237
238 void
mps_describe_devinfo(uint32_t devinfo,char * string,int len)239 mps_describe_devinfo(uint32_t devinfo, char *string, int len)
240 {
241 snprintf(string, len, "%b,%s", devinfo,
242 "\20" "\4SataHost" "\5SmpInit" "\6StpInit" "\7SspInit"
243 "\10SataDev" "\11SmpTarg" "\12StpTarg" "\13SspTarg" "\14Direct"
244 "\15LsiDev" "\16AtapiDev" "\17SepDev",
245 mps_describe_table(mps_sasdev0_devtype, devinfo & 0x03));
246 }
247
248 void
mps_print_iocfacts(struct mps_softc * sc,MPI2_IOC_FACTS_REPLY * facts)249 mps_print_iocfacts(struct mps_softc *sc, MPI2_IOC_FACTS_REPLY *facts)
250 {
251
252 MPS_PRINTFIELD_START(sc, "IOCFacts");
253 MPS_PRINTFIELD(sc, facts, MsgVersion, 0x%x);
254 MPS_PRINTFIELD(sc, facts, HeaderVersion, 0x%x);
255 MPS_PRINTFIELD(sc, facts, IOCNumber, %d);
256 MPS_PRINTFIELD(sc, facts, IOCExceptions, 0x%x);
257 MPS_PRINTFIELD(sc, facts, MaxChainDepth, %d);
258 mps_print_field(sc, "WhoInit: %s\n",
259 mps_describe_table(mps_whoinit_names, facts->WhoInit));
260 MPS_PRINTFIELD(sc, facts, NumberOfPorts, %d);
261 MPS_PRINTFIELD(sc, facts, MaxMSIxVectors, %d);
262 MPS_PRINTFIELD(sc, facts, RequestCredit, %d);
263 MPS_PRINTFIELD(sc, facts, ProductID, 0x%x);
264 mps_print_field(sc, "IOCCapabilities: %b\n",
265 facts->IOCCapabilities, "\20" "\3ScsiTaskFull" "\4DiagTrace"
266 "\5SnapBuf" "\6ExtBuf" "\7EEDP" "\10BiDirTarg" "\11Multicast"
267 "\14TransRetry" "\15IR" "\16EventReplay" "\17RaidAccel"
268 "\20MSIXIndex" "\21HostDisc");
269 mps_print_field(sc, "FWVersion= %d-%d-%d-%d\n",
270 facts->FWVersion.Struct.Major,
271 facts->FWVersion.Struct.Minor,
272 facts->FWVersion.Struct.Unit,
273 facts->FWVersion.Struct.Dev);
274 MPS_PRINTFIELD(sc, facts, IOCRequestFrameSize, %d);
275 MPS_PRINTFIELD(sc, facts, MaxInitiators, %d);
276 MPS_PRINTFIELD(sc, facts, MaxTargets, %d);
277 MPS_PRINTFIELD(sc, facts, MaxSasExpanders, %d);
278 MPS_PRINTFIELD(sc, facts, MaxEnclosures, %d);
279 mps_print_field(sc, "ProtocolFlags: %b\n",
280 facts->ProtocolFlags, "\20" "\1ScsiTarg" "\2ScsiInit");
281 MPS_PRINTFIELD(sc, facts, HighPriorityCredit, %d);
282 MPS_PRINTFIELD(sc, facts, MaxReplyDescriptorPostQueueDepth, %d);
283 MPS_PRINTFIELD(sc, facts, ReplyFrameSize, %d);
284 MPS_PRINTFIELD(sc, facts, MaxVolumes, %d);
285 MPS_PRINTFIELD(sc, facts, MaxDevHandle, %d);
286 MPS_PRINTFIELD(sc, facts, MaxPersistentEntries, %d);
287 }
288
289 void
mps_print_portfacts(struct mps_softc * sc,MPI2_PORT_FACTS_REPLY * facts)290 mps_print_portfacts(struct mps_softc *sc, MPI2_PORT_FACTS_REPLY *facts)
291 {
292
293 MPS_PRINTFIELD_START(sc, "PortFacts");
294 MPS_PRINTFIELD(sc, facts, PortNumber, %d);
295 MPS_PRINTFIELD(sc, facts, PortType, 0x%x);
296 MPS_PRINTFIELD(sc, facts, MaxPostedCmdBuffers, %d);
297 }
298
299 void
mps_print_evt_generic(struct mps_softc * sc,MPI2_EVENT_NOTIFICATION_REPLY * event)300 mps_print_evt_generic(struct mps_softc *sc, MPI2_EVENT_NOTIFICATION_REPLY *event)
301 {
302
303 MPS_PRINTFIELD_START(sc, "EventReply");
304 MPS_PRINTFIELD(sc, event, EventDataLength, %d);
305 MPS_PRINTFIELD(sc, event, AckRequired, %d);
306 mps_print_field(sc, "Event: %s (0x%x)\n",
307 mps_describe_table(mps_event_names, event->Event), event->Event);
308 MPS_PRINTFIELD(sc, event, EventContext, 0x%x);
309 }
310
311 void
mps_print_sasdev0(struct mps_softc * sc,MPI2_CONFIG_PAGE_SAS_DEV_0 * buf)312 mps_print_sasdev0(struct mps_softc *sc, MPI2_CONFIG_PAGE_SAS_DEV_0 *buf)
313 {
314 MPS_PRINTFIELD_START(sc, "SAS Device Page 0");
315 MPS_PRINTFIELD(sc, buf, Slot, %d);
316 MPS_PRINTFIELD(sc, buf, EnclosureHandle, 0x%x);
317 mps_print_field(sc, "SASAddress: 0x%jx\n",
318 mps_to_u64(&buf->SASAddress));
319 MPS_PRINTFIELD(sc, buf, ParentDevHandle, 0x%x);
320 MPS_PRINTFIELD(sc, buf, PhyNum, %d);
321 MPS_PRINTFIELD(sc, buf, AccessStatus, 0x%x);
322 MPS_PRINTFIELD(sc, buf, DevHandle, 0x%x);
323 MPS_PRINTFIELD(sc, buf, AttachedPhyIdentifier, 0x%x);
324 MPS_PRINTFIELD(sc, buf, ZoneGroup, %d);
325 mps_print_field(sc, "DeviceInfo: %b,%s\n", buf->DeviceInfo,
326 "\20" "\4SataHost" "\5SmpInit" "\6StpInit" "\7SspInit"
327 "\10SataDev" "\11SmpTarg" "\12StpTarg" "\13SspTarg" "\14Direct"
328 "\15LsiDev" "\16AtapiDev" "\17SepDev",
329 mps_describe_table(mps_sasdev0_devtype, buf->DeviceInfo & 0x03));
330 MPS_PRINTFIELD(sc, buf, Flags, 0x%x);
331 MPS_PRINTFIELD(sc, buf, PhysicalPort, %d);
332 MPS_PRINTFIELD(sc, buf, MaxPortConnections, %d);
333 mps_print_field(sc, "DeviceName: 0x%jx\n",
334 mps_to_u64(&buf->DeviceName));
335 MPS_PRINTFIELD(sc, buf, PortGroups, %d);
336 MPS_PRINTFIELD(sc, buf, DmaGroup, %d);
337 MPS_PRINTFIELD(sc, buf, ControlGroup, %d);
338 }
339
340 void
mps_print_evt_sas(struct mps_softc * sc,MPI2_EVENT_NOTIFICATION_REPLY * event)341 mps_print_evt_sas(struct mps_softc *sc, MPI2_EVENT_NOTIFICATION_REPLY *event)
342 {
343
344 mps_print_evt_generic(sc, event);
345
346 switch(event->Event) {
347 case MPI2_EVENT_SAS_DISCOVERY:
348 {
349 MPI2_EVENT_DATA_SAS_DISCOVERY *data;
350
351 data = (MPI2_EVENT_DATA_SAS_DISCOVERY *)&event->EventData;
352 mps_print_field(sc, "Flags: %b\n", data->Flags,
353 "\20" "\1InProgress" "\2DeviceChange");
354 mps_print_field(sc, "ReasonCode: %s\n",
355 mps_describe_table(mps_sasdisc_reason, data->ReasonCode));
356 MPS_PRINTFIELD(sc, data, PhysicalPort, %d);
357 mps_print_field(sc, "DiscoveryStatus: %b\n",
358 data->DiscoveryStatus, "\20"
359 "\1Loop" "\2UnaddressableDev" "\3DupSasAddr" "\5SmpTimeout"
360 "\6ExpRouteFull" "\7RouteIndexError" "\10SmpFailed"
361 "\11SmpCrcError" "\12SubSubLink" "\13TableTableLink"
362 "\14UnsupDevice" "\15TableSubLink" "\16MultiDomain"
363 "\17MultiSub" "\20MultiSubSub" "\34DownstreamInit"
364 "\35MaxPhys" "\36MaxTargs" "\37MaxExpanders"
365 "\40MaxEnclosures");
366 break;
367 }
368 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
369 {
370 MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *data;
371 MPI2_EVENT_SAS_TOPO_PHY_ENTRY *phy;
372 int i, phynum;
373
374 data = (MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *)
375 &event->EventData;
376 MPS_PRINTFIELD(sc, data, EnclosureHandle, 0x%x);
377 MPS_PRINTFIELD(sc, data, ExpanderDevHandle, 0x%x);
378 MPS_PRINTFIELD(sc, data, NumPhys, %d);
379 MPS_PRINTFIELD(sc, data, NumEntries, %d);
380 MPS_PRINTFIELD(sc, data, StartPhyNum, %d);
381 mps_print_field(sc, "ExpStatus: %s (0x%x)\n",
382 mps_describe_table(mps_sastopo_exp, data->ExpStatus),
383 data->ExpStatus);
384 MPS_PRINTFIELD(sc, data, PhysicalPort, %d);
385 for (i = 0; i < data->NumEntries; i++) {
386 phy = &data->PHY[i];
387 phynum = data->StartPhyNum + i;
388 mps_print_field(sc,
389 "PHY[%d].AttachedDevHandle: 0x%04x\n", phynum,
390 phy->AttachedDevHandle);
391 mps_print_field(sc,
392 "PHY[%d].LinkRate: %s (0x%x)\n", phynum,
393 mps_describe_table(mps_linkrate_names,
394 (phy->LinkRate >> 4) & 0xf), phy->LinkRate);
395 mps_print_field(sc, "PHY[%d].PhyStatus: %s\n",
396 phynum, mps_describe_table(mps_phystatus_names,
397 phy->PhyStatus));
398 }
399 break;
400 }
401 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
402 {
403 MPI2_EVENT_DATA_SAS_ENCL_DEV_STATUS_CHANGE *data;
404
405 data = (MPI2_EVENT_DATA_SAS_ENCL_DEV_STATUS_CHANGE *)
406 &event->EventData;
407 MPS_PRINTFIELD(sc, data, EnclosureHandle, 0x%x);
408 mps_print_field(sc, "ReasonCode: %s\n",
409 mps_describe_table(mps_sastopo_exp, data->ReasonCode));
410 MPS_PRINTFIELD(sc, data, PhysicalPort, %d);
411 MPS_PRINTFIELD(sc, data, NumSlots, %d);
412 MPS_PRINTFIELD(sc, data, StartSlot, %d);
413 MPS_PRINTFIELD(sc, data, PhyBits, 0x%x);
414 break;
415 }
416 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
417 {
418 MPI2_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *data;
419
420 data = (MPI2_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
421 &event->EventData;
422 MPS_PRINTFIELD(sc, data, TaskTag, 0x%x);
423 mps_print_field(sc, "ReasonCode: %s\n",
424 mps_describe_table(mps_sasdev_reason, data->ReasonCode));
425 MPS_PRINTFIELD(sc, data, ASC, 0x%x);
426 MPS_PRINTFIELD(sc, data, ASCQ, 0x%x);
427 MPS_PRINTFIELD(sc, data, DevHandle, 0x%x);
428 mps_print_field(sc, "SASAddress: 0x%jx\n",
429 mps_to_u64(&data->SASAddress));
430 break;
431 }
432 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
433 {
434 MPI2_EVENT_DATA_SAS_BROADCAST_PRIMITIVE *data;
435
436 data = (MPI2_EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)&event->EventData;
437 MPS_PRINTFIELD(sc, data, PhyNum, %d);
438 MPS_PRINTFIELD(sc, data, Port, %d);
439 MPS_PRINTFIELD(sc, data, PortWidth, %d);
440 MPS_PRINTFIELD(sc, data, Primitive, 0x%x);
441 break;
442 }
443 default:
444 break;
445 }
446 }
447
448 void
mps_print_expander1(struct mps_softc * sc,MPI2_CONFIG_PAGE_EXPANDER_1 * buf)449 mps_print_expander1(struct mps_softc *sc, MPI2_CONFIG_PAGE_EXPANDER_1 *buf)
450 {
451 MPS_PRINTFIELD_START(sc, "SAS Expander Page 1 #%d", buf->Phy);
452 MPS_PRINTFIELD(sc, buf, PhysicalPort, %d);
453 MPS_PRINTFIELD(sc, buf, NumPhys, %d);
454 MPS_PRINTFIELD(sc, buf, Phy, %d);
455 MPS_PRINTFIELD(sc, buf, NumTableEntriesProgrammed, %d);
456 mps_print_field(sc, "ProgrammedLinkRate: %s (0x%x)\n",
457 mps_describe_table(mps_linkrate_names,
458 (buf->ProgrammedLinkRate >> 4) & 0xf), buf->ProgrammedLinkRate);
459 mps_print_field(sc, "HwLinkRate: %s (0x%x)\n",
460 mps_describe_table(mps_linkrate_names,
461 (buf->HwLinkRate >> 4) & 0xf), buf->HwLinkRate);
462 MPS_PRINTFIELD(sc, buf, AttachedDevHandle, 0x%04x);
463 mps_print_field(sc, "PhyInfo Reason: %s (0x%x)\n",
464 mps_describe_table(mps_phyinfo_reason_names,
465 (buf->PhyInfo >> 16) & 0xf), buf->PhyInfo);
466 mps_print_field(sc, "AttachedDeviceInfo: %b,%s\n",
467 buf->AttachedDeviceInfo, "\20" "\4SATAhost" "\5SMPinit" "\6STPinit"
468 "\7SSPinit" "\10SATAdev" "\11SMPtarg" "\12STPtarg" "\13SSPtarg"
469 "\14Direct" "\15LSIdev" "\16ATAPIdev" "\17SEPdev",
470 mps_describe_table(mps_sasdev0_devtype,
471 buf->AttachedDeviceInfo & 0x03));
472 MPS_PRINTFIELD(sc, buf, ExpanderDevHandle, 0x%04x);
473 MPS_PRINTFIELD(sc, buf, ChangeCount, %d);
474 mps_print_field(sc, "NegotiatedLinkRate: %s (0x%x)\n",
475 mps_describe_table(mps_linkrate_names,
476 buf->NegotiatedLinkRate & 0xf), buf->NegotiatedLinkRate);
477 MPS_PRINTFIELD(sc, buf, PhyIdentifier, %d);
478 MPS_PRINTFIELD(sc, buf, AttachedPhyIdentifier, %d);
479 MPS_PRINTFIELD(sc, buf, DiscoveryInfo, 0x%x);
480 MPS_PRINTFIELD(sc, buf, AttachedPhyInfo, 0x%x);
481 mps_print_field(sc, "AttachedPhyInfo Reason: %s (0x%x)\n",
482 mps_describe_table(mps_phyinfo_reason_names,
483 buf->AttachedPhyInfo & 0xf), buf->AttachedPhyInfo);
484 MPS_PRINTFIELD(sc, buf, ZoneGroup, %d);
485 MPS_PRINTFIELD(sc, buf, SelfConfigStatus, 0x%x);
486 }
487
488 void
mps_print_sasphy0(struct mps_softc * sc,MPI2_CONFIG_PAGE_SAS_PHY_0 * buf)489 mps_print_sasphy0(struct mps_softc *sc, MPI2_CONFIG_PAGE_SAS_PHY_0 *buf)
490 {
491 MPS_PRINTFIELD_START(sc, "SAS PHY Page 0");
492 MPS_PRINTFIELD(sc, buf, OwnerDevHandle, 0x%04x);
493 MPS_PRINTFIELD(sc, buf, AttachedDevHandle, 0x%04x);
494 MPS_PRINTFIELD(sc, buf, AttachedPhyIdentifier, %d);
495 mps_print_field(sc, "AttachedPhyInfo Reason: %s (0x%x)\n",
496 mps_describe_table(mps_phyinfo_reason_names,
497 buf->AttachedPhyInfo & 0xf), buf->AttachedPhyInfo);
498 mps_print_field(sc, "ProgrammedLinkRate: %s (0x%x)\n",
499 mps_describe_table(mps_linkrate_names,
500 (buf->ProgrammedLinkRate >> 4) & 0xf), buf->ProgrammedLinkRate);
501 mps_print_field(sc, "HwLinkRate: %s (0x%x)\n",
502 mps_describe_table(mps_linkrate_names,
503 (buf->HwLinkRate >> 4) & 0xf), buf->HwLinkRate);
504 MPS_PRINTFIELD(sc, buf, ChangeCount, %d);
505 MPS_PRINTFIELD(sc, buf, Flags, 0x%x);
506 mps_print_field(sc, "PhyInfo Reason: %s (0x%x)\n",
507 mps_describe_table(mps_phyinfo_reason_names,
508 (buf->PhyInfo >> 16) & 0xf), buf->PhyInfo);
509 mps_print_field(sc, "NegotiatedLinkRate: %s (0x%x)\n",
510 mps_describe_table(mps_linkrate_names,
511 buf->NegotiatedLinkRate & 0xf), buf->NegotiatedLinkRate);
512 }
513
514 void
mps_print_sgl(struct mps_softc * sc,struct mps_command * cm,int offset)515 mps_print_sgl(struct mps_softc *sc, struct mps_command *cm, int offset)
516 {
517 MPI2_SGE_SIMPLE64 *sge;
518 MPI2_SGE_CHAIN32 *sgc;
519 struct mps_chain *chain = NULL;
520 char *frame;
521 u_int i = 0, flags;
522
523 frame = (char *)cm->cm_req;
524 sge = (MPI2_SGE_SIMPLE64 *)&frame[offset * 4];
525 printf("SGL for command %p\n", cm);
526
527 hexdump(frame, 128, NULL, 0);
528 while (frame != NULL) {
529 flags = le32toh(sge->FlagsLength) >> MPI2_SGE_FLAGS_SHIFT;
530 printf("seg%d flags=0x%02x len=0x%06x addr=0x%016jx\n",
531 i, flags, le32toh(sge->FlagsLength) & 0xffffff,
532 mps_to_u64(&sge->Address));
533 if (flags & (MPI2_SGE_FLAGS_END_OF_LIST |
534 MPI2_SGE_FLAGS_END_OF_BUFFER))
535 break;
536 sge++;
537 i++;
538 if (flags & MPI2_SGE_FLAGS_LAST_ELEMENT) {
539 sgc = (MPI2_SGE_CHAIN32 *)sge;
540 printf("chain flags=0x%x len=0x%x Offset=0x%x "
541 "Address=0x%x\n", sgc->Flags, le16toh(sgc->Length),
542 sgc->NextChainOffset, le32toh(sgc->Address));
543 if (chain == NULL)
544 chain = TAILQ_FIRST(&cm->cm_chain_list);
545 else
546 chain = TAILQ_NEXT(chain, chain_link);
547 frame = (char *)chain->chain;
548 sge = (MPI2_SGE_SIMPLE64 *)frame;
549 hexdump(frame, 128, NULL, 0);
550 }
551 }
552 }
553
554 void
mps_print_scsiio_cmd(struct mps_softc * sc,struct mps_command * cm)555 mps_print_scsiio_cmd(struct mps_softc *sc, struct mps_command *cm)
556 {
557 MPI2_SCSI_IO_REQUEST *req;
558
559 req = (MPI2_SCSI_IO_REQUEST *)cm->cm_req;
560 mps_print_sgl(sc, cm, req->SGLOffset0);
561 }
562