2 * Copyright (c) 2015 Netflix, Inc.
4 * Written by: Scott Long <scottl@freebsd.org>
6 * Copyright (c) 2008 Yahoo!, Inc.
8 * Written by: John Baldwin <jhb@FreeBSD.org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 #include <sys/param.h>
39 #include <sys/errno.h>
48 static char * get_device_speed(uint8_t rate);
49 static char * get_device_type(uint32_t di);
50 static int show_all(int ac, char **av);
51 static int show_devices(int ac, char **av);
52 static int show_enclosures(int ac, char **av);
53 static int show_expanders(int ac, char **av);
57 #define STANDALONE_STATE "ONLINE"
60 show_adapter(int ac, char **av)
62 MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0;
63 MPI2_CONFIG_PAGE_SASIOUNIT_1 *sas1;
64 MPI2_SAS_IO_UNIT0_PHY_DATA *phy0;
65 MPI2_SAS_IO_UNIT1_PHY_DATA *phy1;
66 MPI2_CONFIG_PAGE_MAN_0 *man0;
67 MPI2_CONFIG_PAGE_BIOS_3 *bios3;
68 MPI2_IOC_FACTS_REPLY *facts;
70 char *speed, *minspeed, *maxspeed, *isdisabled, *type;
71 char devhandle[5], ctrlhandle[5];
75 warnx("show adapter: extra arguments");
79 fd = mps_open(mps_unit);
86 man0 = mps_read_man_page(fd, 0, NULL);
89 warn("Failed to get controller info");
92 if (man0->Header.PageLength < sizeof(*man0) / 4) {
93 warnx("Invalid controller info");
96 printf("mp%s%d Adapter:\n", is_mps ? "s": "r", mps_unit);
97 printf(" Board Name: %.16s\n", man0->BoardName);
98 printf(" Board Assembly: %.16s\n", man0->BoardAssembly);
99 printf(" Chip Name: %.16s\n", man0->ChipName);
100 printf(" Chip Revision: %.16s\n", man0->ChipRevision);
103 bios3 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_BIOS, 3, 0, NULL);
106 warn("Failed to get BIOS page 3 info");
109 v = bios3->BiosVersion;
110 printf(" BIOS Revision: %d.%02d.%02d.%02d\n",
111 ((v & 0xff000000) >> 24), ((v &0xff0000) >> 16),
112 ((v & 0xff00) >> 8), (v & 0xff));
115 if ((facts = mps_get_iocfacts(fd)) == NULL) {
116 printf("could not get controller IOCFacts\n");
120 v = facts->FWVersion.Word;
121 printf("Firmware Revision: %d.%02d.%02d.%02d\n",
122 ((v & 0xff000000) >> 24), ((v &0xff0000) >> 16),
123 ((v & 0xff00) >> 8), (v & 0xff));
124 printf(" Integrated RAID: %s\n",
125 (facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID)
129 fd = mps_open(mps_unit);
136 sas0 = mps_read_extended_config_page(fd,
137 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
138 MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus);
141 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
147 sas1 = mps_read_extended_config_page(fd,
148 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
149 MPI2_SASIOUNITPAGE1_PAGEVERSION, 1, 0, &IOCStatus);
152 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
159 printf("%-8s%-12s%-11s%-10s%-8s%-7s%-7s%s\n", "PhyNum", "CtlrHandle",
160 "DevHandle", "Disabled", "Speed", "Min", "Max", "Device");
161 for (i = 0; i < sas0->NumPhys; i++) {
162 phy0 = &sas0->PhyData[i];
163 phy1 = &sas1->PhyData[i];
164 if (phy0->PortFlags &
165 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) {
166 printf("Discovery still in progress\n");
169 if (phy0->PhyFlags & MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED)
174 minspeed = get_device_speed(phy1->MaxMinLinkRate);
175 maxspeed = get_device_speed(phy1->MaxMinLinkRate >> 4);
176 type = get_device_type(phy0->ControllerPhyDeviceInfo);
178 if (phy0->AttachedDevHandle != 0) {
179 snprintf(devhandle, 5, "%04x", phy0->AttachedDevHandle);
180 snprintf(ctrlhandle, 5, "%04x",
181 phy0->ControllerDevHandle);
182 speed = get_device_speed(phy0->NegotiatedLinkRate);
184 snprintf(devhandle, 5, " ");
185 snprintf(ctrlhandle, 5, " ");
188 printf("%-8d%-12s%-11s%-10s%-8s%-7s%-7s%s\n",
189 i, ctrlhandle, devhandle, isdisabled, speed, minspeed,
199 MPS_COMMAND(show, adapter, show_adapter, "", "display controller information")
202 show_iocfacts(int ac, char **av)
204 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 printf(" MaxChainDepth: %d\n", facts->MaxChainDepth);
221 printf(" WhoInit: 0x%x\n", facts->WhoInit);
222 printf(" NumberOfPorts: %d\n", facts->NumberOfPorts);
223 printf(" MaxMSIxVectors: %d\n", facts->MaxMSIxVectors);
224 printf(" RequestCredit: %d\n", facts->RequestCredit);
225 printf(" ProductID: 0x%x\n", facts->ProductID);
226 printf(" IOCCapabilities: 0x%x\n", facts->IOCCapabilities);
227 printf(" FWVersion: 0x%08x\n", facts->FWVersion.Word);
228 printf(" IOCRequestFrameSize: %d\n", facts->IOCRequestFrameSize);
229 printf(" MaxInitiators: %d\n", facts->MaxInitiators);
230 printf(" MaxTargets: %d\n", facts->MaxTargets);
231 printf(" MaxSasExpanders: %d\n", facts->MaxSasExpanders);
232 printf(" MaxEnclosures: %d\n", facts->MaxEnclosures);
233 printf(" ProtocolFlags: 0x%x\n", facts->ProtocolFlags);
234 printf(" HighPriorityCredit: %d\n", facts->HighPriorityCredit);
235 printf("MaxRepDescPostQDepth: %d\n",
236 facts->MaxReplyDescriptorPostQueueDepth);
237 printf(" ReplyFrameSize: %d\n", facts->ReplyFrameSize);
238 printf(" MaxVolumes: %d\n", facts->MaxVolumes);
239 printf(" MaxDevHandle: %d\n", facts->MaxDevHandle);
240 printf("MaxPersistentEntries: %d\n", facts->MaxPersistentEntries);
241 printf(" MinDevHandle: %d\n", facts->MinDevHandle);
247 MPS_COMMAND(show, iocfacts, show_iocfacts, "", "Show IOC Facts Message");
250 show_adapters(int ac, char **av)
252 MPI2_CONFIG_PAGE_MAN_0 *man0;
253 MPI2_IOC_FACTS_REPLY *facts;
256 printf("Device Name\t Chip Name Board Name Firmware\n");
257 for (unit = 0; unit < MPS_MAX_UNIT; unit++) {
261 facts = mps_get_iocfacts(fd);
264 warn("Faled to get controller iocfacts");
268 man0 = mps_read_man_page(fd, 0, NULL);
271 warn("Failed to get controller info");
276 if (man0->Header.PageLength < sizeof(*man0) / 4) {
277 warnx("Invalid controller info");
283 printf("/dev/mp%s%d\t%16s %16s %08x\n",
284 is_mps ? "s": "r", unit,
285 man0->ChipName, man0->BoardName, facts->FWVersion.Word);
292 MPS_COMMAND(show, adapters, show_adapters, "", "Show a summary of all adapters");
295 get_device_type(uint32_t di)
299 return ("SEP Target ");
301 return ("ATAPI Target ");
303 return ("SAS Target ");
305 return ("STP Target ");
307 return ("SMP Target ");
309 return ("SATA Target ");
311 return ("SAS Initiator ");
313 return ("SATA Initiator");
315 return ("No Device ");
316 return ("Unknown Device");
320 get_enc_type(uint32_t flags, int *issep)
325 switch (flags & 0xf) {
327 type = "Direct Attached SES-2";
331 type = "Direct Attached SGPIO";
334 type = "Expander SGPIO";
337 type = "External SES-2";
341 type = "Direct Attached GPIO";
352 mps_device_speed[] = {
368 get_device_speed(uint8_t rate)
373 if (rate >= sizeof(mps_device_speed))
376 if ((speed = mps_device_speed[rate]) == NULL)
393 "RAID Physical Disk",
405 "RAID Configuration",
406 "Driver Persistent Mapping",
409 "Extended Manufacturing"
413 get_page_name(u_int page)
417 if (page >= sizeof(mps_page_name))
419 if ((name = mps_page_name[page]) == NULL)
425 show_all(int ac, char **av)
429 printf("Adapter:\n");
430 error = show_adapter(ac, av);
431 printf("Devices:\n");
432 error = show_devices(ac, av);
433 printf("Enclosures:\n");
434 error = show_enclosures(ac, av);
435 printf("Expanders:\n");
436 error = show_expanders(ac, av);
439 MPS_COMMAND(show, all, show_all, "", "Show all devices");
442 show_devices(int ac, char **av)
444 MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0;
445 MPI2_SAS_IO_UNIT0_PHY_DATA *phydata;
446 MPI2_CONFIG_PAGE_SAS_DEV_0 *device;
447 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
448 uint16_t IOCStatus, handle, bus, target;
449 char *type, *speed, enchandle[5], slot[3], bt[8];
451 int fd, error, nphys;
453 fd = mps_open(mps_unit);
460 sas0 = mps_read_extended_config_page(fd,
461 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
462 MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus);
465 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
468 nphys = sas0->NumPhys;
470 printf("B____%-5s%-17s%-8s%-10s%-14s%-6s%-5s%-6s%s\n",
471 "T", "SAS Address", "Handle", "Parent", "Device", "Speed",
472 "Enc", "Slot", "Wdt");
475 device = mps_read_extended_config_page(fd,
476 MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE,
477 MPI2_SASDEVICE0_PAGEVERSION, 0,
478 MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE | handle,
480 if (device == NULL) {
481 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
484 warn("Error retrieving device page");
488 handle = device->DevHandle;
490 if (device->ParentDevHandle == 0x0) {
497 error = mps_map_btdh(fd, &handle, &bus, &target);
502 if ((bus == 0xffff) || (target == 0xffff))
503 snprintf(bt, sizeof(bt), " ");
505 snprintf(bt, sizeof(bt), "%02d %02d", bus, target);
507 type = get_device_type(device->DeviceInfo);
509 if (device->PhyNum < nphys) {
510 phydata = &sas0->PhyData[device->PhyNum];
511 speed = get_device_speed(phydata->NegotiatedLinkRate);
512 } else if (device->ParentDevHandle > 0) {
513 exp1 = mps_read_extended_config_page(fd,
514 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
515 MPI2_SASEXPANDER1_PAGEVERSION, 1,
516 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
518 MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
519 device->ParentDevHandle, &IOCStatus);
521 if (IOCStatus != MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) {
523 warn("Error retrieving expander page 1: 0x%x",
531 speed = get_device_speed(exp1->NegotiatedLinkRate);
537 if (device->EnclosureHandle != 0) {
538 snprintf(enchandle, 5, "%04x", device->EnclosureHandle);
539 snprintf(slot, 3, "%02d", device->Slot);
541 snprintf(enchandle, 5, " ");
542 snprintf(slot, 3, " ");
545 snprintf(buf, sizeof(buf), "%08x%08x", device->SASAddress.High,
546 device->SASAddress.Low);
547 printf("%-17s", buf);
548 snprintf(buf, sizeof(buf), "%04x", device->DevHandle);
550 snprintf(buf, sizeof(buf), "%04x", device->ParentDevHandle);
551 printf("%-10s", buf);
552 printf("%-14s%-6s%-5s%-6s%d\n", type, speed,
553 enchandle, slot, device->MaxPortConnections);
561 MPS_COMMAND(show, devices, show_devices, "", "Show attached devices");
564 show_enclosures(int ac, char **av)
566 MPI2_CONFIG_PAGE_SAS_ENCLOSURE_0 *enc;
567 char *type, sepstr[5];
568 uint16_t IOCStatus, handle;
569 int fd, error, issep;
571 fd = mps_open(mps_unit);
578 printf("Slots Logical ID SEPHandle EncHandle Type\n");
581 enc = mps_read_extended_config_page(fd,
582 MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE,
583 MPI2_SASENCLOSURE0_PAGEVERSION, 0,
584 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE | handle,
587 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
590 warn("Error retrieving enclosure page");
594 type = get_enc_type(enc->Flags, &issep);
596 snprintf(sepstr, 5, " ");
598 snprintf(sepstr, 5, "%04x", enc->SEPDevHandle);
599 printf(" %.2d %08x%08x %s %04x %s\n",
600 enc->NumSlots, enc->EnclosureLogicalID.High,
601 enc->EnclosureLogicalID.Low, sepstr, enc->EnclosureHandle,
603 handle = enc->EnclosureHandle;
610 MPS_COMMAND(show, enclosures, show_enclosures, "", "Show attached enclosures");
613 show_expanders(int ac, char **av)
615 MPI2_CONFIG_PAGE_EXPANDER_0 *exp0;
616 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
617 uint16_t IOCStatus, handle;
618 char enchandle[5], parent[5], rphy[3], rhandle[5];
619 char *speed, *min, *max, *type;
620 int fd, error, nphys, i;
622 fd = mps_open(mps_unit);
629 printf("NumPhys SAS Address DevHandle Parent EncHandle SAS Level\n");
632 exp0 = mps_read_extended_config_page(fd,
633 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
634 MPI2_SASEXPANDER0_PAGEVERSION, 0,
635 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL | handle,
638 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
641 warn("Error retrieving expander page 0");
646 nphys = exp0->NumPhys;
647 handle = exp0->DevHandle;
649 if (exp0->EnclosureHandle == 0x00)
650 snprintf(enchandle, 5, " ");
652 snprintf(enchandle, 5, "%04d", exp0->EnclosureHandle);
653 if (exp0->ParentDevHandle == 0x0)
654 snprintf(parent, 5, " ");
656 snprintf(parent, 5, "%04x", exp0->ParentDevHandle);
657 printf(" %02d %08x%08x %04x %s %s %d\n",
658 exp0->NumPhys, exp0->SASAddress.High, exp0->SASAddress.Low,
659 exp0->DevHandle, parent, enchandle, exp0->SASLevel);
662 printf(" Phy RemotePhy DevHandle Speed Min Max Device\n");
663 for (i = 0; i < nphys; i++) {
664 exp1 = mps_read_extended_config_page(fd,
665 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
666 MPI2_SASEXPANDER1_PAGEVERSION, 1,
667 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
668 (i << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
669 exp0->DevHandle, &IOCStatus);
672 MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
673 warn("Error retrieving expander pg 1");
676 type = get_device_type(exp1->AttachedDeviceInfo);
677 if ((exp1->AttachedDeviceInfo &0x7) == 0) {
679 snprintf(rphy, 3, " ");
680 snprintf(rhandle, 5, " ");
682 speed = get_device_speed(
683 exp1->NegotiatedLinkRate);
684 snprintf(rphy, 3, "%02d",
685 exp1->AttachedPhyIdentifier);
686 snprintf(rhandle, 5, "%04x",
687 exp1->AttachedDevHandle);
689 min = get_device_speed(exp1->HwLinkRate);
690 max = get_device_speed(exp1->HwLinkRate >> 4);
691 printf(" %02d %s %s %s %s %s %s\n", exp1->Phy, rphy, rhandle, speed, min, max, type);
703 MPS_COMMAND(show, expanders, show_expanders, "", "Show attached expanders");
706 show_cfgpage(int ac, char **av)
708 MPI2_CONFIG_PAGE_HEADER *hdr;
709 MPI2_CONFIG_EXTENDED_PAGE_HEADER *ehdr;
714 int fd, error, len, attrs;
715 char *pgname, *pgattr;
717 fd = mps_open(mps_unit);
730 addr = (uint32_t)strtoul(av[3], NULL, 0);
732 num = (uint8_t)strtoul(av[2], NULL, 0);
734 page = (uint8_t)strtoul(av[1], NULL, 0);
738 warn("cfgpage: not enough arguments");
743 data = mps_read_extended_config_page(fd, page, 0, num, addr,
746 data = mps_read_config_page(fd, page, num, addr, &IOCStatus);
750 warn("Error retrieving cfg page: %s\n",
751 mps_ioc_status(IOCStatus));
757 len = ehdr->ExtPageLength * 4;
758 page = ehdr->ExtPageType;
759 attrs = ehdr->PageType >> 4;
762 len = hdr->PageLength * 4;
763 page = hdr->PageType & 0xf;
764 attrs = hdr->PageType >> 4;
767 pgname = get_page_name(page);
769 pgattr = "Read-only";
771 pgattr = "Read-Write";
773 pgattr = "Read-Write Persistent";
775 pgattr = "Unknown Page Attribute";
777 printf("Page 0x%x: %s %d, %s\n", page, pgname, num, pgattr);
778 hexdump(data, len, NULL, HD_REVERSED | 4);
784 MPS_COMMAND(show, cfgpage, show_cfgpage, "page [num] [addr]", "Display config page");