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/param.h>
34 #include <sys/errno.h>
45 #define STANDALONE_STATE "ONLINE"
48 format_stripe(char *buf, size_t buflen, U32 stripe)
51 humanize_number(buf, buflen, stripe * 512, "", HN_AUTOSCALE,
56 display_stripe_map(const char *label, U32 StripeMap)
62 printf("%s: ", label);
63 for (i = 0; StripeMap != 0; i++, StripeMap >>= 1)
65 format_stripe(stripe, sizeof(stripe), 1 << i);
75 show_adapter(int ac, char **av)
77 CONFIG_PAGE_MANUFACTURING_0 *man0;
78 CONFIG_PAGE_IOC_2 *ioc2;
79 CONFIG_PAGE_IOC_6 *ioc6;
84 warnx("show adapter: extra arguments");
88 fd = mpt_open(mpt_unit);
95 man0 = mpt_read_man_page(fd, 0, NULL);
98 warn("Failed to get controller info");
102 if (man0->Header.PageLength < sizeof(*man0) / 4) {
103 warnx("Invalid controller info");
108 printf("mpt%d Adapter:\n", mpt_unit);
109 printf(" Board Name: %.16s\n", man0->BoardName);
110 printf(" Board Assembly: %.16s\n", man0->BoardAssembly);
111 printf(" Chip Name: %.16s\n", man0->ChipName);
112 printf(" Chip Revision: %.16s\n", man0->ChipRevision);
116 ioc2 = mpt_read_ioc_page(fd, 2, &IOCStatus);
118 printf(" RAID Levels:");
120 if (ioc2->CapabilitiesFlags &
121 MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT) {
125 if (ioc2->CapabilitiesFlags &
126 MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT) {
127 printf("%s RAID1", comma ? "," : "");
130 if (ioc2->CapabilitiesFlags &
131 MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT) {
132 printf("%s RAID1E", comma ? "," : "");
135 if (ioc2->CapabilitiesFlags &
136 MPI_IOCPAGE2_CAP_FLAGS_RAID_5_SUPPORT) {
137 printf("%s RAID5", comma ? "," : "");
140 if (ioc2->CapabilitiesFlags &
141 MPI_IOCPAGE2_CAP_FLAGS_RAID_6_SUPPORT) {
142 printf("%s RAID6", comma ? "," : "");
145 if (ioc2->CapabilitiesFlags &
146 MPI_IOCPAGE2_CAP_FLAGS_RAID_10_SUPPORT) {
147 printf("%s RAID10", comma ? "," : "");
150 if (ioc2->CapabilitiesFlags &
151 MPI_IOCPAGE2_CAP_FLAGS_RAID_50_SUPPORT) {
152 printf("%s RAID50", comma ? "," : "");
159 } else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
160 MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
161 warnx("mpt_read_ioc_page(2): %s", mpt_ioc_status(IOCStatus));
163 ioc6 = mpt_read_ioc_page(fd, 6, &IOCStatus);
165 display_stripe_map(" RAID0 Stripes",
166 ioc6->SupportedStripeSizeMapIS);
167 display_stripe_map(" RAID1E Stripes",
168 ioc6->SupportedStripeSizeMapIME);
169 printf(" RAID0 Drives/Vol: %u", ioc6->MinDrivesIS);
170 if (ioc6->MinDrivesIS != ioc6->MaxDrivesIS)
171 printf("-%u", ioc6->MaxDrivesIS);
173 printf(" RAID1 Drives/Vol: %u", ioc6->MinDrivesIM);
174 if (ioc6->MinDrivesIM != ioc6->MaxDrivesIM)
175 printf("-%u", ioc6->MaxDrivesIM);
177 printf("RAID1E Drives/Vol: %u", ioc6->MinDrivesIME);
178 if (ioc6->MinDrivesIME != ioc6->MaxDrivesIME)
179 printf("-%u", ioc6->MaxDrivesIME);
182 } else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
183 MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
184 warnx("mpt_read_ioc_page(6): %s", mpt_ioc_status(IOCStatus));
186 /* TODO: Add an ioctl to fetch IOC_FACTS and print firmware version. */
192 MPT_COMMAND(show, adapter, show_adapter);
195 print_vol(CONFIG_PAGE_RAID_VOL_0 *info, int state_len)
198 const char *level, *state;
199 char buf[6], stripe[5];
201 size = ((uint64_t)info->MaxLBAHigh << 32) | info->MaxLBA;
202 humanize_number(buf, sizeof(buf), (size + 1) * 512, "", HN_AUTOSCALE,
203 HN_B | HN_NOSPACE | HN_DECIMAL);
204 if (info->VolumeType == MPI_RAID_VOL_TYPE_IM)
207 format_stripe(stripe, sizeof(stripe), info->StripeSize);
208 level = mpt_raid_level(info->VolumeType);
209 state = mpt_volstate(info->VolumeStatus.State);
211 printf("(%6s) %-8s %6s %-*s", buf, level, stripe, state_len,
213 else if (stripe[0] != '\0')
214 printf("(%s) %s %s %s", buf, level, stripe, state);
216 printf("(%s) %s %s", buf, level, state);
220 print_pd(CONFIG_PAGE_RAID_PHYS_DISK_0 *info, int state_len, int location)
222 const char *inq, *state;
225 humanize_number(buf, sizeof(buf), ((uint64_t)info->MaxLBA + 1) * 512,
226 "", HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
227 state = mpt_pdstate(info);
229 printf("(%6s) %-*s", buf, state_len, state);
231 printf("(%s) %s", buf, state);
232 inq = mpt_pd_inq_string(info);
237 printf(" bus %d id %d", info->PhysDiskBus, info->PhysDiskID);
241 print_standalone(struct mpt_standalone_disk *disk, int state_len, int location)
245 humanize_number(buf, sizeof(buf), (disk->maxlba + 1) * 512,
246 "", HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
248 printf("(%6s) %-*s", buf, state_len, STANDALONE_STATE);
250 printf("(%s) %s", buf, STANDALONE_STATE);
251 if (disk->inqstring[0] != '\0')
252 printf(" %s", disk->inqstring);
255 printf(" bus %d id %d", disk->bus, disk->target);
259 print_spare_pools(U8 HotSparePool)
263 if (HotSparePool == 0) {
267 for (i = 0; HotSparePool != 0; i++) {
268 if (HotSparePool & 1) {
270 if (HotSparePool == 1)
279 show_config(int ac, char **av)
281 CONFIG_PAGE_IOC_2 *ioc2;
282 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
283 CONFIG_PAGE_IOC_5 *ioc5;
284 IOC_5_HOT_SPARE *spare;
285 CONFIG_PAGE_RAID_VOL_0 *vinfo;
286 RAID_VOL0_PHYS_DISK *disk;
287 CONFIG_PAGE_RAID_VOL_1 *vnames;
288 CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
289 struct mpt_standalone_disk *sdisks;
290 int error, fd, i, j, nsdisks;
293 warnx("show config: extra arguments");
297 fd = mpt_open(mpt_unit);
304 /* Get the config from the controller. */
305 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
306 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
307 if (ioc2 == NULL || ioc5 == NULL) {
309 warn("Failed to get config");
314 if (mpt_fetch_disks(fd, &nsdisks, &sdisks) < 0) {
316 warn("Failed to get standalone drive list");
323 /* Dump out the configuration. */
324 printf("mpt%d Configuration: %d volumes, %d drives\n",
325 mpt_unit, ioc2->NumActiveVolumes, ioc2->NumActivePhysDisks +
327 vol = ioc2->RaidVolume;
328 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
329 printf(" volume %s ", mpt_volume_name(vol->VolumeBus,
331 vinfo = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
333 printf("%s UNKNOWN", mpt_raid_level(vol->VolumeType));
335 print_vol(vinfo, -1);
336 vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
337 if (vnames != NULL) {
338 if (vnames->Name[0] != '\0')
339 printf(" <%s>", vnames->Name);
347 disk = vinfo->PhysDisk;
348 for (j = 0; j < vinfo->NumPhysDisks; disk++, j++) {
349 printf(" drive %u ", disk->PhysDiskNum);
350 pinfo = mpt_pd_info(fd, disk->PhysDiskNum, NULL);
352 print_pd(pinfo, -1, 0);
357 if (vinfo->VolumeSettings.HotSparePool != 0) {
358 printf(" spare pools: ");
359 print_spare_pools(vinfo->VolumeSettings.HotSparePool);
365 spare = ioc5->HotSpare;
366 for (i = 0; i < ioc5->NumHotSpares; spare++, i++) {
367 printf(" spare %u ", spare->PhysDiskNum);
368 pinfo = mpt_pd_info(fd, spare->PhysDiskNum, NULL);
370 print_pd(pinfo, -1, 0);
373 printf(" backs pool %d\n", ffs(spare->HotSparePool) - 1);
375 for (i = 0; i < nsdisks; i++) {
376 printf(" drive %s ", sdisks[i].devname);
377 print_standalone(&sdisks[i], -1, 0);
387 MPT_COMMAND(show, config, show_config);
390 show_volumes(int ac, char **av)
392 CONFIG_PAGE_IOC_2 *ioc2;
393 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
394 CONFIG_PAGE_RAID_VOL_0 **volumes;
395 CONFIG_PAGE_RAID_VOL_1 *vnames;
396 int error, fd, i, len, state_len;
399 warnx("show volumes: extra arguments");
403 fd = mpt_open(mpt_unit);
410 /* Get the volume list from the controller. */
411 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
414 warn("Failed to get volume list");
419 * Go ahead and read the info for all the volumes and figure
420 * out the maximum width of the state field.
422 volumes = malloc(sizeof(*volumes) * ioc2->NumActiveVolumes);
423 state_len = strlen("State");
424 vol = ioc2->RaidVolume;
425 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
426 volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID,
428 if (volumes[i] == NULL)
429 len = strlen("UNKNOWN");
431 len = strlen(mpt_volstate(
432 volumes[i]->VolumeStatus.State));
436 printf("mpt%d Volumes:\n", mpt_unit);
437 printf(" Id Size Level Stripe ");
438 len = state_len - strlen("State");
439 for (i = 0; i < (len + 1) / 2; i++)
442 for (i = 0; i < len / 2; i++)
444 printf(" Write-Cache Name\n");
445 vol = ioc2->RaidVolume;
446 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
447 printf("%6s ", mpt_volume_name(vol->VolumeBus, vol->VolumeID));
448 if (volumes[i] != NULL)
449 print_vol(volumes[i], state_len);
452 mpt_raid_level(vol->VolumeType), state_len,
454 if (volumes[i] != NULL) {
455 if (volumes[i]->VolumeSettings.Settings &
456 MPI_RAIDVOL0_SETTING_WRITE_CACHING_ENABLE)
459 printf(" Disabled ");
463 vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
464 if (vnames != NULL) {
465 if (vnames->Name[0] != '\0')
466 printf(" <%s>", vnames->Name);
477 MPT_COMMAND(show, volumes, show_volumes);
480 show_drives(int ac, char **av)
482 struct mpt_drive_list *list;
483 struct mpt_standalone_disk *sdisks;
484 int error, fd, i, len, nsdisks, state_len;
487 warnx("show drives: extra arguments");
491 fd = mpt_open(mpt_unit);
498 /* Get the drive list. */
499 list = mpt_pd_list(fd);
503 warn("Failed to get drive list");
507 /* Fetch the list of standalone disks for this controller. */
509 if (mpt_fetch_disks(fd, &nsdisks, &sdisks) != 0) {
514 state_len = strlen(STANDALONE_STATE);
516 /* Walk the drive list to determine width of state column. */
517 for (i = 0; i < list->ndrives; i++) {
518 len = strlen(mpt_pdstate(list->drives[i]));
523 /* List the drives. */
524 printf("mpt%d Physical Drives:\n", mpt_unit);
525 for (i = 0; i < list->ndrives; i++) {
526 printf("%4u ", list->drives[i]->PhysDiskNum);
527 print_pd(list->drives[i], state_len, 1);
530 mpt_free_pd_list(list);
531 for (i = 0; i < nsdisks; i++) {
532 printf("%4s ", sdisks[i].devname);
533 print_standalone(&sdisks[i], state_len, 1);
542 MPT_COMMAND(show, drives, show_drives);
546 show_physdisks(int ac, char **av)
548 CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
553 warnx("show drives: extra arguments");
557 fd = mpt_open(mpt_unit);
564 /* Try to find each possible phys disk page. */
565 for (i = 0; i <= 0xff; i++) {
566 pinfo = mpt_pd_info(fd, i, &IOCStatus);
568 if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
569 MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
570 warnx("mpt_pd_info(%d): %s", i,
571 mpt_ioc_status(IOCStatus));
575 print_pd(pinfo, -1, 1);
583 MPT_COMMAND(show, pd, show_physdisks);