2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2008 Yahoo!, Inc.
6 * Written by: John Baldwin <jhb@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
36 #include <sys/param.h>
37 #include <sys/errno.h>
48 #define STANDALONE_STATE "ONLINE"
51 format_stripe(char *buf, size_t buflen, U32 stripe)
54 humanize_number(buf, buflen, stripe * 512, "", HN_AUTOSCALE,
59 display_stripe_map(const char *label, U32 StripeMap)
65 printf("%s: ", label);
66 for (i = 0; StripeMap != 0; i++, StripeMap >>= 1)
68 format_stripe(stripe, sizeof(stripe), 1 << i);
78 show_adapter(int ac, char **av)
80 CONFIG_PAGE_MANUFACTURING_0 *man0;
81 CONFIG_PAGE_IOC_2 *ioc2;
82 CONFIG_PAGE_IOC_6 *ioc6;
87 warnx("show adapter: extra arguments");
91 fd = mpt_open(mpt_unit);
98 man0 = mpt_read_man_page(fd, 0, NULL);
101 warn("Failed to get controller info");
105 if (man0->Header.PageLength < sizeof(*man0) / 4) {
106 warnx("Invalid controller info");
111 printf("mpt%d Adapter:\n", mpt_unit);
112 printf(" Board Name: %.16s\n", man0->BoardName);
113 printf(" Board Assembly: %.16s\n", man0->BoardAssembly);
114 printf(" Chip Name: %.16s\n", man0->ChipName);
115 printf(" Chip Revision: %.16s\n", man0->ChipRevision);
119 ioc2 = mpt_read_ioc_page(fd, 2, &IOCStatus);
121 printf(" RAID Levels:");
123 if (ioc2->CapabilitiesFlags &
124 MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT) {
128 if (ioc2->CapabilitiesFlags &
129 MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT) {
130 printf("%s RAID1", comma ? "," : "");
133 if (ioc2->CapabilitiesFlags &
134 MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT) {
135 printf("%s RAID1E", comma ? "," : "");
138 if (ioc2->CapabilitiesFlags &
139 MPI_IOCPAGE2_CAP_FLAGS_RAID_5_SUPPORT) {
140 printf("%s RAID5", comma ? "," : "");
143 if (ioc2->CapabilitiesFlags &
144 MPI_IOCPAGE2_CAP_FLAGS_RAID_6_SUPPORT) {
145 printf("%s RAID6", comma ? "," : "");
148 if (ioc2->CapabilitiesFlags &
149 MPI_IOCPAGE2_CAP_FLAGS_RAID_10_SUPPORT) {
150 printf("%s RAID10", comma ? "," : "");
153 if (ioc2->CapabilitiesFlags &
154 MPI_IOCPAGE2_CAP_FLAGS_RAID_50_SUPPORT) {
155 printf("%s RAID50", comma ? "," : "");
162 } else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
163 MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
164 warnx("mpt_read_ioc_page(2): %s", mpt_ioc_status(IOCStatus));
166 ioc6 = mpt_read_ioc_page(fd, 6, &IOCStatus);
168 display_stripe_map(" RAID0 Stripes",
169 ioc6->SupportedStripeSizeMapIS);
170 display_stripe_map(" RAID1E Stripes",
171 ioc6->SupportedStripeSizeMapIME);
172 printf(" RAID0 Drives/Vol: %u", ioc6->MinDrivesIS);
173 if (ioc6->MinDrivesIS != ioc6->MaxDrivesIS)
174 printf("-%u", ioc6->MaxDrivesIS);
176 printf(" RAID1 Drives/Vol: %u", ioc6->MinDrivesIM);
177 if (ioc6->MinDrivesIM != ioc6->MaxDrivesIM)
178 printf("-%u", ioc6->MaxDrivesIM);
180 printf("RAID1E Drives/Vol: %u", ioc6->MinDrivesIME);
181 if (ioc6->MinDrivesIME != ioc6->MaxDrivesIME)
182 printf("-%u", ioc6->MaxDrivesIME);
185 } else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
186 MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
187 warnx("mpt_read_ioc_page(6): %s", mpt_ioc_status(IOCStatus));
189 /* TODO: Add an ioctl to fetch IOC_FACTS and print firmware version. */
195 MPT_COMMAND(show, adapter, show_adapter);
198 print_vol(CONFIG_PAGE_RAID_VOL_0 *info, int state_len)
201 const char *level, *state;
202 char buf[6], stripe[5];
204 size = ((uint64_t)info->MaxLBAHigh << 32) | info->MaxLBA;
205 humanize_number(buf, sizeof(buf), (size + 1) * 512, "", HN_AUTOSCALE,
206 HN_B | HN_NOSPACE | HN_DECIMAL);
207 if (info->VolumeType == MPI_RAID_VOL_TYPE_IM)
210 format_stripe(stripe, sizeof(stripe), info->StripeSize);
211 level = mpt_raid_level(info->VolumeType);
212 state = mpt_volstate(info->VolumeStatus.State);
214 printf("(%6s) %-8s %6s %-*s", buf, level, stripe, state_len,
216 else if (stripe[0] != '\0')
217 printf("(%s) %s %s %s", buf, level, stripe, state);
219 printf("(%s) %s %s", buf, level, state);
223 print_pd(CONFIG_PAGE_RAID_PHYS_DISK_0 *info, int state_len, int location)
225 const char *inq, *state;
228 humanize_number(buf, sizeof(buf), ((uint64_t)info->MaxLBA + 1) * 512,
229 "", HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
230 state = mpt_pdstate(info);
232 printf("(%6s) %-*s", buf, state_len, state);
234 printf("(%s) %s", buf, state);
235 inq = mpt_pd_inq_string(info);
240 printf(" bus %d id %d", info->PhysDiskBus, info->PhysDiskID);
244 print_standalone(struct mpt_standalone_disk *disk, int state_len, int location)
248 humanize_number(buf, sizeof(buf), (disk->maxlba + 1) * 512,
249 "", HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
251 printf("(%6s) %-*s", buf, state_len, STANDALONE_STATE);
253 printf("(%s) %s", buf, STANDALONE_STATE);
254 if (disk->inqstring[0] != '\0')
255 printf(" %s", disk->inqstring);
258 printf(" bus %d id %d", disk->bus, disk->target);
262 print_spare_pools(U8 HotSparePool)
266 if (HotSparePool == 0) {
270 for (i = 0; HotSparePool != 0; i++) {
271 if (HotSparePool & 1) {
273 if (HotSparePool == 1)
282 show_config(int ac, char **av)
284 CONFIG_PAGE_IOC_2 *ioc2;
285 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
286 CONFIG_PAGE_IOC_5 *ioc5;
287 IOC_5_HOT_SPARE *spare;
288 CONFIG_PAGE_RAID_VOL_0 *vinfo;
289 RAID_VOL0_PHYS_DISK *disk;
290 CONFIG_PAGE_RAID_VOL_1 *vnames;
291 CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
292 struct mpt_standalone_disk *sdisks;
293 int error, fd, i, j, nsdisks;
296 warnx("show config: extra arguments");
300 fd = mpt_open(mpt_unit);
307 /* Get the config from the controller. */
308 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
309 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
310 if (ioc2 == NULL || ioc5 == NULL) {
312 warn("Failed to get config");
317 if (mpt_fetch_disks(fd, &nsdisks, &sdisks) < 0) {
319 warn("Failed to get standalone drive list");
326 /* Dump out the configuration. */
327 printf("mpt%d Configuration: %d volumes, %d drives\n",
328 mpt_unit, ioc2->NumActiveVolumes, ioc2->NumActivePhysDisks +
330 vol = ioc2->RaidVolume;
331 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
332 printf(" volume %s ", mpt_volume_name(vol->VolumeBus,
334 vinfo = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
336 printf("%s UNKNOWN", mpt_raid_level(vol->VolumeType));
338 print_vol(vinfo, -1);
339 vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
340 if (vnames != NULL) {
341 if (vnames->Name[0] != '\0')
342 printf(" <%s>", vnames->Name);
350 disk = vinfo->PhysDisk;
351 for (j = 0; j < vinfo->NumPhysDisks; disk++, j++) {
352 printf(" drive %u ", disk->PhysDiskNum);
353 pinfo = mpt_pd_info(fd, disk->PhysDiskNum, NULL);
355 print_pd(pinfo, -1, 0);
360 if (vinfo->VolumeSettings.HotSparePool != 0) {
361 printf(" spare pools: ");
362 print_spare_pools(vinfo->VolumeSettings.HotSparePool);
368 spare = ioc5->HotSpare;
369 for (i = 0; i < ioc5->NumHotSpares; spare++, i++) {
370 printf(" spare %u ", spare->PhysDiskNum);
371 pinfo = mpt_pd_info(fd, spare->PhysDiskNum, NULL);
373 print_pd(pinfo, -1, 0);
376 printf(" backs pool %d\n", ffs(spare->HotSparePool) - 1);
378 for (i = 0; i < nsdisks; i++) {
379 printf(" drive %s ", sdisks[i].devname);
380 print_standalone(&sdisks[i], -1, 0);
390 MPT_COMMAND(show, config, show_config);
393 show_volumes(int ac, char **av)
395 CONFIG_PAGE_IOC_2 *ioc2;
396 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
397 CONFIG_PAGE_RAID_VOL_0 **volumes;
398 CONFIG_PAGE_RAID_VOL_1 *vnames;
399 int error, fd, i, len, state_len;
402 warnx("show volumes: extra arguments");
406 fd = mpt_open(mpt_unit);
413 /* Get the volume list from the controller. */
414 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
417 warn("Failed to get volume list");
422 * Go ahead and read the info for all the volumes and figure
423 * out the maximum width of the state field.
425 volumes = malloc(sizeof(*volumes) * ioc2->NumActiveVolumes);
426 state_len = strlen("State");
427 vol = ioc2->RaidVolume;
428 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
429 volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID,
431 if (volumes[i] == NULL)
432 len = strlen("UNKNOWN");
434 len = strlen(mpt_volstate(
435 volumes[i]->VolumeStatus.State));
439 printf("mpt%d Volumes:\n", mpt_unit);
440 printf(" Id Size Level Stripe ");
441 len = state_len - strlen("State");
442 for (i = 0; i < (len + 1) / 2; i++)
445 for (i = 0; i < len / 2; i++)
447 printf(" Write-Cache Name\n");
448 vol = ioc2->RaidVolume;
449 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
450 printf("%6s ", mpt_volume_name(vol->VolumeBus, vol->VolumeID));
451 if (volumes[i] != NULL)
452 print_vol(volumes[i], state_len);
455 mpt_raid_level(vol->VolumeType), state_len,
457 if (volumes[i] != NULL) {
458 if (volumes[i]->VolumeSettings.Settings &
459 MPI_RAIDVOL0_SETTING_WRITE_CACHING_ENABLE)
462 printf(" Disabled ");
466 vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
467 if (vnames != NULL) {
468 if (vnames->Name[0] != '\0')
469 printf(" <%s>", vnames->Name);
480 MPT_COMMAND(show, volumes, show_volumes);
483 show_drives(int ac, char **av)
485 struct mpt_drive_list *list;
486 struct mpt_standalone_disk *sdisks;
487 int error, fd, i, len, nsdisks, state_len;
490 warnx("show drives: extra arguments");
494 fd = mpt_open(mpt_unit);
501 /* Get the drive list. */
502 list = mpt_pd_list(fd);
506 warn("Failed to get drive list");
510 /* Fetch the list of standalone disks for this controller. */
512 if (mpt_fetch_disks(fd, &nsdisks, &sdisks) != 0) {
517 state_len = strlen(STANDALONE_STATE);
519 /* Walk the drive list to determine width of state column. */
520 for (i = 0; i < list->ndrives; i++) {
521 len = strlen(mpt_pdstate(list->drives[i]));
526 /* List the drives. */
527 printf("mpt%d Physical Drives:\n", mpt_unit);
528 for (i = 0; i < list->ndrives; i++) {
529 printf("%4u ", list->drives[i]->PhysDiskNum);
530 print_pd(list->drives[i], state_len, 1);
533 mpt_free_pd_list(list);
534 for (i = 0; i < nsdisks; i++) {
535 printf("%4s ", sdisks[i].devname);
536 print_standalone(&sdisks[i], state_len, 1);
545 MPT_COMMAND(show, drives, show_drives);
549 show_physdisks(int ac, char **av)
551 CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
556 warnx("show drives: extra arguments");
560 fd = mpt_open(mpt_unit);
567 /* Try to find each possible phys disk page. */
568 for (i = 0; i <= 0xff; i++) {
569 pinfo = mpt_pd_info(fd, i, &IOCStatus);
571 if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
572 MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
573 warnx("mpt_pd_info(%d): %s", i,
574 mpt_ioc_status(IOCStatus));
578 print_pd(pinfo, -1, 1);
586 MPT_COMMAND(show, pd, show_physdisks);