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);
145 sas1 = mps_read_extended_config_page(fd,
146 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
147 MPI2_SASIOUNITPAGE1_PAGEVERSION, 1, 0, &IOCStatus);
150 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
155 printf("%-8s%-12s%-11s%-10s%-8s%-7s%-7s%s\n", "PhyNum", "CtlrHandle",
156 "DevHandle", "Disabled", "Speed", "Min", "Max", "Device");
157 for (i = 0; i < sas0->NumPhys; i++) {
158 phy0 = &sas0->PhyData[i];
159 phy1 = &sas1->PhyData[i];
160 if (phy0->PortFlags &
161 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) {
162 printf("Discovery still in progress\n");
165 if (phy0->PhyFlags & MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED)
170 minspeed = get_device_speed(phy1->MaxMinLinkRate);
171 maxspeed = get_device_speed(phy1->MaxMinLinkRate >> 4);
172 type = get_device_type(phy0->ControllerPhyDeviceInfo);
174 if (phy0->AttachedDevHandle != 0) {
175 snprintf(devhandle, 5, "%04x", phy0->AttachedDevHandle);
176 snprintf(ctrlhandle, 5, "%04x",
177 phy0->ControllerDevHandle);
178 speed = get_device_speed(phy0->NegotiatedLinkRate);
180 snprintf(devhandle, 5, " ");
181 snprintf(ctrlhandle, 5, " ");
184 printf("%-8d%-12s%-11s%-10s%-8s%-7s%-7s%s\n",
185 i, ctrlhandle, devhandle, isdisabled, speed, minspeed,
195 MPS_COMMAND(show, adapter, show_adapter, "", "display controller information")
198 show_iocfacts(int ac, char **av)
200 MPI2_IOC_FACTS_REPLY *facts;
203 fd = mps_open(mps_unit);
210 if ((facts = mps_get_iocfacts(fd)) == NULL) {
211 printf("could not get controller IOCFacts\n");
216 printf(" MaxChainDepth: %d\n", facts->MaxChainDepth);
217 printf(" WhoInit: 0x%x\n", facts->WhoInit);
218 printf(" NumberOfPorts: %d\n", facts->NumberOfPorts);
219 printf(" MaxMSIxVectors: %d\n", facts->MaxMSIxVectors);
220 printf(" RequestCredit: %d\n", facts->RequestCredit);
221 printf(" ProductID: 0x%x\n", facts->ProductID);
222 printf(" IOCCapabilities: 0x%x\n", facts->IOCCapabilities);
223 printf(" FWVersion: 0x%08x\n", facts->FWVersion.Word);
224 printf(" IOCRequestFrameSize: %d\n", facts->IOCRequestFrameSize);
225 printf(" MaxInitiators: %d\n", facts->MaxInitiators);
226 printf(" MaxTargets: %d\n", facts->MaxTargets);
227 printf(" MaxSasExpanders: %d\n", facts->MaxSasExpanders);
228 printf(" MaxEnclosures: %d\n", facts->MaxEnclosures);
229 printf(" ProtocolFlags: 0x%x\n", facts->ProtocolFlags);
230 printf(" HighPriorityCredit: %d\n", facts->HighPriorityCredit);
231 printf("MaxRepDescPostQDepth: %d\n",
232 facts->MaxReplyDescriptorPostQueueDepth);
233 printf(" ReplyFrameSize: %d\n", facts->ReplyFrameSize);
234 printf(" MaxVolumes: %d\n", facts->MaxVolumes);
235 printf(" MaxDevHandle: %d\n", facts->MaxDevHandle);
236 printf("MaxPersistentEntries: %d\n", facts->MaxPersistentEntries);
237 printf(" MinDevHandle: %d\n", facts->MinDevHandle);
243 MPS_COMMAND(show, iocfacts, show_iocfacts, "", "Show IOC Facts Message");
246 show_adapters(int ac, char **av)
248 MPI2_CONFIG_PAGE_MAN_0 *man0;
249 MPI2_IOC_FACTS_REPLY *facts;
252 printf("Device Name\t Chip Name Board Name Firmware\n");
253 for (unit = 0; unit < MPS_MAX_UNIT; unit++) {
257 facts = mps_get_iocfacts(fd);
260 warn("Faled to get controller iocfacts");
264 man0 = mps_read_man_page(fd, 0, NULL);
267 warn("Failed to get controller info");
271 if (man0->Header.PageLength < sizeof(*man0) / 4) {
272 warnx("Invalid controller info");
277 printf("/dev/mp%s%d\t%16s %16s %08x\n",
278 is_mps ? "s": "r", unit,
279 man0->ChipName, man0->BoardName, facts->FWVersion.Word);
286 MPS_COMMAND(show, adapters, show_adapters, "", "Show a summary of all adapters");
289 get_device_type(uint32_t di)
293 return ("SEP Target ");
295 return ("ATAPI Target ");
297 return ("SAS Target ");
299 return ("STP Target ");
301 return ("SMP Target ");
303 return ("SATA Target ");
305 return ("SAS Initiator ");
307 return ("SATA Initiator");
309 return ("No Device ");
310 return ("Unknown Device");
314 get_enc_type(uint32_t flags, int *issep)
319 switch (flags & 0xf) {
321 type = "Direct Attached SES-2";
325 type = "Direct Attached SGPIO";
328 type = "Expander SGPIO";
331 type = "External SES-2";
335 type = "Direct Attached GPIO";
346 mps_device_speed[] = {
362 get_device_speed(uint8_t rate)
367 if (rate >= sizeof(mps_device_speed))
370 if ((speed = mps_device_speed[rate]) == NULL)
387 "RAID Physical Disk",
399 "RAID Configuration",
400 "Driver Persistent Mapping",
403 "Extended Manufacturing"
407 get_page_name(u_int page)
411 if (page >= sizeof(mps_page_name))
413 if ((name = mps_page_name[page]) == NULL)
419 show_all(int ac, char **av)
423 printf("Adapter:\n");
424 error = show_adapter(ac, av);
425 printf("Devices:\n");
426 error = show_devices(ac, av);
427 printf("Enclosures:\n");
428 error = show_enclosures(ac, av);
429 printf("Expanders:\n");
430 error = show_expanders(ac, av);
433 MPS_COMMAND(show, all, show_all, "", "Show all devices");
436 show_devices(int ac, char **av)
438 MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0;
439 MPI2_SAS_IO_UNIT0_PHY_DATA *phydata;
440 MPI2_CONFIG_PAGE_SAS_DEV_0 *device;
441 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
442 uint16_t IOCStatus, handle, bus, target;
443 char *type, *speed, enchandle[5], slot[3], bt[8];
445 int fd, error, nphys;
447 fd = mps_open(mps_unit);
454 sas0 = mps_read_extended_config_page(fd,
455 MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
456 MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus);
459 warn("Error retrieving SAS IO Unit page %d", IOCStatus);
462 nphys = sas0->NumPhys;
464 printf("B____%-5s%-17s%-8s%-10s%-14s%-6s%-5s%-6s%s\n",
465 "T", "SAS Address", "Handle", "Parent", "Device", "Speed",
466 "Enc", "Slot", "Wdt");
469 device = mps_read_extended_config_page(fd,
470 MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE,
471 MPI2_SASDEVICE0_PAGEVERSION, 0,
472 MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE | handle,
474 if (device == NULL) {
475 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
478 warn("Error retrieving device page");
481 handle = device->DevHandle;
483 if (device->ParentDevHandle == 0x0) {
490 error = mps_map_btdh(fd, &handle, &bus, &target);
495 if ((bus == 0xffff) || (target == 0xffff))
496 snprintf(bt, sizeof(bt), " ");
498 snprintf(bt, sizeof(bt), "%02d %02d", bus, target);
500 type = get_device_type(device->DeviceInfo);
502 if (device->PhyNum < nphys) {
503 phydata = &sas0->PhyData[device->PhyNum];
504 speed = get_device_speed(phydata->NegotiatedLinkRate);
505 } else if (device->ParentDevHandle > 0) {
506 exp1 = mps_read_extended_config_page(fd,
507 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
508 MPI2_SASEXPANDER1_PAGEVERSION, 1,
509 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
511 MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
512 device->ParentDevHandle, &IOCStatus);
514 if (IOCStatus != MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) {
516 warn("Error retrieving expander page 1: 0x%x",
522 speed = get_device_speed(exp1->NegotiatedLinkRate);
528 if (device->EnclosureHandle != 0) {
529 snprintf(enchandle, 5, "%04x", device->EnclosureHandle);
530 snprintf(slot, 3, "%02d", device->Slot);
532 snprintf(enchandle, 5, " ");
533 snprintf(slot, 3, " ");
536 snprintf(buf, sizeof(buf), "%08x%08x", device->SASAddress.High,
537 device->SASAddress.Low);
538 printf("%-17s", buf);
539 snprintf(buf, sizeof(buf), "%04x", device->DevHandle);
541 snprintf(buf, sizeof(buf), "%04x", device->ParentDevHandle);
542 printf("%-10s", buf);
543 printf("%-14s%-6s%-5s%-6s%d\n", type, speed,
544 enchandle, slot, device->MaxPortConnections);
552 MPS_COMMAND(show, devices, show_devices, "", "Show attached devices");
555 show_enclosures(int ac, char **av)
557 MPI2_CONFIG_PAGE_SAS_ENCLOSURE_0 *enc;
558 char *type, sepstr[5];
559 uint16_t IOCStatus, handle;
560 int fd, error, issep;
562 fd = mps_open(mps_unit);
569 printf("Slots Logical ID SEPHandle EncHandle Type\n");
572 enc = mps_read_extended_config_page(fd,
573 MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE,
574 MPI2_SASENCLOSURE0_PAGEVERSION, 0,
575 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE | handle,
578 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
581 warn("Error retrieving enclosure page");
584 type = get_enc_type(enc->Flags, &issep);
586 snprintf(sepstr, 5, " ");
588 snprintf(sepstr, 5, "%04x", enc->SEPDevHandle);
589 printf(" %.2d %08x%08x %s %04x %s\n",
590 enc->NumSlots, enc->EnclosureLogicalID.High,
591 enc->EnclosureLogicalID.Low, sepstr, enc->EnclosureHandle,
593 handle = enc->EnclosureHandle;
600 MPS_COMMAND(show, enclosures, show_enclosures, "", "Show attached enclosures");
603 show_expanders(int ac, char **av)
605 MPI2_CONFIG_PAGE_EXPANDER_0 *exp0;
606 MPI2_CONFIG_PAGE_EXPANDER_1 *exp1;
607 uint16_t IOCStatus, handle;
608 char enchandle[5], parent[5], rphy[3], rhandle[5];
609 char *speed, *min, *max, *type;
610 int fd, error, nphys, i;
612 fd = mps_open(mps_unit);
619 printf("NumPhys SAS Address DevHandle Parent EncHandle SAS Level\n");
622 exp0 = mps_read_extended_config_page(fd,
623 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
624 MPI2_SASEXPANDER0_PAGEVERSION, 0,
625 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL | handle,
628 if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
631 warn("Error retrieving expander page 0");
635 nphys = exp0->NumPhys;
636 handle = exp0->DevHandle;
638 if (exp0->EnclosureHandle == 0x00)
639 snprintf(enchandle, 5, " ");
641 snprintf(enchandle, 5, "%04d", exp0->EnclosureHandle);
642 if (exp0->ParentDevHandle == 0x0)
643 snprintf(parent, 5, " ");
645 snprintf(parent, 5, "%04x", exp0->ParentDevHandle);
646 printf(" %02d %08x%08x %04x %s %s %d\n",
647 exp0->NumPhys, exp0->SASAddress.High, exp0->SASAddress.Low,
648 exp0->DevHandle, parent, enchandle, exp0->SASLevel);
651 printf(" Phy RemotePhy DevHandle Speed Min Max Device\n");
652 for (i = 0; i < nphys; i++) {
653 exp1 = mps_read_extended_config_page(fd,
654 MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER,
655 MPI2_SASEXPANDER1_PAGEVERSION, 1,
656 MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM |
657 (i << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) |
658 exp0->DevHandle, &IOCStatus);
661 MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
662 warn("Error retrieving expander pg 1");
665 type = get_device_type(exp1->AttachedDeviceInfo);
666 if ((exp1->AttachedDeviceInfo &0x7) == 0) {
668 snprintf(rphy, 3, " ");
669 snprintf(rhandle, 5, " ");
671 speed = get_device_speed(
672 exp1->NegotiatedLinkRate);
673 snprintf(rphy, 3, "%02d",
674 exp1->AttachedPhyIdentifier);
675 snprintf(rhandle, 5, "%04x",
676 exp1->AttachedDevHandle);
678 min = get_device_speed(exp1->HwLinkRate);
679 max = get_device_speed(exp1->HwLinkRate >> 4);
680 printf(" %02d %s %s %s %s %s %s\n", exp1->Phy, rphy, rhandle, speed, min, max, type);
692 MPS_COMMAND(show, expanders, show_expanders, "", "Show attached expanders");
695 show_cfgpage(int ac, char **av)
697 MPI2_CONFIG_PAGE_HEADER *hdr;
698 MPI2_CONFIG_EXTENDED_PAGE_HEADER *ehdr;
703 int fd, error, len, attrs;
704 char *pgname, *pgattr;
706 fd = mps_open(mps_unit);
719 addr = (uint32_t)strtoul(av[3], NULL, 0);
721 num = (uint8_t)strtoul(av[2], NULL, 0);
723 page = (uint8_t)strtoul(av[1], NULL, 0);
727 warn("cfgpage: not enough arguments");
732 data = mps_read_extended_config_page(fd, page, 0, num, addr,
735 data = mps_read_config_page(fd, page, num, addr, &IOCStatus);
739 warn("Error retrieving cfg page: %s\n",
740 mps_ioc_status(IOCStatus));
746 len = ehdr->ExtPageLength * 4;
747 page = ehdr->ExtPageType;
748 attrs = ehdr->PageType >> 4;
751 len = hdr->PageLength * 4;
752 page = hdr->PageType & 0xf;
753 attrs = hdr->PageType >> 4;
756 pgname = get_page_name(page);
758 pgattr = "Read-only";
760 pgattr = "Read-Write";
762 pgattr = "Read-Write Persistent";
764 pgattr = "Unknown Page Attribute";
766 printf("Page 0x%x: %s %d, %s\n", page, pgname, num, pgattr);
767 hexdump(data, len, NULL, HD_REVERSED | 4);
772 MPS_COMMAND(show, cfgpage, show_cfgpage, "page [num] [addr]", "Display config page");