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: %d.%d\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: %02d.%02d.%02d.%02d\n",
250 facts->FWVersion.Struct.Major, facts->FWVersion.Struct.Minor,
251 facts->FWVersion.Struct.Unit, facts->FWVersion.Struct.Dev);
252 printf(" IOCRequestFrameSize: %d\n", facts->IOCRequestFrameSize);
253 printf(" MaxInitiators: %d\n", facts->MaxInitiators);
254 printf(" MaxTargets: %d\n", facts->MaxTargets);
255 printf(" MaxSasExpanders: %d\n", facts->MaxSasExpanders);
256 printf(" MaxEnclosures: %d\n", facts->MaxEnclosures);
258 bzero(tmpbuf, sizeof(tmpbuf));
259 mps_parse_flags(facts->ProtocolFlags,
260 "\4NvmeDevices\2ScsiTarget\1ScsiInitiator", tmpbuf, sizeof(tmpbuf));
261 printf(" ProtocolFlags: 0x%x %s\n", facts->ProtocolFlags, tmpbuf);
262 printf(" HighPriorityCredit: %d\n", facts->HighPriorityCredit);
263 printf("MaxRepDescPostQDepth: %d\n",
264 facts->MaxReplyDescriptorPostQueueDepth);
265 printf(" ReplyFrameSize: %d\n", facts->ReplyFrameSize);
266 printf(" MaxVolumes: %d\n", facts->MaxVolumes);
267 printf(" MaxDevHandle: %d\n", facts->MaxDevHandle);
268 printf("MaxPersistentEntries: %d\n", facts->MaxPersistentEntries);
269 printf(" MinDevHandle: %d\n", facts->MinDevHandle);
275 MPS_COMMAND(show, iocfacts, show_iocfacts, "", "Show IOC Facts Message");
278 show_adapters(int ac, char **av)
280 MPI2_CONFIG_PAGE_MAN_0 *man0;
281 MPI2_IOC_FACTS_REPLY *facts;
284 printf("Device Name\t Chip Name Board Name Firmware\n");
285 for (unit = 0; unit < MPS_MAX_UNIT; unit++) {
289 facts = mps_get_iocfacts(fd);
292 warn("Faled to get controller iocfacts");
296 man0 = mps_read_man_page(fd, 0, NULL);
299 warn("Failed to get controller info");
304 if (man0->Header.PageLength < sizeof(*man0) / 4) {
305 warnx("Invalid controller info");
311 printf("/dev/mp%s%d\t%16s %16s %08x\n",
312 is_mps ? "s": "r", unit,
313 man0->ChipName, man0->BoardName, facts->FWVersion.Word);
320 MPS_COMMAND(show, adapters, show_adapters, "", "Show a summary of all adapters");
323 get_device_type(uint32_t di)
327 return ("SEP Target ");
329 return ("ATAPI Target ");
331 return ("SAS Target ");
333 return ("STP Target ");
335 return ("SMP Target ");
337 return ("SATA Target ");
339 return ("SAS Initiator ");
341 return ("SATA Initiator");
343 return ("No Device ");
344 return ("Unknown Device");
348 get_enc_type(uint32_t flags, int *issep)
353 switch (flags & 0xf) {
355 type = "Direct Attached SES-2";
359 type = "Direct Attached SGPIO";
362 type = "Expander SGPIO";
365 type = "External SES-2";
369 type = "Direct Attached GPIO";
380 mps_device_speed[] = {
396 get_device_speed(uint8_t rate)
401 if (rate >= sizeof(mps_device_speed))
404 if ((speed = mps_device_speed[rate]) == NULL)
421 "RAID Physical Disk",
433 "RAID Configuration",
434 "Driver Persistent Mapping",
437 "Extended Manufacturing"
441 get_page_name(u_int page)
445 if (page >= sizeof(mps_page_name))
447 if ((name = mps_page_name[page]) == NULL)
453 show_all(int ac, char **av)
457 printf("Adapter:\n");
458 error = show_adapter(ac, av);
459 printf("Devices:\n");
460 error = show_devices(ac, av);
461 printf("Enclosures:\n");
462 error = show_enclosures(ac, av);
463 printf("Expanders:\n");
464 error = show_expanders(ac, av);
467 MPS_COMMAND(show, all, show_all, "", "Show all devices");
470 show_devices(int ac, char **av)
472 MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0;
473 MPI2_SAS_IO_UNIT0_PHY_DATA *phydata;
474 MPI2_CONFIG_PAGE_SAS_DEV_0 *device;
475 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
476 uint16_t IOCStatus, handle, bus, target;
477 char *type, *speed, enchandle[5], slot[3], bt[8];
479 int fd, error, nphys;
481 fd = mps_open(mps_unit);
488 sas0 = mps_read_extended_config_page(fd,
489 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
490 MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus);
493 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
496 nphys = sas0->NumPhys;
498 printf("B____%-5s%-17s%-8s%-10s%-14s%-6s%-5s%-6s%s\n",
499 "T", "SAS Address", "Handle", "Parent", "Device", "Speed",
500 "Enc", "Slot", "Wdt");
503 device = mps_read_extended_config_page(fd,
504 MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE,
505 MPI2_SASDEVICE0_PAGEVERSION, 0,
506 MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE | handle,
508 if (device == NULL) {
509 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
512 warn("Error retrieving device page");
516 handle = device->DevHandle;
518 if (device->ParentDevHandle == 0x0) {
525 error = mps_map_btdh(fd, &handle, &bus, &target);
530 if ((bus == 0xffff) || (target == 0xffff))
531 snprintf(bt, sizeof(bt), " ");
533 snprintf(bt, sizeof(bt), "%02d %02d", bus, target);
535 type = get_device_type(device->DeviceInfo);
537 if (device->PhyNum < nphys) {
538 phydata = &sas0->PhyData[device->PhyNum];
539 speed = get_device_speed(phydata->NegotiatedLinkRate);
540 } else if (device->ParentDevHandle > 0) {
541 exp1 = mps_read_extended_config_page(fd,
542 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
543 MPI2_SASEXPANDER1_PAGEVERSION, 1,
544 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
546 MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
547 device->ParentDevHandle, &IOCStatus);
549 if (IOCStatus != MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) {
551 warn("Error retrieving expander page 1: 0x%x",
559 speed = get_device_speed(exp1->NegotiatedLinkRate);
565 if (device->EnclosureHandle != 0) {
566 snprintf(enchandle, 5, "%04x", device->EnclosureHandle);
567 snprintf(slot, 3, "%02d", device->Slot);
569 snprintf(enchandle, 5, " ");
570 snprintf(slot, 3, " ");
573 snprintf(buf, sizeof(buf), "%08x%08x", device->SASAddress.High,
574 device->SASAddress.Low);
575 printf("%-17s", buf);
576 snprintf(buf, sizeof(buf), "%04x", device->DevHandle);
578 snprintf(buf, sizeof(buf), "%04x", device->ParentDevHandle);
579 printf("%-10s", buf);
580 printf("%-14s%-6s%-5s%-6s%d\n", type, speed,
581 enchandle, slot, device->MaxPortConnections);
589 MPS_COMMAND(show, devices, show_devices, "", "Show attached devices");
592 show_enclosures(int ac, char **av)
594 MPI2_CONFIG_PAGE_SAS_ENCLOSURE_0 *enc;
595 char *type, sepstr[5];
596 uint16_t IOCStatus, handle;
597 int fd, error, issep;
599 fd = mps_open(mps_unit);
606 printf("Slots Logical ID SEPHandle EncHandle Type\n");
609 enc = mps_read_extended_config_page(fd,
610 MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE,
611 MPI2_SASENCLOSURE0_PAGEVERSION, 0,
612 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE | handle,
615 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
618 warn("Error retrieving enclosure page");
622 type = get_enc_type(enc->Flags, &issep);
624 snprintf(sepstr, 5, " ");
626 snprintf(sepstr, 5, "%04x", enc->SEPDevHandle);
627 printf(" %.2d %08x%08x %s %04x %s\n",
628 enc->NumSlots, enc->EnclosureLogicalID.High,
629 enc->EnclosureLogicalID.Low, sepstr, enc->EnclosureHandle,
631 handle = enc->EnclosureHandle;
638 MPS_COMMAND(show, enclosures, show_enclosures, "", "Show attached enclosures");
641 show_expanders(int ac, char **av)
643 MPI2_CONFIG_PAGE_EXPANDER_0 *exp0;
644 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
645 uint16_t IOCStatus, handle;
646 char enchandle[5], parent[5], rphy[3], rhandle[5];
647 char *speed, *min, *max, *type;
648 int fd, error, nphys, i;
650 fd = mps_open(mps_unit);
657 printf("NumPhys SAS Address DevHandle Parent EncHandle SAS Level\n");
660 exp0 = mps_read_extended_config_page(fd,
661 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
662 MPI2_SASEXPANDER0_PAGEVERSION, 0,
663 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL | handle,
666 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
669 warn("Error retrieving expander page 0");
674 nphys = exp0->NumPhys;
675 handle = exp0->DevHandle;
677 if (exp0->EnclosureHandle == 0x00)
678 snprintf(enchandle, 5, " ");
680 snprintf(enchandle, 5, "%04d", exp0->EnclosureHandle);
681 if (exp0->ParentDevHandle == 0x0)
682 snprintf(parent, 5, " ");
684 snprintf(parent, 5, "%04x", exp0->ParentDevHandle);
685 printf(" %02d %08x%08x %04x %s %s %d\n",
686 exp0->NumPhys, exp0->SASAddress.High, exp0->SASAddress.Low,
687 exp0->DevHandle, parent, enchandle, exp0->SASLevel);
690 printf(" Phy RemotePhy DevHandle Speed Min Max Device\n");
691 for (i = 0; i < nphys; i++) {
692 exp1 = mps_read_extended_config_page(fd,
693 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
694 MPI2_SASEXPANDER1_PAGEVERSION, 1,
695 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
696 (i << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
697 exp0->DevHandle, &IOCStatus);
700 MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
701 warn("Error retrieving expander pg 1");
704 type = get_device_type(exp1->AttachedDeviceInfo);
705 if ((exp1->AttachedDeviceInfo &0x7) == 0) {
707 snprintf(rphy, 3, " ");
708 snprintf(rhandle, 5, " ");
710 speed = get_device_speed(
711 exp1->NegotiatedLinkRate);
712 snprintf(rphy, 3, "%02d",
713 exp1->AttachedPhyIdentifier);
714 snprintf(rhandle, 5, "%04x",
715 exp1->AttachedDevHandle);
717 min = get_device_speed(exp1->HwLinkRate);
718 max = get_device_speed(exp1->HwLinkRate >> 4);
719 printf(" %02d %s %s %s %s %s %s\n", exp1->Phy, rphy, rhandle, speed, min, max, type);
731 MPS_COMMAND(show, expanders, show_expanders, "", "Show attached expanders");
734 show_cfgpage(int ac, char **av)
736 MPI2_CONFIG_PAGE_HEADER *hdr;
737 MPI2_CONFIG_EXTENDED_PAGE_HEADER *ehdr;
742 int fd, error, len, attrs;
743 char *pgname, *pgattr;
745 fd = mps_open(mps_unit);
758 addr = (uint32_t)strtoul(av[3], NULL, 0);
760 num = (uint8_t)strtoul(av[2], NULL, 0);
762 page = (uint8_t)strtoul(av[1], NULL, 0);
766 warn("cfgpage: not enough arguments");
771 data = mps_read_extended_config_page(fd, page, 0, num, addr,
774 data = mps_read_config_page(fd, page, num, addr, &IOCStatus);
778 warn("Error retrieving cfg page: %s\n",
779 mps_ioc_status(IOCStatus));
785 len = ehdr->ExtPageLength * 4;
786 page = ehdr->ExtPageType;
787 attrs = ehdr->PageType >> 4;
790 len = hdr->PageLength * 4;
791 page = hdr->PageType & 0xf;
792 attrs = hdr->PageType >> 4;
795 pgname = get_page_name(page);
797 pgattr = "Read-only";
799 pgattr = "Read-Write";
801 pgattr = "Read-Write Persistent";
803 pgattr = "Unknown Page Attribute";
805 printf("Page 0x%x: %s %d, %s\n", page, pgname, num, pgattr);
806 hexdump(data, len, NULL, HD_REVERSED | 4);
812 MPS_COMMAND(show, cfgpage, show_cfgpage, "page [num] [addr]", "Display config page");