2 * Copyright (c) 2015 Netflix, Inc.
3 * Written by: Scott Long <scottl@freebsd.org>
5 * Copyright (c) 2008 Yahoo!, Inc.
7 * Written by: John Baldwin <jhb@FreeBSD.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the author nor the names of any co-contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
37 #include <sys/param.h>
38 #include <sys/errno.h>
47 static char * get_device_speed(uint8_t rate);
48 static char * get_device_type(uint32_t di);
49 static int show_all(int ac, char **av);
50 static int show_devices(int ac, char **av);
51 static int show_enclosures(int ac, char **av);
52 static int show_expanders(int ac, char **av);
56 #define STANDALONE_STATE "ONLINE"
59 show_adapter(int ac, char **av)
61 MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0;
62 MPI2_CONFIG_PAGE_SASIOUNIT_1 *sas1;
63 MPI2_SAS_IO_UNIT0_PHY_DATA *phy0;
64 MPI2_SAS_IO_UNIT1_PHY_DATA *phy1;
65 MPI2_CONFIG_PAGE_MAN_0 *man0;
66 MPI2_CONFIG_PAGE_BIOS_3 *bios3;
67 MPI2_IOC_FACTS_REPLY *facts;
69 char *speed, *minspeed, *maxspeed, *isdisabled, *type;
70 char devhandle[5], ctrlhandle[5];
74 warnx("show adapter: extra arguments");
78 fd = mps_open(mps_unit);
85 man0 = mps_read_man_page(fd, 0, NULL);
88 warn("Failed to get controller info");
91 if (man0->Header.PageLength < sizeof(*man0) / 4) {
92 warnx("Invalid controller info");
95 printf("mp%s%d Adapter:\n", is_mps ? "s": "r", mps_unit);
96 printf(" Board Name: %.16s\n", man0->BoardName);
97 printf(" Board Assembly: %.16s\n", man0->BoardAssembly);
98 printf(" Chip Name: %.16s\n", man0->ChipName);
99 printf(" Chip Revision: %.16s\n", man0->ChipRevision);
102 bios3 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_BIOS, 3, 0, NULL);
105 warn("Failed to get BIOS page 3 info");
108 v = bios3->BiosVersion;
109 printf(" BIOS Revision: %d.%02d.%02d.%02d\n",
110 ((v & 0xff000000) >> 24), ((v &0xff0000) >> 16),
111 ((v & 0xff00) >> 8), (v & 0xff));
114 if ((facts = mps_get_iocfacts(fd)) == NULL) {
115 printf("could not get controller IOCFacts\n");
119 v = facts->FWVersion.Word;
120 printf("Firmware Revision: %d.%02d.%02d.%02d\n",
121 ((v & 0xff000000) >> 24), ((v &0xff0000) >> 16),
122 ((v & 0xff00) >> 8), (v & 0xff));
123 printf(" Integrated RAID: %s\n",
124 (facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID)
128 fd = mps_open(mps_unit);
135 sas0 = mps_read_extended_config_page(fd,
136 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
137 MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus);
140 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
146 sas1 = mps_read_extended_config_page(fd,
147 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
148 MPI2_SASIOUNITPAGE1_PAGEVERSION, 1, 0, &IOCStatus);
151 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
158 printf("%-8s%-12s%-11s%-10s%-8s%-7s%-7s%s\n", "PhyNum", "CtlrHandle",
159 "DevHandle", "Disabled", "Speed", "Min", "Max", "Device");
160 for (i = 0; i < sas0->NumPhys; i++) {
161 phy0 = &sas0->PhyData[i];
162 phy1 = &sas1->PhyData[i];
163 if (phy0->PortFlags &
164 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) {
165 printf("Discovery still in progress\n");
168 if (phy0->PhyFlags & MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED)
173 minspeed = get_device_speed(phy1->MaxMinLinkRate);
174 maxspeed = get_device_speed(phy1->MaxMinLinkRate >> 4);
175 type = get_device_type(phy0->ControllerPhyDeviceInfo);
177 if (phy0->AttachedDevHandle != 0) {
178 snprintf(devhandle, 5, "%04x", phy0->AttachedDevHandle);
179 snprintf(ctrlhandle, 5, "%04x",
180 phy0->ControllerDevHandle);
181 speed = get_device_speed(phy0->NegotiatedLinkRate);
183 snprintf(devhandle, 5, " ");
184 snprintf(ctrlhandle, 5, " ");
187 printf("%-8d%-12s%-11s%-10s%-8s%-7s%-7s%s\n",
188 i, ctrlhandle, devhandle, isdisabled, speed, minspeed,
198 MPS_COMMAND(show, adapter, show_adapter, "", "display controller information")
201 show_iocfacts(int ac, char **av)
203 MPI2_IOC_FACTS_REPLY *facts;
207 fd = mps_open(mps_unit);
214 if ((facts = mps_get_iocfacts(fd)) == NULL) {
215 printf("could not get controller IOCFacts\n");
220 #define IOCCAP "\3ScsiTaskFull" "\4DiagTrace" "\5SnapBuf" "\6ExtBuf" \
221 "\7EEDP" "\10BiDirTarg" "\11Multicast" "\14TransRetry" "\15IR" \
222 "\16EventReplay" "\17RaidAccel" "\20MSIXIndex" "\21HostDisc" \
223 "\22FastPath" "\23RDPQArray" "\24AtomicReqDesc" "\25PCIeSRIOV"
225 bzero(tmpbuf, sizeof(tmpbuf));
226 mps_parse_flags(facts->IOCCapabilities, IOCCAP, tmpbuf, sizeof(tmpbuf));
228 printf(" MsgVersion: %02d.%02d\n",
229 facts->MsgVersion >> 8, facts->MsgVersion & 0xff);
230 printf(" MsgLength: %d\n", facts->MsgLength);
231 printf(" Function: 0x%x\n", facts->Function);
232 printf(" HeaderVersion: %02d,%02d\n",
233 facts->HeaderVersion >> 8, facts->HeaderVersion & 0xff);
234 printf(" IOCNumber: %d\n", facts->IOCNumber);
235 printf(" MsgFlags: 0x%x\n", facts->MsgFlags);
236 printf(" VP_ID: %d\n", facts->VP_ID);
237 printf(" VF_ID: %d\n", facts->VF_ID);
238 printf(" IOCExceptions: %d\n", facts->IOCExceptions);
239 printf(" IOCStatus: %d\n", facts->IOCStatus);
240 printf(" IOCLogInfo: 0x%x\n", facts->IOCLogInfo);
241 printf(" MaxChainDepth: %d\n", facts->MaxChainDepth);
242 printf(" WhoInit: 0x%x\n", facts->WhoInit);
243 printf(" NumberOfPorts: %d\n", facts->NumberOfPorts);
244 printf(" MaxMSIxVectors: %d\n", facts->MaxMSIxVectors);
245 printf(" RequestCredit: %d\n", facts->RequestCredit);
246 printf(" ProductID: 0x%x\n", facts->ProductID);
247 printf(" IOCCapabilities: 0x%x %s\n", facts->IOCCapabilities,
249 printf(" FWVersion: 0x%08x\n", facts->FWVersion.Word);
250 printf(" IOCRequestFrameSize: %d\n", facts->IOCRequestFrameSize);
251 printf(" MaxInitiators: %d\n", facts->MaxInitiators);
252 printf(" MaxTargets: %d\n", facts->MaxTargets);
253 printf(" MaxSasExpanders: %d\n", facts->MaxSasExpanders);
254 printf(" MaxEnclosures: %d\n", facts->MaxEnclosures);
256 bzero(tmpbuf, sizeof(tmpbuf));
257 mps_parse_flags(facts->ProtocolFlags,
258 "\4NvmeDevices\2ScsiTarget\1ScsiInitiator", tmpbuf, sizeof(tmpbuf));
259 printf(" ProtocolFlags: 0x%x %s\n", facts->ProtocolFlags, tmpbuf);
260 printf(" HighPriorityCredit: %d\n", facts->HighPriorityCredit);
261 printf("MaxRepDescPostQDepth: %d\n",
262 facts->MaxReplyDescriptorPostQueueDepth);
263 printf(" ReplyFrameSize: %d\n", facts->ReplyFrameSize);
264 printf(" MaxVolumes: %d\n", facts->MaxVolumes);
265 printf(" MaxDevHandle: %d\n", facts->MaxDevHandle);
266 printf("MaxPersistentEntries: %d\n", facts->MaxPersistentEntries);
267 printf(" MinDevHandle: %d\n", facts->MinDevHandle);
273 MPS_COMMAND(show, iocfacts, show_iocfacts, "", "Show IOC Facts Message");
276 show_adapters(int ac, char **av)
278 MPI2_CONFIG_PAGE_MAN_0 *man0;
279 MPI2_IOC_FACTS_REPLY *facts;
282 printf("Device Name\t Chip Name Board Name Firmware\n");
283 for (unit = 0; unit < MPS_MAX_UNIT; unit++) {
287 facts = mps_get_iocfacts(fd);
290 warn("Faled to get controller iocfacts");
294 man0 = mps_read_man_page(fd, 0, NULL);
297 warn("Failed to get controller info");
302 if (man0->Header.PageLength < sizeof(*man0) / 4) {
303 warnx("Invalid controller info");
309 printf("/dev/mp%s%d\t%16s %16s %08x\n",
310 is_mps ? "s": "r", unit,
311 man0->ChipName, man0->BoardName, facts->FWVersion.Word);
318 MPS_COMMAND(show, adapters, show_adapters, "", "Show a summary of all adapters");
321 get_device_type(uint32_t di)
325 return ("SEP Target ");
327 return ("ATAPI Target ");
329 return ("SAS Target ");
331 return ("STP Target ");
333 return ("SMP Target ");
335 return ("SATA Target ");
337 return ("SAS Initiator ");
339 return ("SATA Initiator");
341 return ("No Device ");
342 return ("Unknown Device");
346 get_enc_type(uint32_t flags, int *issep)
351 switch (flags & 0xf) {
353 type = "Direct Attached SES-2";
357 type = "Direct Attached SGPIO";
360 type = "Expander SGPIO";
363 type = "External SES-2";
367 type = "Direct Attached GPIO";
378 mps_device_speed[] = {
394 get_device_speed(uint8_t rate)
399 if (rate >= sizeof(mps_device_speed))
402 if ((speed = mps_device_speed[rate]) == NULL)
419 "RAID Physical Disk",
431 "RAID Configuration",
432 "Driver Persistent Mapping",
435 "Extended Manufacturing"
439 get_page_name(u_int page)
443 if (page >= sizeof(mps_page_name))
445 if ((name = mps_page_name[page]) == NULL)
451 show_all(int ac, char **av)
455 printf("Adapter:\n");
456 error = show_adapter(ac, av);
457 printf("Devices:\n");
458 error = show_devices(ac, av);
459 printf("Enclosures:\n");
460 error = show_enclosures(ac, av);
461 printf("Expanders:\n");
462 error = show_expanders(ac, av);
465 MPS_COMMAND(show, all, show_all, "", "Show all devices");
468 show_devices(int ac, char **av)
470 MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0;
471 MPI2_SAS_IO_UNIT0_PHY_DATA *phydata;
472 MPI2_CONFIG_PAGE_SAS_DEV_0 *device;
473 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
474 uint16_t IOCStatus, handle, bus, target;
475 char *type, *speed, enchandle[5], slot[3], bt[8];
477 int fd, error, nphys;
479 fd = mps_open(mps_unit);
486 sas0 = mps_read_extended_config_page(fd,
487 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
488 MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus);
491 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
494 nphys = sas0->NumPhys;
496 printf("B____%-5s%-17s%-8s%-10s%-14s%-6s%-5s%-6s%s\n",
497 "T", "SAS Address", "Handle", "Parent", "Device", "Speed",
498 "Enc", "Slot", "Wdt");
501 device = mps_read_extended_config_page(fd,
502 MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE,
503 MPI2_SASDEVICE0_PAGEVERSION, 0,
504 MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE | handle,
506 if (device == NULL) {
507 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
510 warn("Error retrieving device page");
514 handle = device->DevHandle;
516 if (device->ParentDevHandle == 0x0) {
523 error = mps_map_btdh(fd, &handle, &bus, &target);
528 if ((bus == 0xffff) || (target == 0xffff))
529 snprintf(bt, sizeof(bt), " ");
531 snprintf(bt, sizeof(bt), "%02d %02d", bus, target);
533 type = get_device_type(device->DeviceInfo);
535 if (device->PhyNum < nphys) {
536 phydata = &sas0->PhyData[device->PhyNum];
537 speed = get_device_speed(phydata->NegotiatedLinkRate);
538 } else if (device->ParentDevHandle > 0) {
539 exp1 = mps_read_extended_config_page(fd,
540 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
541 MPI2_SASEXPANDER1_PAGEVERSION, 1,
542 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
544 MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
545 device->ParentDevHandle, &IOCStatus);
547 if (IOCStatus != MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) {
549 warn("Error retrieving expander page 1: 0x%x",
557 speed = get_device_speed(exp1->NegotiatedLinkRate);
563 if (device->EnclosureHandle != 0) {
564 snprintf(enchandle, 5, "%04x", device->EnclosureHandle);
565 snprintf(slot, 3, "%02d", device->Slot);
567 snprintf(enchandle, 5, " ");
568 snprintf(slot, 3, " ");
571 snprintf(buf, sizeof(buf), "%08x%08x", device->SASAddress.High,
572 device->SASAddress.Low);
573 printf("%-17s", buf);
574 snprintf(buf, sizeof(buf), "%04x", device->DevHandle);
576 snprintf(buf, sizeof(buf), "%04x", device->ParentDevHandle);
577 printf("%-10s", buf);
578 printf("%-14s%-6s%-5s%-6s%d\n", type, speed,
579 enchandle, slot, device->MaxPortConnections);
587 MPS_COMMAND(show, devices, show_devices, "", "Show attached devices");
590 show_enclosures(int ac, char **av)
592 MPI2_CONFIG_PAGE_SAS_ENCLOSURE_0 *enc;
593 char *type, sepstr[5];
594 uint16_t IOCStatus, handle;
595 int fd, error, issep;
597 fd = mps_open(mps_unit);
604 printf("Slots Logical ID SEPHandle EncHandle Type\n");
607 enc = mps_read_extended_config_page(fd,
608 MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE,
609 MPI2_SASENCLOSURE0_PAGEVERSION, 0,
610 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE | handle,
613 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
616 warn("Error retrieving enclosure page");
620 type = get_enc_type(enc->Flags, &issep);
622 snprintf(sepstr, 5, " ");
624 snprintf(sepstr, 5, "%04x", enc->SEPDevHandle);
625 printf(" %.2d %08x%08x %s %04x %s\n",
626 enc->NumSlots, enc->EnclosureLogicalID.High,
627 enc->EnclosureLogicalID.Low, sepstr, enc->EnclosureHandle,
629 handle = enc->EnclosureHandle;
636 MPS_COMMAND(show, enclosures, show_enclosures, "", "Show attached enclosures");
639 show_expanders(int ac, char **av)
641 MPI2_CONFIG_PAGE_EXPANDER_0 *exp0;
642 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
643 uint16_t IOCStatus, handle;
644 char enchandle[5], parent[5], rphy[3], rhandle[5];
645 char *speed, *min, *max, *type;
646 int fd, error, nphys, i;
648 fd = mps_open(mps_unit);
655 printf("NumPhys SAS Address DevHandle Parent EncHandle SAS Level\n");
658 exp0 = mps_read_extended_config_page(fd,
659 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
660 MPI2_SASEXPANDER0_PAGEVERSION, 0,
661 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL | handle,
664 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
667 warn("Error retrieving expander page 0");
672 nphys = exp0->NumPhys;
673 handle = exp0->DevHandle;
675 if (exp0->EnclosureHandle == 0x00)
676 snprintf(enchandle, 5, " ");
678 snprintf(enchandle, 5, "%04d", exp0->EnclosureHandle);
679 if (exp0->ParentDevHandle == 0x0)
680 snprintf(parent, 5, " ");
682 snprintf(parent, 5, "%04x", exp0->ParentDevHandle);
683 printf(" %02d %08x%08x %04x %s %s %d\n",
684 exp0->NumPhys, exp0->SASAddress.High, exp0->SASAddress.Low,
685 exp0->DevHandle, parent, enchandle, exp0->SASLevel);
688 printf(" Phy RemotePhy DevHandle Speed Min Max Device\n");
689 for (i = 0; i < nphys; i++) {
690 exp1 = mps_read_extended_config_page(fd,
691 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
692 MPI2_SASEXPANDER1_PAGEVERSION, 1,
693 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
694 (i << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
695 exp0->DevHandle, &IOCStatus);
698 MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
699 warn("Error retrieving expander pg 1");
702 type = get_device_type(exp1->AttachedDeviceInfo);
703 if ((exp1->AttachedDeviceInfo &0x7) == 0) {
705 snprintf(rphy, 3, " ");
706 snprintf(rhandle, 5, " ");
708 speed = get_device_speed(
709 exp1->NegotiatedLinkRate);
710 snprintf(rphy, 3, "%02d",
711 exp1->AttachedPhyIdentifier);
712 snprintf(rhandle, 5, "%04x",
713 exp1->AttachedDevHandle);
715 min = get_device_speed(exp1->HwLinkRate);
716 max = get_device_speed(exp1->HwLinkRate >> 4);
717 printf(" %02d %s %s %s %s %s %s\n", exp1->Phy, rphy, rhandle, speed, min, max, type);
729 MPS_COMMAND(show, expanders, show_expanders, "", "Show attached expanders");
732 show_cfgpage(int ac, char **av)
734 MPI2_CONFIG_PAGE_HEADER *hdr;
735 MPI2_CONFIG_EXTENDED_PAGE_HEADER *ehdr;
740 int fd, error, len, attrs;
741 char *pgname, *pgattr;
743 fd = mps_open(mps_unit);
756 addr = (uint32_t)strtoul(av[3], NULL, 0);
758 num = (uint8_t)strtoul(av[2], NULL, 0);
760 page = (uint8_t)strtoul(av[1], NULL, 0);
764 warn("cfgpage: not enough arguments");
769 data = mps_read_extended_config_page(fd, page, 0, num, addr,
772 data = mps_read_config_page(fd, page, num, addr, &IOCStatus);
776 warn("Error retrieving cfg page: %s\n",
777 mps_ioc_status(IOCStatus));
783 len = ehdr->ExtPageLength * 4;
784 page = ehdr->ExtPageType;
785 attrs = ehdr->PageType >> 4;
788 len = hdr->PageLength * 4;
789 page = hdr->PageType & 0xf;
790 attrs = hdr->PageType >> 4;
793 pgname = get_page_name(page);
795 pgattr = "Read-only";
797 pgattr = "Read-Write";
799 pgattr = "Read-Write Persistent";
801 pgattr = "Unknown Page Attribute";
803 printf("Page 0x%x: %s %d, %s\n", page, pgname, num, pgattr);
804 hexdump(data, len, NULL, HD_REVERSED | 4);
810 MPS_COMMAND(show, cfgpage, show_cfgpage, "page [num] [addr]", "Display config page");