2 * Copyright (c) 2008, 2009 Yahoo!, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the authors may not be used to endorse or promote
14 * products derived from this software without specific prior written
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
34 #include <sys/sysctl.h>
50 static void dump_config(int fd, struct mfi_config_data *config);
53 static int add_spare(int ac, char **av);
54 static int remove_spare(int ac, char **av);
57 dehumanize(const char *value)
64 iv = strtoq(value, &vtp, 0);
65 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
85 mfi_config_read(int fd, struct mfi_config_data **configp)
87 struct mfi_config_data *config;
92 * Keep fetching the config in a loop until we have a large enough
93 * buffer to hold the entire configuration.
98 config = reallocf(config, config_size);
101 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_READ, config,
102 config_size, NULL, 0, NULL) < 0) {
109 if (config->size > config_size) {
110 config_size = config->size;
118 static struct mfi_array *
119 mfi_config_lookup_array(struct mfi_config_data *config, uint16_t array_ref)
121 struct mfi_array *ar;
125 p = (char *)config->array;
126 for (i = 0; i < config->array_count; i++) {
127 ar = (struct mfi_array *)p;
128 if (ar->array_ref == array_ref)
130 p += config->array_size;
136 static struct mfi_ld_config *
137 mfi_config_lookup_volume(struct mfi_config_data *config, uint8_t target_id)
139 struct mfi_ld_config *ld;
143 p = (char *)config->array + config->array_count * config->array_size;
144 for (i = 0; i < config->log_drv_count; i++) {
145 ld = (struct mfi_ld_config *)p;
146 if (ld->properties.ld.v.target_id == target_id)
148 p += config->log_drv_size;
155 clear_config(int ac __unused, char **av __unused)
157 struct mfi_ld_list list;
161 fd = mfi_open(mfi_unit, O_RDWR);
168 if (!mfi_reconfig_supported()) {
169 warnx("The current mfi(4) driver does not support "
170 "configuration changes.");
175 if (mfi_ld_get_list(fd, &list, NULL) < 0) {
177 warn("Failed to get volume list");
182 for (i = 0; i < list.ld_count; i++) {
183 if (mfi_volume_busy(fd, list.ld_list[i].ld.v.target_id)) {
184 warnx("Volume %s is busy and cannot be deleted",
185 mfi_volume_name(fd, list.ld_list[i].ld.v.target_id));
192 "Are you sure you wish to clear the configuration on mfi%u? [y/N] ",
195 if (ch != 'y' && ch != 'Y') {
196 printf("\nAborting\n");
201 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_CLEAR, NULL, 0, NULL, 0, NULL) < 0) {
203 warn("Failed to clear configuration");
208 printf("mfi%d: Configuration cleared\n", mfi_unit);
213 MFI_COMMAND(top, clear, clear_config);
215 #define MAX_DRIVES_PER_ARRAY MFI_MAX_ROW_SIZE
216 #define MFI_ARRAY_SIZE sizeof(struct mfi_array)
229 compare_int(const void *one, const void *two)
233 first = *(const int *)one;
234 second = *(const int *)two;
236 return (first - second);
239 static struct raid_type_entry {
242 } raid_type_table[] = {
243 { "raid0", RT_RAID0 },
244 { "raid-0", RT_RAID0 },
245 { "raid1", RT_RAID1 },
246 { "raid-1", RT_RAID1 },
247 { "mirror", RT_RAID1 },
248 { "raid5", RT_RAID5 },
249 { "raid-5", RT_RAID5 },
250 { "raid6", RT_RAID6 },
251 { "raid-6", RT_RAID6 },
253 { "concat", RT_CONCAT },
254 { "raid10", RT_RAID10 },
255 { "raid1+0", RT_RAID10 },
256 { "raid-10", RT_RAID10 },
257 { "raid-1+0", RT_RAID10 },
258 { "raid50", RT_RAID50 },
259 { "raid5+0", RT_RAID50 },
260 { "raid-50", RT_RAID50 },
261 { "raid-5+0", RT_RAID50 },
262 { "raid60", RT_RAID60 },
263 { "raid6+0", RT_RAID60 },
264 { "raid-60", RT_RAID60 },
265 { "raid-6+0", RT_RAID60 },
269 struct config_id_state {
280 struct mfi_pd_info *drives;
281 struct mfi_array *array;
284 /* Parse a comma-separated list of drives for an array. */
286 parse_array(int fd, int raid_type, char *array_str, struct array_info *info)
288 struct mfi_pd_info *pinfo;
295 for (count = 0; cp != NULL; count++) {
296 cp = strchr(cp, ',');
300 warnx("Invalid drive list '%s'", array_str);
306 /* Validate the number of drives for this array. */
307 if (count >= MAX_DRIVES_PER_ARRAY) {
308 warnx("Too many drives for a single array: max is %d",
309 MAX_DRIVES_PER_ARRAY);
315 if (count % 2 != 0) {
316 warnx("RAID1 and RAID10 require an even number of "
317 "drives in each array");
324 warnx("RAID5 and RAID50 require at least 3 drives in "
332 warnx("RAID6 and RAID60 require at least 4 drives in "
339 /* Validate each drive. */
340 info->drives = calloc(count, sizeof(struct mfi_pd_info));
341 if (info->drives == NULL) {
342 warnx("malloc failed");
345 info->drive_count = count;
346 for (pinfo = info->drives; (cp = strsep(&array_str, ",")) != NULL;
348 error = mfi_lookup_drive(fd, cp, &device_id);
355 if (mfi_pd_get_info(fd, device_id, pinfo, NULL) < 0) {
357 warn("Failed to fetch drive info for drive %s", cp);
363 if (pinfo->fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
364 warnx("Drive %u is not available", device_id);
375 * Find the next free array ref assuming that 'array_ref' is the last
376 * one used. 'array_ref' should be 0xffff for the initial test.
379 find_next_array(struct config_id_state *state)
383 /* Assume the current one is used. */
386 /* Find the next free one. */
387 for (i = 0; i < state->array_count; i++)
388 if (state->arrays[i] == state->array_ref)
390 return (state->array_ref);
394 * Find the next free volume ID assuming that 'target_id' is the last
395 * one used. 'target_id' should be 0xff for the initial test.
398 find_next_volume(struct config_id_state *state)
402 /* Assume the current one is used. */
405 /* Find the next free one. */
406 for (i = 0; i < state->log_drv_count; i++)
407 if (state->volumes[i] == state->target_id)
409 return (state->target_id);
412 /* Populate an array with drives. */
414 build_array(int fd __unused, char *arrayp, struct array_info *array_info,
415 struct config_id_state *state, int verbose)
417 struct mfi_array *ar = (struct mfi_array *)arrayp;
420 ar->size = array_info->drives[0].coerced_size;
421 ar->num_drives = array_info->drive_count;
422 ar->array_ref = find_next_array(state);
423 for (i = 0; i < array_info->drive_count; i++) {
425 printf("Adding drive %s to array %u\n",
427 array_info->drives[i].ref.v.device_id,
428 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS),
430 if (ar->size > array_info->drives[i].coerced_size)
431 ar->size = array_info->drives[i].coerced_size;
432 ar->pd[i].ref = array_info->drives[i].ref;
433 ar->pd[i].fw_state = MFI_PD_STATE_ONLINE;
435 array_info->array = ar;
439 * Create a volume that spans one or more arrays.
442 build_volume(char *volumep, int narrays, struct array_info *arrays,
443 int raid_type, long stripe_size, struct config_id_state *state, int verbose)
445 struct mfi_ld_config *ld = (struct mfi_ld_config *)volumep;
446 struct mfi_array *ar;
450 ld->properties.ld.v.target_id = find_next_volume(state);
451 ld->properties.ld.v.seq = 0;
452 ld->properties.default_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
453 MR_LD_CACHE_WRITE_BACK;
454 ld->properties.access_policy = MFI_LD_ACCESS_RW;
455 ld->properties.disk_cache_policy = MR_PD_CACHE_UNCHANGED;
456 ld->properties.current_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
457 MR_LD_CACHE_WRITE_BACK;
458 ld->properties.no_bgi = 0;
464 ld->params.primary_raid_level = DDF_RAID0;
465 ld->params.raid_level_qualifier = 0;
466 ld->params.secondary_raid_level = 0;
469 ld->params.primary_raid_level = DDF_RAID1;
470 ld->params.raid_level_qualifier = 0;
471 ld->params.secondary_raid_level = 0;
474 ld->params.primary_raid_level = DDF_RAID5;
475 ld->params.raid_level_qualifier = 3;
476 ld->params.secondary_raid_level = 0;
479 ld->params.primary_raid_level = DDF_RAID6;
480 ld->params.raid_level_qualifier = 3;
481 ld->params.secondary_raid_level = 0;
484 ld->params.primary_raid_level = DDF_CONCAT;
485 ld->params.raid_level_qualifier = 0;
486 ld->params.secondary_raid_level = 0;
489 ld->params.primary_raid_level = DDF_RAID1;
490 ld->params.raid_level_qualifier = 0;
491 ld->params.secondary_raid_level = 3; /* XXX? */
495 * XXX: This appears to work though the card's BIOS
496 * complains that the configuration is foreign. The
497 * BIOS setup does not allow for creation of RAID-50
498 * or RAID-60 arrays. The only nested array
499 * configuration it allows for is RAID-10.
501 ld->params.primary_raid_level = DDF_RAID5;
502 ld->params.raid_level_qualifier = 3;
503 ld->params.secondary_raid_level = 3; /* XXX? */
506 ld->params.primary_raid_level = DDF_RAID6;
507 ld->params.raid_level_qualifier = 3;
508 ld->params.secondary_raid_level = 3; /* XXX? */
513 * Stripe size is encoded as (2 ^ N) * 512 = stripe_size. Use
514 * ffs() to simulate log2(stripe_size).
516 ld->params.stripe_size = ffs(stripe_size) - 1 - 9;
517 ld->params.num_drives = arrays[0].array->num_drives;
518 ld->params.span_depth = narrays;
519 ld->params.state = MFI_LD_STATE_OPTIMAL;
520 ld->params.init_state = MFI_LD_PARAMS_INIT_NO;
521 ld->params.is_consistent = 0;
524 for (i = 0; i < narrays; i++) {
525 ar = arrays[i].array;
527 printf("Adding array %u to volume %u\n", ar->array_ref,
528 ld->properties.ld.v.target_id);
529 ld->span[i].start_block = 0;
530 ld->span[i].num_blocks = ar->size;
531 ld->span[i].array_ref = ar->array_ref;
536 create_volume(int ac, char **av)
538 struct mfi_config_data *config;
539 struct mfi_array *ar;
540 struct mfi_ld_config *ld;
541 struct config_id_state state;
543 char *p, *cfg_arrays, *cfg_volumes;
544 int error, fd, i, raid_type;
545 int narrays, nvolumes, arrays_per_volume;
546 struct array_info *arrays;
554 * Backwards compat. Map 'create volume' to 'create' and
555 * 'create spare' to 'add'.
558 if (strcmp(av[1], "volume") == 0) {
561 } else if (strcmp(av[1], "spare") == 0) {
564 return (add_spare(ac, av));
569 warnx("create volume: volume type required");
573 bzero(&state, sizeof(state));
579 fd = mfi_open(mfi_unit, O_RDWR);
586 if (!mfi_reconfig_supported()) {
587 warnx("The current mfi(4) driver does not support "
588 "configuration changes.");
593 /* Lookup the RAID type first. */
595 for (i = 0; raid_type_table[i].name != NULL; i++)
596 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
597 raid_type = raid_type_table[i].raid_type;
601 if (raid_type == -1) {
602 warnx("Unknown or unsupported volume type %s", av[1]);
607 /* Parse any options. */
613 stripe_size = 64 * 1024;
615 while ((ch = getopt(ac, av, "ds:v")) != -1) {
623 stripe_size = dehumanize(optarg);
624 if ((stripe_size < 512) || (!powerof2(stripe_size)))
625 stripe_size = 64 * 1024;
639 /* Parse all the arrays. */
642 warnx("At least one drive list is required");
653 warnx("Only one drive list can be specified");
662 warnx("RAID10, RAID50, and RAID60 require at least "
667 if (narrays > MFI_MAX_SPAN_DEPTH) {
668 warnx("Volume spans more than %d arrays",
675 arrays = calloc(narrays, sizeof(*arrays));
676 if (arrays == NULL) {
677 warnx("malloc failed");
681 for (i = 0; i < narrays; i++) {
682 error = parse_array(fd, raid_type, av[i], &arrays[i]);
691 for (i = 1; i < narrays; i++) {
692 if (arrays[i].drive_count != arrays[0].drive_count) {
693 warnx("All arrays must contain the same "
703 * Fetch the current config and build sorted lists of existing
704 * array and volume identifiers.
706 if (mfi_config_read(fd, &config) < 0) {
708 warn("Failed to read configuration");
711 p = (char *)config->array;
712 state.array_ref = 0xffff;
713 state.target_id = 0xff;
714 state.array_count = config->array_count;
715 if (config->array_count > 0) {
716 state.arrays = calloc(config->array_count, sizeof(int));
717 if (state.arrays == NULL) {
718 warnx("malloc failed");
722 for (i = 0; i < config->array_count; i++) {
723 ar = (struct mfi_array *)p;
724 state.arrays[i] = ar->array_ref;
725 p += config->array_size;
727 qsort(state.arrays, config->array_count, sizeof(int),
731 state.log_drv_count = config->log_drv_count;
732 if (config->log_drv_count) {
733 state.volumes = calloc(config->log_drv_count, sizeof(int));
734 if (state.volumes == NULL) {
735 warnx("malloc failed");
739 for (i = 0; i < config->log_drv_count; i++) {
740 ld = (struct mfi_ld_config *)p;
741 state.volumes[i] = ld->properties.ld.v.target_id;
742 p += config->log_drv_size;
744 qsort(state.volumes, config->log_drv_count, sizeof(int),
747 state.volumes = NULL;
750 /* Determine the size of the configuration we will build. */
758 /* Each volume spans a single array. */
764 /* A single volume spans multiple arrays. */
772 config_size = sizeof(struct mfi_config_data) +
773 sizeof(struct mfi_ld_config) * nvolumes + MFI_ARRAY_SIZE * narrays;
774 config = calloc(1, config_size);
775 if (config == NULL) {
776 warnx("malloc failed");
780 config->size = config_size;
781 config->array_count = narrays;
782 config->array_size = MFI_ARRAY_SIZE; /* XXX: Firmware hardcode */
783 config->log_drv_count = nvolumes;
784 config->log_drv_size = sizeof(struct mfi_ld_config);
785 config->spares_count = 0;
786 config->spares_size = 40; /* XXX: Firmware hardcode */
787 cfg_arrays = (char *)config->array;
788 cfg_volumes = cfg_arrays + config->array_size * narrays;
790 /* Build the arrays. */
791 for (i = 0; i < narrays; i++) {
792 build_array(fd, cfg_arrays, &arrays[i], &state, verbose);
793 cfg_arrays += config->array_size;
796 /* Now build the volume(s). */
797 arrays_per_volume = narrays / nvolumes;
798 for (i = 0; i < nvolumes; i++) {
799 build_volume(cfg_volumes, arrays_per_volume,
800 &arrays[i * arrays_per_volume], raid_type, stripe_size,
802 cfg_volumes += config->log_drv_size;
807 dump_config(fd, config);
810 /* Send the new config to the controller. */
811 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_ADD, config, config_size,
812 NULL, 0, NULL) < 0) {
814 warn("Failed to add volume");
823 if (arrays != NULL) {
824 for (i = 0; i < narrays; i++)
825 free(arrays[i].drives);
832 MFI_COMMAND(top, create, create_volume);
835 delete_volume(int ac, char **av)
837 struct mfi_ld_info info;
839 uint8_t target_id, mbox[4];
842 * Backwards compat. Map 'delete volume' to 'delete' and
843 * 'delete spare' to 'remove'.
846 if (strcmp(av[1], "volume") == 0) {
849 } else if (strcmp(av[1], "spare") == 0) {
852 return (remove_spare(ac, av));
857 warnx("delete volume: volume required");
861 fd = mfi_open(mfi_unit, O_RDWR);
868 if (!mfi_reconfig_supported()) {
869 warnx("The current mfi(4) driver does not support "
870 "configuration changes.");
875 if (mfi_lookup_volume(fd, av[1], &target_id) < 0) {
877 warn("Invalid volume %s", av[1]);
882 if (mfi_ld_get_info(fd, target_id, &info, NULL) < 0) {
884 warn("Failed to get info for volume %d", target_id);
889 if (mfi_volume_busy(fd, target_id)) {
890 warnx("Volume %s is busy and cannot be deleted",
891 mfi_volume_name(fd, target_id));
896 mbox_store_ldref(mbox, &info.ld_config.properties.ld);
897 if (mfi_dcmd_command(fd, MFI_DCMD_LD_DELETE, NULL, 0, mbox,
898 sizeof(mbox), NULL) < 0) {
900 warn("Failed to delete volume");
909 MFI_COMMAND(top, delete, delete_volume);
912 add_spare(int ac, char **av)
914 struct mfi_pd_info info;
915 struct mfi_config_data *config;
916 struct mfi_array *ar;
917 struct mfi_ld_config *ld;
918 struct mfi_spare *spare;
925 warnx("add spare: drive required");
929 fd = mfi_open(mfi_unit, O_RDWR);
938 error = mfi_lookup_drive(fd, av[1], &device_id);
942 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
944 warn("Failed to fetch drive info");
948 if (info.fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
949 warnx("Drive %u is not available", device_id);
955 if (mfi_lookup_volume(fd, av[2], &target_id) < 0) {
957 warn("Invalid volume %s", av[2]);
962 if (mfi_config_read(fd, &config) < 0) {
964 warn("Failed to read configuration");
968 spare = malloc(sizeof(struct mfi_spare) + sizeof(uint16_t) *
969 config->array_count);
971 warnx("malloc failed");
975 bzero(spare, sizeof(struct mfi_spare));
976 spare->ref = info.ref;
979 /* Global spare backs all arrays. */
980 p = (char *)config->array;
981 for (i = 0; i < config->array_count; i++) {
982 ar = (struct mfi_array *)p;
983 if (ar->size > info.coerced_size) {
984 warnx("Spare isn't large enough for array %u",
989 p += config->array_size;
991 spare->array_count = 0;
994 * Dedicated spares only back the arrays for a
997 ld = mfi_config_lookup_volume(config, target_id);
999 warnx("Did not find volume %d", target_id);
1004 spare->spare_type |= MFI_SPARE_DEDICATED;
1005 spare->array_count = ld->params.span_depth;
1006 for (i = 0; i < ld->params.span_depth; i++) {
1007 ar = mfi_config_lookup_array(config,
1008 ld->span[i].array_ref);
1010 warnx("Missing array; inconsistent config?");
1014 if (ar->size > info.coerced_size) {
1015 warnx("Spare isn't large enough for array %u",
1020 spare->array_ref[i] = ar->array_ref;
1024 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_MAKE_SPARE, spare,
1025 sizeof(struct mfi_spare) + sizeof(uint16_t) * spare->array_count,
1026 NULL, 0, NULL) < 0) {
1028 warn("Failed to assign spare");
1039 MFI_COMMAND(top, add, add_spare);
1042 remove_spare(int ac, char **av)
1044 struct mfi_pd_info info;
1050 warnx("remove spare: drive required");
1054 fd = mfi_open(mfi_unit, O_RDWR);
1061 error = mfi_lookup_drive(fd, av[1], &device_id);
1067 /* Get the info for this drive. */
1068 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
1070 warn("Failed to fetch info for drive %u", device_id);
1075 if (info.fw_state != MFI_PD_STATE_HOT_SPARE) {
1076 warnx("Drive %u is not a hot spare", device_id);
1081 mbox_store_pdref(mbox, &info.ref);
1082 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_REMOVE_SPARE, NULL, 0, mbox,
1083 sizeof(mbox), NULL) < 0) {
1085 warn("Failed to delete spare");
1094 MFI_COMMAND(top, remove, remove_spare);
1097 /* Display raw data about a config. */
1099 dump_config(int fd, struct mfi_config_data *config)
1101 struct mfi_array *ar;
1102 struct mfi_ld_config *ld;
1103 struct mfi_spare *sp;
1104 struct mfi_pd_info pinfo;
1110 "mfi%d Configuration (Debug): %d arrays, %d volumes, %d spares\n",
1111 mfi_unit, config->array_count, config->log_drv_count,
1112 config->spares_count);
1113 printf(" array size: %u\n", config->array_size);
1114 printf(" volume size: %u\n", config->log_drv_size);
1115 printf(" spare size: %u\n", config->spares_size);
1116 p = (char *)config->array;
1118 for (i = 0; i < config->array_count; i++) {
1119 ar = (struct mfi_array *)p;
1120 printf(" array %u of %u drives:\n", ar->array_ref,
1122 printf(" size = %ju\n", (uintmax_t)ar->size);
1123 for (j = 0; j < ar->num_drives; j++) {
1124 device_id = ar->pd[j].ref.v.device_id;
1125 if (device_id == 0xffff)
1126 printf(" drive MISSING\n");
1128 printf(" drive %u %s\n", device_id,
1129 mfi_pdstate(ar->pd[j].fw_state));
1130 if (mfi_pd_get_info(fd, device_id, &pinfo,
1132 printf(" raw size: %ju\n",
1133 (uintmax_t)pinfo.raw_size);
1134 printf(" non-coerced size: %ju\n",
1135 (uintmax_t)pinfo.non_coerced_size);
1136 printf(" coerced size: %ju\n",
1137 (uintmax_t)pinfo.coerced_size);
1141 p += config->array_size;
1144 for (i = 0; i < config->log_drv_count; i++) {
1145 ld = (struct mfi_ld_config *)p;
1146 printf(" volume %s ",
1147 mfi_volume_name(fd, ld->properties.ld.v.target_id));
1149 mfi_raid_level(ld->params.primary_raid_level,
1150 ld->params.secondary_raid_level),
1151 mfi_ldstate(ld->params.state));
1152 if (ld->properties.name[0] != '\0')
1153 printf(" <%s>", ld->properties.name);
1155 printf(" primary raid level: %u\n",
1156 ld->params.primary_raid_level);
1157 printf(" raid level qualifier: %u\n",
1158 ld->params.raid_level_qualifier);
1159 printf(" secondary raid level: %u\n",
1160 ld->params.secondary_raid_level);
1161 printf(" stripe size: %u\n", ld->params.stripe_size);
1162 printf(" num drives: %u\n", ld->params.num_drives);
1163 printf(" init state: %u\n", ld->params.init_state);
1164 printf(" consistent: %u\n", ld->params.is_consistent);
1165 printf(" no bgi: %u\n", ld->properties.no_bgi);
1166 printf(" spans:\n");
1167 for (j = 0; j < ld->params.span_depth; j++) {
1168 printf(" array %u @ ", ld->span[j].array_ref);
1169 printf("%ju : %ju\n",
1170 (uintmax_t)ld->span[j].start_block,
1171 (uintmax_t)ld->span[j].num_blocks);
1173 p += config->log_drv_size;
1176 for (i = 0; i < config->spares_count; i++) {
1177 sp = (struct mfi_spare *)p;
1178 printf(" %s spare %u ",
1179 sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" :
1180 "global", sp->ref.v.device_id);
1181 printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE));
1182 printf(" backs:\n");
1183 for (j = 0; j < sp->array_count; j++)
1184 printf(" array %u\n", sp->array_ref[j]);
1185 p += config->spares_size;
1190 debug_config(int ac, char **av)
1192 struct mfi_config_data *config;
1196 warnx("debug: extra arguments");
1200 fd = mfi_open(mfi_unit, O_RDWR);
1207 /* Get the config from the controller. */
1208 if (mfi_config_read(fd, &config) < 0) {
1210 warn("Failed to get config");
1215 /* Dump out the configuration. */
1216 dump_config(fd, config);
1222 MFI_COMMAND(top, debug, debug_config);
1225 dump(int ac, char **av)
1227 struct mfi_config_data *config;
1233 warnx("dump: extra arguments");
1237 fd = mfi_open(mfi_unit, O_RDWR);
1244 /* Get the stashed copy of the last dcmd from the driver. */
1245 snprintf(buf, sizeof(buf), "dev.mfi.%d.debug_command", mfi_unit);
1246 if (sysctlbyname(buf, NULL, &len, NULL, 0) < 0) {
1248 warn("Failed to read debug command");
1249 if (error == ENOENT)
1255 config = malloc(len);
1256 if (config == NULL) {
1257 warnx("malloc failed");
1261 if (sysctlbyname(buf, config, &len, NULL, 0) < 0) {
1263 warn("Failed to read debug command");
1268 dump_config(fd, config);
1274 MFI_COMMAND(top, dump, dump);