1fc58801cSScott Long /*-
28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni *
4fc58801cSScott Long * Copyright (c) 2008 Yahoo!, Inc.
5fc58801cSScott Long * All rights reserved.
6fc58801cSScott Long * Written by: John Baldwin <jhb@FreeBSD.org>
7fc58801cSScott Long *
8fc58801cSScott Long * Redistribution and use in source and binary forms, with or without
9fc58801cSScott Long * modification, are permitted provided that the following conditions
10fc58801cSScott Long * are met:
11fc58801cSScott Long * 1. Redistributions of source code must retain the above copyright
12fc58801cSScott Long * notice, this list of conditions and the following disclaimer.
13fc58801cSScott Long * 2. Redistributions in binary form must reproduce the above copyright
14fc58801cSScott Long * notice, this list of conditions and the following disclaimer in the
15fc58801cSScott Long * documentation and/or other materials provided with the distribution.
16fc58801cSScott Long * 3. Neither the name of the author nor the names of any co-contributors
17fc58801cSScott Long * may be used to endorse or promote products derived from this software
18fc58801cSScott Long * without specific prior written permission.
19fc58801cSScott Long *
20fc58801cSScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21fc58801cSScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22fc58801cSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23fc58801cSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24fc58801cSScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25fc58801cSScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26fc58801cSScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27fc58801cSScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28fc58801cSScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29fc58801cSScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30fc58801cSScott Long * SUCH DAMAGE.
31fc58801cSScott Long */
32fc58801cSScott Long
33fc58801cSScott Long #include <sys/param.h>
34fc58801cSScott Long #include <sys/errno.h>
35fc58801cSScott Long #include <err.h>
36fc58801cSScott Long #include <libutil.h>
37fc58801cSScott Long #include <stdio.h>
38fc58801cSScott Long #include <stdlib.h>
39fc58801cSScott Long #include <string.h>
40fc58801cSScott Long #include <unistd.h>
41fc58801cSScott Long #include "mptutil.h"
42fc58801cSScott Long
43fc58801cSScott Long MPT_TABLE(top, show);
44fc58801cSScott Long
45fc58801cSScott Long #define STANDALONE_STATE "ONLINE"
46fc58801cSScott Long
47fc58801cSScott Long static void
format_stripe(char * buf,size_t buflen,U32 stripe)48fc58801cSScott Long format_stripe(char *buf, size_t buflen, U32 stripe)
49fc58801cSScott Long {
50fc58801cSScott Long
51fc58801cSScott Long humanize_number(buf, buflen, stripe * 512, "", HN_AUTOSCALE,
52fc58801cSScott Long HN_B | HN_NOSPACE);
53fc58801cSScott Long }
54fc58801cSScott Long
55fc58801cSScott Long static void
display_stripe_map(const char * label,U32 StripeMap)56fc58801cSScott Long display_stripe_map(const char *label, U32 StripeMap)
57fc58801cSScott Long {
58fc58801cSScott Long char stripe[5];
59fc58801cSScott Long int comma, i;
60fc58801cSScott Long
61fc58801cSScott Long comma = 0;
62fc58801cSScott Long printf("%s: ", label);
63fc58801cSScott Long for (i = 0; StripeMap != 0; i++, StripeMap >>= 1)
64fc58801cSScott Long if (StripeMap & 1) {
65fc58801cSScott Long format_stripe(stripe, sizeof(stripe), 1 << i);
66fc58801cSScott Long if (comma)
67fc58801cSScott Long printf(", ");
68fc58801cSScott Long printf("%s", stripe);
69fc58801cSScott Long comma = 1;
70fc58801cSScott Long }
71fc58801cSScott Long printf("\n");
72fc58801cSScott Long }
73fc58801cSScott Long
74fc58801cSScott Long static int
show_adapter(int ac,char ** av)75fc58801cSScott Long show_adapter(int ac, char **av)
76fc58801cSScott Long {
77fc58801cSScott Long CONFIG_PAGE_MANUFACTURING_0 *man0;
78fc58801cSScott Long CONFIG_PAGE_IOC_2 *ioc2;
79fc58801cSScott Long CONFIG_PAGE_IOC_6 *ioc6;
805f1f6da8SJohn Baldwin U16 IOCStatus;
81c5f2b79dSJohn Baldwin int comma, error, fd;
82fc58801cSScott Long
83fc58801cSScott Long if (ac != 1) {
84fc58801cSScott Long warnx("show adapter: extra arguments");
85fc58801cSScott Long return (EINVAL);
86fc58801cSScott Long }
87fc58801cSScott Long
88fc58801cSScott Long fd = mpt_open(mpt_unit);
89fc58801cSScott Long if (fd < 0) {
90c5f2b79dSJohn Baldwin error = errno;
91fc58801cSScott Long warn("mpt_open");
92c5f2b79dSJohn Baldwin return (error);
93fc58801cSScott Long }
94fc58801cSScott Long
95fc58801cSScott Long man0 = mpt_read_man_page(fd, 0, NULL);
96fc58801cSScott Long if (man0 == NULL) {
97c5f2b79dSJohn Baldwin error = errno;
98fc58801cSScott Long warn("Failed to get controller info");
99d68b76a9SAlan Somers close(fd);
100c5f2b79dSJohn Baldwin return (error);
101fc58801cSScott Long }
102fc58801cSScott Long if (man0->Header.PageLength < sizeof(*man0) / 4) {
103c5f2b79dSJohn Baldwin warnx("Invalid controller info");
104d68b76a9SAlan Somers free(man0);
105d68b76a9SAlan Somers close(fd);
106fc58801cSScott Long return (EINVAL);
107fc58801cSScott Long }
108fc58801cSScott Long printf("mpt%d Adapter:\n", mpt_unit);
109fc58801cSScott Long printf(" Board Name: %.16s\n", man0->BoardName);
110fc58801cSScott Long printf(" Board Assembly: %.16s\n", man0->BoardAssembly);
111fc58801cSScott Long printf(" Chip Name: %.16s\n", man0->ChipName);
112fc58801cSScott Long printf(" Chip Revision: %.16s\n", man0->ChipRevision);
113fc58801cSScott Long
114fc58801cSScott Long free(man0);
115fc58801cSScott Long
1165f1f6da8SJohn Baldwin ioc2 = mpt_read_ioc_page(fd, 2, &IOCStatus);
117fc58801cSScott Long if (ioc2 != NULL) {
118fc58801cSScott Long printf(" RAID Levels:");
119fc58801cSScott Long comma = 0;
120fc58801cSScott Long if (ioc2->CapabilitiesFlags &
121fc58801cSScott Long MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT) {
122fc58801cSScott Long printf(" RAID0");
123fc58801cSScott Long comma = 1;
124fc58801cSScott Long }
125fc58801cSScott Long if (ioc2->CapabilitiesFlags &
126fc58801cSScott Long MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT) {
127fc58801cSScott Long printf("%s RAID1", comma ? "," : "");
128fc58801cSScott Long comma = 1;
129fc58801cSScott Long }
130fc58801cSScott Long if (ioc2->CapabilitiesFlags &
131fc58801cSScott Long MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT) {
132fc58801cSScott Long printf("%s RAID1E", comma ? "," : "");
133fc58801cSScott Long comma = 1;
134fc58801cSScott Long }
135fc58801cSScott Long if (ioc2->CapabilitiesFlags &
136fc58801cSScott Long MPI_IOCPAGE2_CAP_FLAGS_RAID_5_SUPPORT) {
137fc58801cSScott Long printf("%s RAID5", comma ? "," : "");
138fc58801cSScott Long comma = 1;
139fc58801cSScott Long }
140fc58801cSScott Long if (ioc2->CapabilitiesFlags &
141fc58801cSScott Long MPI_IOCPAGE2_CAP_FLAGS_RAID_6_SUPPORT) {
142fc58801cSScott Long printf("%s RAID6", comma ? "," : "");
143fc58801cSScott Long comma = 1;
144fc58801cSScott Long }
145fc58801cSScott Long if (ioc2->CapabilitiesFlags &
146fc58801cSScott Long MPI_IOCPAGE2_CAP_FLAGS_RAID_10_SUPPORT) {
147fc58801cSScott Long printf("%s RAID10", comma ? "," : "");
148fc58801cSScott Long comma = 1;
149fc58801cSScott Long }
150fc58801cSScott Long if (ioc2->CapabilitiesFlags &
151fc58801cSScott Long MPI_IOCPAGE2_CAP_FLAGS_RAID_50_SUPPORT) {
152fc58801cSScott Long printf("%s RAID50", comma ? "," : "");
153fc58801cSScott Long comma = 1;
154fc58801cSScott Long }
155fc58801cSScott Long if (!comma)
156fc58801cSScott Long printf(" none");
157fc58801cSScott Long printf("\n");
158fc58801cSScott Long free(ioc2);
1595f1f6da8SJohn Baldwin } else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
1605f1f6da8SJohn Baldwin MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
1615f1f6da8SJohn Baldwin warnx("mpt_read_ioc_page(2): %s", mpt_ioc_status(IOCStatus));
162fc58801cSScott Long
1635f1f6da8SJohn Baldwin ioc6 = mpt_read_ioc_page(fd, 6, &IOCStatus);
164fc58801cSScott Long if (ioc6 != NULL) {
165fc58801cSScott Long display_stripe_map(" RAID0 Stripes",
166fc58801cSScott Long ioc6->SupportedStripeSizeMapIS);
167fc58801cSScott Long display_stripe_map(" RAID1E Stripes",
168fc58801cSScott Long ioc6->SupportedStripeSizeMapIME);
169fc58801cSScott Long printf(" RAID0 Drives/Vol: %u", ioc6->MinDrivesIS);
170fc58801cSScott Long if (ioc6->MinDrivesIS != ioc6->MaxDrivesIS)
171fc58801cSScott Long printf("-%u", ioc6->MaxDrivesIS);
172fc58801cSScott Long printf("\n");
173fc58801cSScott Long printf(" RAID1 Drives/Vol: %u", ioc6->MinDrivesIM);
174fc58801cSScott Long if (ioc6->MinDrivesIM != ioc6->MaxDrivesIM)
175fc58801cSScott Long printf("-%u", ioc6->MaxDrivesIM);
176fc58801cSScott Long printf("\n");
177fc58801cSScott Long printf("RAID1E Drives/Vol: %u", ioc6->MinDrivesIME);
178fc58801cSScott Long if (ioc6->MinDrivesIME != ioc6->MaxDrivesIME)
179fc58801cSScott Long printf("-%u", ioc6->MaxDrivesIME);
180fc58801cSScott Long printf("\n");
181fc58801cSScott Long free(ioc6);
1825f1f6da8SJohn Baldwin } else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
1835f1f6da8SJohn Baldwin MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
1845f1f6da8SJohn Baldwin warnx("mpt_read_ioc_page(6): %s", mpt_ioc_status(IOCStatus));
185fc58801cSScott Long
186fc58801cSScott Long /* TODO: Add an ioctl to fetch IOC_FACTS and print firmware version. */
187fc58801cSScott Long
188fc58801cSScott Long close(fd);
189fc58801cSScott Long
190fc58801cSScott Long return (0);
191fc58801cSScott Long }
192fc58801cSScott Long MPT_COMMAND(show, adapter, show_adapter);
193fc58801cSScott Long
194fc58801cSScott Long static void
print_vol(CONFIG_PAGE_RAID_VOL_0 * info,int state_len)195fc58801cSScott Long print_vol(CONFIG_PAGE_RAID_VOL_0 *info, int state_len)
196fc58801cSScott Long {
197fc58801cSScott Long uint64_t size;
198fc58801cSScott Long const char *level, *state;
199fc58801cSScott Long char buf[6], stripe[5];
200fc58801cSScott Long
201fc58801cSScott Long size = ((uint64_t)info->MaxLBAHigh << 32) | info->MaxLBA;
202fc58801cSScott Long humanize_number(buf, sizeof(buf), (size + 1) * 512, "", HN_AUTOSCALE,
203fc58801cSScott Long HN_B | HN_NOSPACE | HN_DECIMAL);
204fc58801cSScott Long if (info->VolumeType == MPI_RAID_VOL_TYPE_IM)
205fc58801cSScott Long stripe[0] = '\0';
206fc58801cSScott Long else
207fc58801cSScott Long format_stripe(stripe, sizeof(stripe), info->StripeSize);
208fc58801cSScott Long level = mpt_raid_level(info->VolumeType);
209fc58801cSScott Long state = mpt_volstate(info->VolumeStatus.State);
210fc58801cSScott Long if (state_len > 0)
211fc58801cSScott Long printf("(%6s) %-8s %6s %-*s", buf, level, stripe, state_len,
212fc58801cSScott Long state);
213fc58801cSScott Long else if (stripe[0] != '\0')
214fc58801cSScott Long printf("(%s) %s %s %s", buf, level, stripe, state);
215fc58801cSScott Long else
216fc58801cSScott Long printf("(%s) %s %s", buf, level, state);
217fc58801cSScott Long }
218fc58801cSScott Long
219fc58801cSScott Long static void
print_pd(CONFIG_PAGE_RAID_PHYS_DISK_0 * info,int state_len,int location)220fc58801cSScott Long print_pd(CONFIG_PAGE_RAID_PHYS_DISK_0 *info, int state_len, int location)
221fc58801cSScott Long {
222fc58801cSScott Long const char *inq, *state;
223fc58801cSScott Long char buf[6];
224fc58801cSScott Long
225fc58801cSScott Long humanize_number(buf, sizeof(buf), ((uint64_t)info->MaxLBA + 1) * 512,
226fc58801cSScott Long "", HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
227fc58801cSScott Long state = mpt_pdstate(info);
228fc58801cSScott Long if (state_len > 0)
229fc58801cSScott Long printf("(%6s) %-*s", buf, state_len, state);
230fc58801cSScott Long else
231fc58801cSScott Long printf("(%s) %s", buf, state);
232fc58801cSScott Long inq = mpt_pd_inq_string(info);
233fc58801cSScott Long if (inq != NULL)
234fc58801cSScott Long printf(" %s", inq);
235fc58801cSScott Long if (!location)
236fc58801cSScott Long return;
237fc58801cSScott Long printf(" bus %d id %d", info->PhysDiskBus, info->PhysDiskID);
238fc58801cSScott Long }
239fc58801cSScott Long
240fc58801cSScott Long static void
print_standalone(struct mpt_standalone_disk * disk,int state_len,int location)241fc58801cSScott Long print_standalone(struct mpt_standalone_disk *disk, int state_len, int location)
242fc58801cSScott Long {
243fc58801cSScott Long char buf[6];
244fc58801cSScott Long
245fc58801cSScott Long humanize_number(buf, sizeof(buf), (disk->maxlba + 1) * 512,
246fc58801cSScott Long "", HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
247fc58801cSScott Long if (state_len > 0)
248fc58801cSScott Long printf("(%6s) %-*s", buf, state_len, STANDALONE_STATE);
249fc58801cSScott Long else
250fc58801cSScott Long printf("(%s) %s", buf, STANDALONE_STATE);
251fc58801cSScott Long if (disk->inqstring[0] != '\0')
252fc58801cSScott Long printf(" %s", disk->inqstring);
253fc58801cSScott Long if (!location)
254fc58801cSScott Long return;
255fc58801cSScott Long printf(" bus %d id %d", disk->bus, disk->target);
256fc58801cSScott Long }
257fc58801cSScott Long
258fc58801cSScott Long static void
print_spare_pools(U8 HotSparePool)259fc58801cSScott Long print_spare_pools(U8 HotSparePool)
260fc58801cSScott Long {
261fc58801cSScott Long int i;
262fc58801cSScott Long
263fc58801cSScott Long if (HotSparePool == 0) {
264fc58801cSScott Long printf("none");
265fc58801cSScott Long return;
266fc58801cSScott Long }
267fc58801cSScott Long for (i = 0; HotSparePool != 0; i++) {
268fc58801cSScott Long if (HotSparePool & 1) {
269fc58801cSScott Long printf("%d", i);
270fc58801cSScott Long if (HotSparePool == 1)
271fc58801cSScott Long break;
272fc58801cSScott Long printf(", ");
273fc58801cSScott Long }
274fc58801cSScott Long HotSparePool >>= 1;
275fc58801cSScott Long }
276fc58801cSScott Long }
277fc58801cSScott Long
278fc58801cSScott Long static int
show_config(int ac,char ** av)279fc58801cSScott Long show_config(int ac, char **av)
280fc58801cSScott Long {
281fc58801cSScott Long CONFIG_PAGE_IOC_2 *ioc2;
282fc58801cSScott Long CONFIG_PAGE_IOC_2_RAID_VOL *vol;
283fc58801cSScott Long CONFIG_PAGE_IOC_5 *ioc5;
284fc58801cSScott Long IOC_5_HOT_SPARE *spare;
285fc58801cSScott Long CONFIG_PAGE_RAID_VOL_0 *vinfo;
286fc58801cSScott Long RAID_VOL0_PHYS_DISK *disk;
287fc58801cSScott Long CONFIG_PAGE_RAID_VOL_1 *vnames;
288fc58801cSScott Long CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
289fc58801cSScott Long struct mpt_standalone_disk *sdisks;
290c5f2b79dSJohn Baldwin int error, fd, i, j, nsdisks;
291fc58801cSScott Long
292fc58801cSScott Long if (ac != 1) {
293fc58801cSScott Long warnx("show config: extra arguments");
294fc58801cSScott Long return (EINVAL);
295fc58801cSScott Long }
296fc58801cSScott Long
297fc58801cSScott Long fd = mpt_open(mpt_unit);
298fc58801cSScott Long if (fd < 0) {
299c5f2b79dSJohn Baldwin error = errno;
300fc58801cSScott Long warn("mpt_open");
301c5f2b79dSJohn Baldwin return (error);
302fc58801cSScott Long }
303fc58801cSScott Long
304fc58801cSScott Long /* Get the config from the controller. */
305fc58801cSScott Long ioc2 = mpt_read_ioc_page(fd, 2, NULL);
306fc58801cSScott Long ioc5 = mpt_read_ioc_page(fd, 5, NULL);
307fc58801cSScott Long if (ioc2 == NULL || ioc5 == NULL) {
308c5f2b79dSJohn Baldwin error = errno;
309fc58801cSScott Long warn("Failed to get config");
310d68b76a9SAlan Somers free(ioc2);
311d68b76a9SAlan Somers close(fd);
312c5f2b79dSJohn Baldwin return (error);
313fc58801cSScott Long }
314fc58801cSScott Long if (mpt_fetch_disks(fd, &nsdisks, &sdisks) < 0) {
315c5f2b79dSJohn Baldwin error = errno;
316fc58801cSScott Long warn("Failed to get standalone drive list");
317d68b76a9SAlan Somers free(ioc5);
318d68b76a9SAlan Somers free(ioc2);
319d68b76a9SAlan Somers close(fd);
320c5f2b79dSJohn Baldwin return (error);
321fc58801cSScott Long }
322fc58801cSScott Long
323fc58801cSScott Long /* Dump out the configuration. */
324fc58801cSScott Long printf("mpt%d Configuration: %d volumes, %d drives\n",
325fc58801cSScott Long mpt_unit, ioc2->NumActiveVolumes, ioc2->NumActivePhysDisks +
326fc58801cSScott Long nsdisks);
327fc58801cSScott Long vol = ioc2->RaidVolume;
328fc58801cSScott Long for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
329fc58801cSScott Long printf(" volume %s ", mpt_volume_name(vol->VolumeBus,
330fc58801cSScott Long vol->VolumeID));
331fc58801cSScott Long vinfo = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
332fc58801cSScott Long if (vinfo == NULL) {
333fc58801cSScott Long printf("%s UNKNOWN", mpt_raid_level(vol->VolumeType));
334fc58801cSScott Long } else
335fc58801cSScott Long print_vol(vinfo, -1);
336fc58801cSScott Long vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
337fc58801cSScott Long if (vnames != NULL) {
338fc58801cSScott Long if (vnames->Name[0] != '\0')
339fc58801cSScott Long printf(" <%s>", vnames->Name);
340fc58801cSScott Long free(vnames);
341fc58801cSScott Long }
342fc58801cSScott Long if (vinfo == NULL) {
343fc58801cSScott Long printf("\n");
344fc58801cSScott Long continue;
345fc58801cSScott Long }
346fc58801cSScott Long printf(" spans:\n");
347fc58801cSScott Long disk = vinfo->PhysDisk;
348fc58801cSScott Long for (j = 0; j < vinfo->NumPhysDisks; disk++, j++) {
349fc58801cSScott Long printf(" drive %u ", disk->PhysDiskNum);
350fc58801cSScott Long pinfo = mpt_pd_info(fd, disk->PhysDiskNum, NULL);
351fc58801cSScott Long if (pinfo != NULL) {
352fc58801cSScott Long print_pd(pinfo, -1, 0);
353fc58801cSScott Long free(pinfo);
354fc58801cSScott Long }
355fc58801cSScott Long printf("\n");
356fc58801cSScott Long }
357fc58801cSScott Long if (vinfo->VolumeSettings.HotSparePool != 0) {
358fc58801cSScott Long printf(" spare pools: ");
359fc58801cSScott Long print_spare_pools(vinfo->VolumeSettings.HotSparePool);
360fc58801cSScott Long printf("\n");
361fc58801cSScott Long }
362fc58801cSScott Long free(vinfo);
363fc58801cSScott Long }
364fc58801cSScott Long
365fc58801cSScott Long spare = ioc5->HotSpare;
366fc58801cSScott Long for (i = 0; i < ioc5->NumHotSpares; spare++, i++) {
367fc58801cSScott Long printf(" spare %u ", spare->PhysDiskNum);
368fc58801cSScott Long pinfo = mpt_pd_info(fd, spare->PhysDiskNum, NULL);
369fc58801cSScott Long if (pinfo != NULL) {
370fc58801cSScott Long print_pd(pinfo, -1, 0);
371fc58801cSScott Long free(pinfo);
372fc58801cSScott Long }
373fc58801cSScott Long printf(" backs pool %d\n", ffs(spare->HotSparePool) - 1);
374fc58801cSScott Long }
375fc58801cSScott Long for (i = 0; i < nsdisks; i++) {
376fc58801cSScott Long printf(" drive %s ", sdisks[i].devname);
377fc58801cSScott Long print_standalone(&sdisks[i], -1, 0);
378fc58801cSScott Long printf("\n");
379fc58801cSScott Long }
380fc58801cSScott Long free(ioc2);
381fc58801cSScott Long free(ioc5);
382fc58801cSScott Long free(sdisks);
383fc58801cSScott Long close(fd);
384fc58801cSScott Long
385fc58801cSScott Long return (0);
386fc58801cSScott Long }
387fc58801cSScott Long MPT_COMMAND(show, config, show_config);
388fc58801cSScott Long
389fc58801cSScott Long static int
show_volumes(int ac,char ** av)390fc58801cSScott Long show_volumes(int ac, char **av)
391fc58801cSScott Long {
392fc58801cSScott Long CONFIG_PAGE_IOC_2 *ioc2;
393fc58801cSScott Long CONFIG_PAGE_IOC_2_RAID_VOL *vol;
394fc58801cSScott Long CONFIG_PAGE_RAID_VOL_0 **volumes;
395fc58801cSScott Long CONFIG_PAGE_RAID_VOL_1 *vnames;
396c5f2b79dSJohn Baldwin int error, fd, i, len, state_len;
397fc58801cSScott Long
398fc58801cSScott Long if (ac != 1) {
399fc58801cSScott Long warnx("show volumes: extra arguments");
400fc58801cSScott Long return (EINVAL);
401fc58801cSScott Long }
402fc58801cSScott Long
403fc58801cSScott Long fd = mpt_open(mpt_unit);
404fc58801cSScott Long if (fd < 0) {
405c5f2b79dSJohn Baldwin error = errno;
406fc58801cSScott Long warn("mpt_open");
407c5f2b79dSJohn Baldwin return (error);
408fc58801cSScott Long }
409fc58801cSScott Long
410fc58801cSScott Long /* Get the volume list from the controller. */
411fc58801cSScott Long ioc2 = mpt_read_ioc_page(fd, 2, NULL);
412fc58801cSScott Long if (ioc2 == NULL) {
413c5f2b79dSJohn Baldwin error = errno;
414fc58801cSScott Long warn("Failed to get volume list");
415c5f2b79dSJohn Baldwin return (error);
416fc58801cSScott Long }
417fc58801cSScott Long
418fc58801cSScott Long /*
419fc58801cSScott Long * Go ahead and read the info for all the volumes and figure
420fc58801cSScott Long * out the maximum width of the state field.
421fc58801cSScott Long */
422fc58801cSScott Long volumes = malloc(sizeof(*volumes) * ioc2->NumActiveVolumes);
423fc58801cSScott Long state_len = strlen("State");
424fc58801cSScott Long vol = ioc2->RaidVolume;
425fc58801cSScott Long for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
426fc58801cSScott Long volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID,
427fc58801cSScott Long NULL);
428fc58801cSScott Long if (volumes[i] == NULL)
429fc58801cSScott Long len = strlen("UNKNOWN");
430fc58801cSScott Long else
431fc58801cSScott Long len = strlen(mpt_volstate(
432fc58801cSScott Long volumes[i]->VolumeStatus.State));
433fc58801cSScott Long if (len > state_len)
434fc58801cSScott Long state_len = len;
435fc58801cSScott Long }
436fc58801cSScott Long printf("mpt%d Volumes:\n", mpt_unit);
437fc58801cSScott Long printf(" Id Size Level Stripe ");
438fc58801cSScott Long len = state_len - strlen("State");
439fc58801cSScott Long for (i = 0; i < (len + 1) / 2; i++)
440fc58801cSScott Long printf(" ");
441fc58801cSScott Long printf("State");
442fc58801cSScott Long for (i = 0; i < len / 2; i++)
443fc58801cSScott Long printf(" ");
444fc58801cSScott Long printf(" Write-Cache Name\n");
445fc58801cSScott Long vol = ioc2->RaidVolume;
446fc58801cSScott Long for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
447fc58801cSScott Long printf("%6s ", mpt_volume_name(vol->VolumeBus, vol->VolumeID));
448fc58801cSScott Long if (volumes[i] != NULL)
449fc58801cSScott Long print_vol(volumes[i], state_len);
450fc58801cSScott Long else
451fc58801cSScott Long printf(" %-8s %-*s",
452fc58801cSScott Long mpt_raid_level(vol->VolumeType), state_len,
453fc58801cSScott Long "UNKNOWN");
454fc58801cSScott Long if (volumes[i] != NULL) {
455fc58801cSScott Long if (volumes[i]->VolumeSettings.Settings &
456fc58801cSScott Long MPI_RAIDVOL0_SETTING_WRITE_CACHING_ENABLE)
457fc58801cSScott Long printf(" Enabled ");
458fc58801cSScott Long else
459fc58801cSScott Long printf(" Disabled ");
460fc58801cSScott Long } else
461fc58801cSScott Long printf(" ");
462fc58801cSScott Long free(volumes[i]);
463fc58801cSScott Long vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
464fc58801cSScott Long if (vnames != NULL) {
465fc58801cSScott Long if (vnames->Name[0] != '\0')
466fc58801cSScott Long printf(" <%s>", vnames->Name);
467fc58801cSScott Long free(vnames);
468fc58801cSScott Long }
469fc58801cSScott Long printf("\n");
470fc58801cSScott Long }
471d68b76a9SAlan Somers free(volumes);
472fc58801cSScott Long free(ioc2);
473fc58801cSScott Long close(fd);
474fc58801cSScott Long
475fc58801cSScott Long return (0);
476fc58801cSScott Long }
477fc58801cSScott Long MPT_COMMAND(show, volumes, show_volumes);
478fc58801cSScott Long
479fc58801cSScott Long static int
show_drives(int ac,char ** av)480fc58801cSScott Long show_drives(int ac, char **av)
481fc58801cSScott Long {
482fc58801cSScott Long struct mpt_drive_list *list;
483fc58801cSScott Long struct mpt_standalone_disk *sdisks;
484c5f2b79dSJohn Baldwin int error, fd, i, len, nsdisks, state_len;
485fc58801cSScott Long
486fc58801cSScott Long if (ac != 1) {
487fc58801cSScott Long warnx("show drives: extra arguments");
488fc58801cSScott Long return (EINVAL);
489fc58801cSScott Long }
490fc58801cSScott Long
491fc58801cSScott Long fd = mpt_open(mpt_unit);
492fc58801cSScott Long if (fd < 0) {
493c5f2b79dSJohn Baldwin error = errno;
494fc58801cSScott Long warn("mpt_open");
495c5f2b79dSJohn Baldwin return (error);
496fc58801cSScott Long }
497fc58801cSScott Long
498fc58801cSScott Long /* Get the drive list. */
499fc58801cSScott Long list = mpt_pd_list(fd);
500fc58801cSScott Long if (list == NULL) {
501c5f2b79dSJohn Baldwin error = errno;
502d68b76a9SAlan Somers close(fd);
503fc58801cSScott Long warn("Failed to get drive list");
504c5f2b79dSJohn Baldwin return (error);
505fc58801cSScott Long }
506fc58801cSScott Long
507fc58801cSScott Long /* Fetch the list of standalone disks for this controller. */
508fc58801cSScott Long state_len = 0;
509fc58801cSScott Long if (mpt_fetch_disks(fd, &nsdisks, &sdisks) != 0) {
510fc58801cSScott Long nsdisks = 0;
511fc58801cSScott Long sdisks = NULL;
512fc58801cSScott Long }
513fc58801cSScott Long if (nsdisks != 0)
514fc58801cSScott Long state_len = strlen(STANDALONE_STATE);
515fc58801cSScott Long
516fc58801cSScott Long /* Walk the drive list to determine width of state column. */
517fc58801cSScott Long for (i = 0; i < list->ndrives; i++) {
518fc58801cSScott Long len = strlen(mpt_pdstate(list->drives[i]));
519fc58801cSScott Long if (len > state_len)
520fc58801cSScott Long state_len = len;
521fc58801cSScott Long }
522fc58801cSScott Long
523fc58801cSScott Long /* List the drives. */
524fc58801cSScott Long printf("mpt%d Physical Drives:\n", mpt_unit);
525fc58801cSScott Long for (i = 0; i < list->ndrives; i++) {
526fc58801cSScott Long printf("%4u ", list->drives[i]->PhysDiskNum);
527fc58801cSScott Long print_pd(list->drives[i], state_len, 1);
528fc58801cSScott Long printf("\n");
529fc58801cSScott Long }
530fc58801cSScott Long mpt_free_pd_list(list);
531fc58801cSScott Long for (i = 0; i < nsdisks; i++) {
532fc58801cSScott Long printf("%4s ", sdisks[i].devname);
533fc58801cSScott Long print_standalone(&sdisks[i], state_len, 1);
534fc58801cSScott Long printf("\n");
535fc58801cSScott Long }
536fc58801cSScott Long free(sdisks);
537fc58801cSScott Long
538fc58801cSScott Long close(fd);
539fc58801cSScott Long
540fc58801cSScott Long return (0);
541fc58801cSScott Long }
542fc58801cSScott Long MPT_COMMAND(show, drives, show_drives);
543fc58801cSScott Long
544fc58801cSScott Long #ifdef DEBUG
545fc58801cSScott Long static int
show_physdisks(int ac,char ** av)546fc58801cSScott Long show_physdisks(int ac, char **av)
547fc58801cSScott Long {
548fc58801cSScott Long CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
549fc58801cSScott Long U16 IOCStatus;
550af57f4cfSEitan Adler int error, fd, i;
551fc58801cSScott Long
552fc58801cSScott Long if (ac != 1) {
553fc58801cSScott Long warnx("show drives: extra arguments");
554fc58801cSScott Long return (EINVAL);
555fc58801cSScott Long }
556fc58801cSScott Long
557fc58801cSScott Long fd = mpt_open(mpt_unit);
558fc58801cSScott Long if (fd < 0) {
559c5f2b79dSJohn Baldwin error = errno;
560fc58801cSScott Long warn("mpt_open");
561c5f2b79dSJohn Baldwin return (error);
562fc58801cSScott Long }
563fc58801cSScott Long
564fc58801cSScott Long /* Try to find each possible phys disk page. */
565fc58801cSScott Long for (i = 0; i <= 0xff; i++) {
566fc58801cSScott Long pinfo = mpt_pd_info(fd, i, &IOCStatus);
567fc58801cSScott Long if (pinfo == NULL) {
5685f1f6da8SJohn Baldwin if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
5695f1f6da8SJohn Baldwin MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
570fc58801cSScott Long warnx("mpt_pd_info(%d): %s", i,
571fc58801cSScott Long mpt_ioc_status(IOCStatus));
572fc58801cSScott Long continue;
573fc58801cSScott Long }
574fc58801cSScott Long printf("%3u ", i);
575fc58801cSScott Long print_pd(pinfo, -1, 1);
576fc58801cSScott Long printf("\n");
577fc58801cSScott Long }
578fc58801cSScott Long
579fc58801cSScott Long close(fd);
580fc58801cSScott Long
581fc58801cSScott Long return (0);
582fc58801cSScott Long }
583fc58801cSScott Long MPT_COMMAND(show, pd, show_physdisks);
584fc58801cSScott Long #endif
585