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");
104 if (man0->Header.PageLength < sizeof(*man0) / 4) {
105 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");
312 if (mpt_fetch_disks(fd, &nsdisks, &sdisks) < 0) {
314 warn("Failed to get standalone drive list");
318 /* Dump out the configuration. */
319 printf("mpt%d Configuration: %d volumes, %d drives\n",
320 mpt_unit, ioc2->NumActiveVolumes, ioc2->NumActivePhysDisks +
322 vol = ioc2->RaidVolume;
323 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
324 printf(" volume %s ", mpt_volume_name(vol->VolumeBus,
326 vinfo = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
328 printf("%s UNKNOWN", mpt_raid_level(vol->VolumeType));
330 print_vol(vinfo, -1);
331 vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
332 if (vnames != NULL) {
333 if (vnames->Name[0] != '\0')
334 printf(" <%s>", vnames->Name);
342 disk = vinfo->PhysDisk;
343 for (j = 0; j < vinfo->NumPhysDisks; disk++, j++) {
344 printf(" drive %u ", disk->PhysDiskNum);
345 pinfo = mpt_pd_info(fd, disk->PhysDiskNum, NULL);
347 print_pd(pinfo, -1, 0);
352 if (vinfo->VolumeSettings.HotSparePool != 0) {
353 printf(" spare pools: ");
354 print_spare_pools(vinfo->VolumeSettings.HotSparePool);
360 spare = ioc5->HotSpare;
361 for (i = 0; i < ioc5->NumHotSpares; spare++, i++) {
362 printf(" spare %u ", spare->PhysDiskNum);
363 pinfo = mpt_pd_info(fd, spare->PhysDiskNum, NULL);
365 print_pd(pinfo, -1, 0);
368 printf(" backs pool %d\n", ffs(spare->HotSparePool) - 1);
370 for (i = 0; i < nsdisks; i++) {
371 printf(" drive %s ", sdisks[i].devname);
372 print_standalone(&sdisks[i], -1, 0);
382 MPT_COMMAND(show, config, show_config);
385 show_volumes(int ac, char **av)
387 CONFIG_PAGE_IOC_2 *ioc2;
388 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
389 CONFIG_PAGE_RAID_VOL_0 **volumes;
390 CONFIG_PAGE_RAID_VOL_1 *vnames;
391 int error, fd, i, len, state_len;
394 warnx("show volumes: extra arguments");
398 fd = mpt_open(mpt_unit);
405 /* Get the volume list from the controller. */
406 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
409 warn("Failed to get volume list");
414 * Go ahead and read the info for all the volumes and figure
415 * out the maximum width of the state field.
417 volumes = malloc(sizeof(*volumes) * ioc2->NumActiveVolumes);
418 state_len = strlen("State");
419 vol = ioc2->RaidVolume;
420 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
421 volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID,
423 if (volumes[i] == NULL)
424 len = strlen("UNKNOWN");
426 len = strlen(mpt_volstate(
427 volumes[i]->VolumeStatus.State));
431 printf("mpt%d Volumes:\n", mpt_unit);
432 printf(" Id Size Level Stripe ");
433 len = state_len - strlen("State");
434 for (i = 0; i < (len + 1) / 2; i++)
437 for (i = 0; i < len / 2; i++)
439 printf(" Write-Cache Name\n");
440 vol = ioc2->RaidVolume;
441 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
442 printf("%6s ", mpt_volume_name(vol->VolumeBus, vol->VolumeID));
443 if (volumes[i] != NULL)
444 print_vol(volumes[i], state_len);
447 mpt_raid_level(vol->VolumeType), state_len,
449 if (volumes[i] != NULL) {
450 if (volumes[i]->VolumeSettings.Settings &
451 MPI_RAIDVOL0_SETTING_WRITE_CACHING_ENABLE)
454 printf(" Disabled ");
458 vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
459 if (vnames != NULL) {
460 if (vnames->Name[0] != '\0')
461 printf(" <%s>", vnames->Name);
471 MPT_COMMAND(show, volumes, show_volumes);
474 show_drives(int ac, char **av)
476 struct mpt_drive_list *list;
477 struct mpt_standalone_disk *sdisks;
478 int error, fd, i, len, nsdisks, state_len;
481 warnx("show drives: extra arguments");
485 fd = mpt_open(mpt_unit);
492 /* Get the drive list. */
493 list = mpt_pd_list(fd);
496 warn("Failed to get drive list");
500 /* Fetch the list of standalone disks for this controller. */
502 if (mpt_fetch_disks(fd, &nsdisks, &sdisks) != 0) {
507 state_len = strlen(STANDALONE_STATE);
509 /* Walk the drive list to determine width of state column. */
510 for (i = 0; i < list->ndrives; i++) {
511 len = strlen(mpt_pdstate(list->drives[i]));
516 /* List the drives. */
517 printf("mpt%d Physical Drives:\n", mpt_unit);
518 for (i = 0; i < list->ndrives; i++) {
519 printf("%4u ", list->drives[i]->PhysDiskNum);
520 print_pd(list->drives[i], state_len, 1);
523 mpt_free_pd_list(list);
524 for (i = 0; i < nsdisks; i++) {
525 printf("%4s ", sdisks[i].devname);
526 print_standalone(&sdisks[i], state_len, 1);
535 MPT_COMMAND(show, drives, show_drives);
539 show_physdisks(int ac, char **av)
541 CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
546 warnx("show drives: extra arguments");
550 fd = mpt_open(mpt_unit);
557 /* Try to find each possible phys disk page. */
558 for (i = 0; i <= 0xff; i++) {
559 pinfo = mpt_pd_info(fd, i, &IOCStatus);
561 if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
562 MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
563 warnx("mpt_pd_info(%d): %s", i,
564 mpt_ioc_status(IOCStatus));
568 print_pd(pinfo, -1, 1);
576 MPT_COMMAND(show, pd, show_physdisks);