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/types.h>
33 #include <sys/errno.h>
46 format_stripe(char *buf, size_t buflen, uint8_t stripe)
49 humanize_number(buf, buflen, (1 << stripe) * 512, "", HN_AUTOSCALE,
54 show_adapter(int ac, char **av __unused)
56 struct mfi_ctrl_info info;
61 warnx("show adapter: extra arguments");
65 fd = mfi_open(mfi_unit, O_RDONLY);
72 if (mfi_ctrl_get_info(fd, &info, NULL) < 0) {
74 warn("Failed to get controller info");
78 printf("mfi%d Adapter:\n", mfi_unit);
79 printf(" Product Name: %.80s\n", info.product_name);
80 printf(" Serial Number: %.32s\n", info.serial_number);
81 if (info.package_version[0] != '\0')
82 printf(" Firmware: %s\n", info.package_version);
83 printf(" RAID Levels:");
85 printf(" (%#x)", info.raid_levels);
88 if (info.raid_levels & MFI_INFO_RAID_0) {
89 printf(" JBOD, RAID0");
92 if (info.raid_levels & MFI_INFO_RAID_1) {
93 printf("%s RAID1", comma ? "," : "");
96 if (info.raid_levels & MFI_INFO_RAID_5) {
97 printf("%s RAID5", comma ? "," : "");
100 if (info.raid_levels & MFI_INFO_RAID_1E) {
101 printf("%s RAID1E", comma ? "," : "");
104 if (info.raid_levels & MFI_INFO_RAID_6) {
105 printf("%s RAID6", comma ? "," : "");
108 if ((info.raid_levels & (MFI_INFO_RAID_0 | MFI_INFO_RAID_1)) ==
109 (MFI_INFO_RAID_0 | MFI_INFO_RAID_1)) {
110 printf("%s RAID10", comma ? "," : "");
113 if ((info.raid_levels & (MFI_INFO_RAID_0 | MFI_INFO_RAID_5)) ==
114 (MFI_INFO_RAID_0 | MFI_INFO_RAID_5)) {
115 printf("%s RAID50", comma ? "," : "");
119 printf(" Battery Backup: ");
120 if (info.hw_present & MFI_INFO_HW_BBU)
123 printf("not present\n");
124 if (info.hw_present & MFI_INFO_HW_NVRAM)
125 printf(" NVRAM: %uK\n", info.nvram_size);
126 printf(" Onboard Memory: %uM\n", info.memory_size);
127 format_stripe(stripe, sizeof(stripe), info.stripe_sz_ops.min);
128 printf(" Minimum Stripe: %s\n", stripe);
129 format_stripe(stripe, sizeof(stripe), info.stripe_sz_ops.max);
130 printf(" Maximum Stripe: %s\n", stripe);
136 MFI_COMMAND(show, adapter, show_adapter);
139 show_battery(int ac, char **av __unused)
141 struct mfi_bbu_capacity_info cap;
142 struct mfi_bbu_design_info design;
143 struct mfi_bbu_properties props;
144 struct mfi_bbu_status stat;
146 int comma, error, fd, show_capacity, show_props;
150 warnx("show battery: extra arguments");
154 fd = mfi_open(mfi_unit, O_RDONLY);
161 if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_CAPACITY_INFO, &cap,
162 sizeof(cap), NULL, 0, &status) < 0) {
164 warn("Failed to get capacity info");
168 if (status == MFI_STAT_NO_HW_PRESENT) {
169 printf("mfi%d: No battery present\n", mfi_unit);
173 show_capacity = (status == MFI_STAT_OK);
175 if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_DESIGN_INFO, &design,
176 sizeof(design), NULL, 0, NULL) < 0) {
178 warn("Failed to get design info");
183 if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_STATUS, &stat, sizeof(stat),
184 NULL, 0, NULL) < 0) {
186 warn("Failed to get status");
191 if (mfi_bbu_get_props(fd, &props, &status) < 0) {
193 warn("Failed to get properties");
197 show_props = (status == MFI_STAT_OK);
199 printf("mfi%d: Battery State:\n", mfi_unit);
200 printf(" Manufacture Date: %d/%d/%d\n", design.mfg_date >> 5 & 0x0f,
201 design.mfg_date & 0x1f, design.mfg_date >> 9 & 0xffff);
202 printf(" Serial Number: %d\n", design.serial_number);
203 printf(" Manufacturer: %s\n", design.mfg_name);
204 printf(" Model: %s\n", design.device_name);
205 printf(" Chemistry: %s\n", design.device_chemistry);
206 printf(" Design Capacity: %d mAh\n", design.design_capacity);
208 printf(" Full Charge Capacity: %d mAh\n",
209 cap.full_charge_capacity);
210 printf(" Current Capacity: %d mAh\n",
211 cap.remaining_capacity);
212 printf(" Charge Cycles: %d\n", cap.cycle_count);
213 printf(" Current Charge: %d%%\n", cap.relative_charge);
215 printf(" Design Voltage: %d mV\n", design.design_voltage);
216 printf(" Current Voltage: %d mV\n", stat.voltage);
217 printf(" Temperature: %d C\n", stat.temperature);
219 mfi_autolearn_period(props.auto_learn_period, buf, sizeof(buf));
220 printf(" Autolearn period: %s\n", buf);
221 if (props.auto_learn_mode != 0)
222 snprintf(buf, sizeof(buf), "never");
224 mfi_next_learn_time(props.next_learn_time, buf,
226 printf(" Next learn time: %s\n", buf);
227 printf(" Learn delay interval: %u hour%s\n",
228 props.learn_delay_interval,
229 props.learn_delay_interval != 1 ? "s" : "");
230 mfi_autolearn_mode(props.auto_learn_mode, buf, sizeof(buf));
231 printf(" Autolearn mode: %s\n", buf);
232 if (props.bbu_mode != 0)
233 printf(" BBU Mode: %d\n", props.bbu_mode);
237 if (stat.fw_status & MFI_BBU_STATE_PACK_MISSING) {
238 printf(" PACK_MISSING");
241 if (stat.fw_status & MFI_BBU_STATE_VOLTAGE_LOW) {
242 printf("%s VOLTAGE_LOW", comma ? "," : "");
245 if (stat.fw_status & MFI_BBU_STATE_TEMPERATURE_HIGH) {
246 printf("%s TEMPERATURE_HIGH", comma ? "," : "");
249 if (stat.fw_status & MFI_BBU_STATE_CHARGE_ACTIVE) {
250 printf("%s CHARGING", comma ? "," : "");
253 if (stat.fw_status & MFI_BBU_STATE_DISCHARGE_ACTIVE) {
254 printf("%s DISCHARGING", comma ? "," : "");
257 if (stat.fw_status & MFI_BBU_STATE_LEARN_CYC_REQ) {
258 printf("%s LEARN_CYCLE_REQUESTED", comma ? "," : "");
261 if (stat.fw_status & MFI_BBU_STATE_LEARN_CYC_ACTIVE) {
262 printf("%s LEARN_CYCLE_ACTIVE", comma ? "," : "");
265 if (stat.fw_status & MFI_BBU_STATE_LEARN_CYC_FAIL) {
266 printf("%s LEARN_CYCLE_FAIL", comma ? "," : "");
269 if (stat.fw_status & MFI_BBU_STATE_LEARN_CYC_TIMEOUT) {
270 printf("%s LEARN_CYCLE_TIMEOUT", comma ? "," : "");
273 if (stat.fw_status & MFI_BBU_STATE_I2C_ERR_DETECT) {
274 printf("%s I2C_ERROR_DETECT", comma ? "," : "");
281 switch (stat.battery_type) {
282 case MFI_BBU_TYPE_BBU:
283 printf(" State of Health: %s\n",
284 stat.detail.bbu.is_SOH_good ? "good" : "bad");
292 MFI_COMMAND(show, battery, show_battery);
295 print_ld(struct mfi_ld_info *info, int state_len)
297 struct mfi_ld_params *params = &info->ld_config.params;
299 char size[6], stripe[5];
301 humanize_number(size, sizeof(size), info->size * 512,
302 "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
303 format_stripe(stripe, sizeof(stripe),
304 info->ld_config.params.stripe_size);
305 level = mfi_raid_level(params->primary_raid_level,
306 params->secondary_raid_level);
308 printf("(%6s) %-8s %6s %-*s", size, level, stripe, state_len,
309 mfi_ldstate(params->state));
311 printf("(%s) %s %s %s", size, level, stripe,
312 mfi_ldstate(params->state));
316 print_pd(struct mfi_pd_info *info, int state_len)
321 humanize_number(buf, sizeof(buf), info->raw_size * 512, "",
322 HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
323 printf("(%6s) ", buf);
325 printf("%-*s", state_len, mfi_pdstate(info->fw_state));
327 printf("%s", mfi_pdstate(info->fw_state));
328 s = mfi_pd_inq_string(info);
334 show_config(int ac, char **av __unused)
336 struct mfi_config_data *config;
337 struct mfi_array *ar;
338 struct mfi_ld_config *ld;
339 struct mfi_spare *sp;
340 struct mfi_ld_info linfo;
341 struct mfi_pd_info pinfo;
347 warnx("show config: extra arguments");
351 fd = mfi_open(mfi_unit, O_RDONLY);
358 /* Get the config from the controller. */
359 if (mfi_config_read(fd, &config) < 0) {
361 warn("Failed to get config");
366 /* Dump out the configuration. */
367 printf("mfi%d Configuration: %d arrays, %d volumes, %d spares\n",
368 mfi_unit, config->array_count, config->log_drv_count,
369 config->spares_count);
370 p = (char *)config->array;
372 for (i = 0; i < config->array_count; i++) {
373 ar = (struct mfi_array *)p;
374 printf(" array %u of %u drives:\n", ar->array_ref,
376 for (j = 0; j < ar->num_drives; j++) {
377 device_id = ar->pd[j].ref.v.device_id;
378 printf(" drive %s ", mfi_drive_name(NULL,
380 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
381 if (device_id != 0xffff) {
382 if (mfi_pd_get_info(fd, device_id, &pinfo,
385 mfi_pdstate(ar->pd[j].fw_state));
387 print_pd(&pinfo, -1);
391 p += config->array_size;
394 for (i = 0; i < config->log_drv_count; i++) {
395 ld = (struct mfi_ld_config *)p;
396 printf(" volume %s ",
397 mfi_volume_name(fd, ld->properties.ld.v.target_id));
398 if (mfi_ld_get_info(fd, ld->properties.ld.v.target_id, &linfo,
401 mfi_raid_level(ld->params.primary_raid_level,
402 ld->params.secondary_raid_level),
403 mfi_ldstate(ld->params.state));
405 print_ld(&linfo, -1);
406 if (ld->properties.name[0] != '\0')
407 printf(" <%s>", ld->properties.name);
409 for (j = 0; j < ld->params.span_depth; j++)
410 printf(" array %u\n", ld->span[j].array_ref);
411 p += config->log_drv_size;
414 for (i = 0; i < config->spares_count; i++) {
415 sp = (struct mfi_spare *)p;
416 printf(" %s spare %s ",
417 sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" :
418 "global", mfi_drive_name(NULL, sp->ref.v.device_id,
419 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
420 if (mfi_pd_get_info(fd, sp->ref.v.device_id, &pinfo, NULL) < 0)
421 printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE));
423 print_pd(&pinfo, -1);
424 if (sp->spare_type & MFI_SPARE_DEDICATED) {
426 for (j = 0; j < sp->array_count; j++)
427 printf(" array %u\n", sp->array_ref[j]);
430 p += config->spares_size;
437 MFI_COMMAND(show, config, show_config);
440 show_volumes(int ac, char **av __unused)
442 struct mfi_ld_list list;
443 struct mfi_ld_info info;
445 u_int i, len, state_len;
448 warnx("show volumes: extra arguments");
452 fd = mfi_open(mfi_unit, O_RDONLY);
459 /* Get the logical drive list from the controller. */
460 if (mfi_ld_get_list(fd, &list, NULL) < 0) {
462 warn("Failed to get volume list");
467 /* List the volumes. */
468 printf("mfi%d Volumes:\n", mfi_unit);
469 state_len = strlen("State");
470 for (i = 0; i < list.ld_count; i++) {
471 len = strlen(mfi_ldstate(list.ld_list[i].state));
475 printf(" Id Size Level Stripe ");
476 len = state_len - strlen("State");
477 for (i = 0; i < (len + 1) / 2; i++)
480 for (i = 0; i < len / 2; i++)
482 printf(" Cache Name\n");
483 for (i = 0; i < list.ld_count; i++) {
484 if (mfi_ld_get_info(fd, list.ld_list[i].ld.v.target_id, &info,
487 warn("Failed to get info for volume %d",
488 list.ld_list[i].ld.v.target_id);
493 mfi_volume_name(fd, list.ld_list[i].ld.v.target_id));
494 print_ld(&info, state_len);
495 switch (info.ld_config.properties.current_cache_policy &
496 (MR_LD_CACHE_ALLOW_WRITE_CACHE |
497 MR_LD_CACHE_ALLOW_READ_CACHE)) {
501 case MR_LD_CACHE_ALLOW_READ_CACHE:
504 case MR_LD_CACHE_ALLOW_WRITE_CACHE:
507 case MR_LD_CACHE_ALLOW_WRITE_CACHE |
508 MR_LD_CACHE_ALLOW_READ_CACHE:
512 if (info.ld_config.properties.name[0] != '\0')
513 printf(" <%s>", info.ld_config.properties.name);
520 MFI_COMMAND(show, volumes, show_volumes);
523 show_drives(int ac, char **av __unused)
525 struct mfi_pd_list *list;
526 struct mfi_pd_info info;
527 u_int i, len, state_len;
531 warnx("show drives: extra arguments");
535 fd = mfi_open(mfi_unit, O_RDONLY);
543 if (mfi_pd_get_list(fd, &list, NULL) < 0) {
545 warn("Failed to get drive list");
549 /* Walk the list of drives to determine width of state column. */
551 for (i = 0; i < list->count; i++) {
552 if (list->addr[i].scsi_dev_type != 0)
555 if (mfi_pd_get_info(fd, list->addr[i].device_id, &info,
558 warn("Failed to fetch info for drive %u",
559 list->addr[i].device_id);
562 len = strlen(mfi_pdstate(info.fw_state));
567 /* List the drives. */
568 printf("mfi%d Physical Drives:\n", mfi_unit);
569 for (i = 0; i < list->count; i++) {
571 /* Skip non-hard disks. */
572 if (list->addr[i].scsi_dev_type != 0)
575 /* Fetch details for this drive. */
576 if (mfi_pd_get_info(fd, list->addr[i].device_id, &info,
579 warn("Failed to fetch info for drive %u",
580 list->addr[i].device_id);
584 printf("%s ", mfi_drive_name(&info, list->addr[i].device_id,
585 MFI_DNAME_DEVICE_ID));
586 print_pd(&info, state_len);
587 printf(" %s", mfi_drive_name(&info, list->addr[i].device_id,
598 MFI_COMMAND(show, drives, show_drives);
600 int fw_name_width, fw_version_width, fw_date_width, fw_time_width;
603 scan_firmware(struct mfi_info_component *comp)
607 len = strlen(comp->name);
608 if (fw_name_width < len)
610 len = strlen(comp->version);
611 if (fw_version_width < len)
612 fw_version_width = len;
613 len = strlen(comp->build_date);
614 if (fw_date_width < len)
616 len = strlen(comp->build_time);
617 if (fw_time_width < len)
622 display_firmware(struct mfi_info_component *comp, const char *tag)
625 printf("%-*s %-*s %-*s %-*s %s\n", fw_name_width, comp->name,
626 fw_version_width, comp->version, fw_date_width, comp->build_date,
627 fw_time_width, comp->build_time, tag);
631 show_firmware(int ac, char **av __unused)
633 struct mfi_ctrl_info info;
634 struct mfi_info_component header;
639 warnx("show firmware: extra arguments");
643 fd = mfi_open(mfi_unit, O_RDONLY);
650 if (mfi_ctrl_get_info(fd, &info, NULL) < 0) {
652 warn("Failed to get controller info");
657 if (info.package_version[0] != '\0')
658 printf("mfi%d Firmware Package Version: %s\n", mfi_unit,
659 info.package_version);
660 printf("mfi%d Firmware Images:\n", mfi_unit);
661 strcpy(header.name, "Name");
662 strcpy(header.version, "Version");
663 strcpy(header.build_date, "Date");
664 strcpy(header.build_time, "Time");
665 scan_firmware(&header);
666 if (info.image_component_count > 8)
667 info.image_component_count = 8;
668 for (i = 0; i < info.image_component_count; i++)
669 scan_firmware(&info.image_component[i]);
670 if (info.pending_image_component_count > 8)
671 info.pending_image_component_count = 8;
672 for (i = 0; i < info.pending_image_component_count; i++)
673 scan_firmware(&info.pending_image_component[i]);
674 display_firmware(&header, "Status");
675 for (i = 0; i < info.image_component_count; i++)
676 display_firmware(&info.image_component[i], "active");
677 for (i = 0; i < info.pending_image_component_count; i++)
678 display_firmware(&info.pending_image_component[i], "pending");
684 MFI_COMMAND(show, firmware, show_firmware);
687 show_progress(int ac, char **av __unused)
689 struct mfi_ld_list llist;
690 struct mfi_pd_list *plist;
691 struct mfi_ld_info linfo;
692 struct mfi_pd_info pinfo;
699 warnx("show progress: extra arguments");
703 fd = mfi_open(mfi_unit, O_RDONLY);
710 if (mfi_ld_get_list(fd, &llist, NULL) < 0) {
712 warn("Failed to get volume list");
716 if (mfi_pd_get_list(fd, &plist, NULL) < 0) {
718 warn("Failed to get drive list");
724 for (i = 0; i < llist.ld_count; i++) {
725 target_id = llist.ld_list[i].ld.v.target_id;
726 if (mfi_ld_get_info(fd, target_id, &linfo, NULL) < 0) {
728 warn("Failed to get info for volume %s",
729 mfi_volume_name(fd, target_id));
734 if (linfo.progress.active & MFI_LD_PROGRESS_CC) {
735 printf("volume %s ", mfi_volume_name(fd, target_id));
736 mfi_display_progress("Consistency Check",
740 if (linfo.progress.active & MFI_LD_PROGRESS_BGI) {
741 printf("volume %s ", mfi_volume_name(fd, target_id));
742 mfi_display_progress("Background Init",
743 &linfo.progress.bgi);
746 if (linfo.progress.active & MFI_LD_PROGRESS_FGI) {
747 printf("volume %s ", mfi_volume_name(fd, target_id));
748 mfi_display_progress("Foreground Init",
749 &linfo.progress.fgi);
752 if (linfo.progress.active & MFI_LD_PROGRESS_RECON) {
753 printf("volume %s ", mfi_volume_name(fd, target_id));
754 mfi_display_progress("Reconstruction",
755 &linfo.progress.recon);
760 for (i = 0; i < plist->count; i++) {
761 if (plist->addr[i].scsi_dev_type != 0)
764 device_id = plist->addr[i].device_id;
765 if (mfi_pd_get_info(fd, device_id, &pinfo, NULL) < 0) {
767 warn("Failed to fetch info for drive %u", device_id);
773 if (pinfo.prog_info.active & MFI_PD_PROGRESS_REBUILD) {
774 printf("drive %s ", mfi_drive_name(NULL, device_id,
775 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
776 mfi_display_progress("Rebuild", &pinfo.prog_info.rbld);
779 if (pinfo.prog_info.active & MFI_PD_PROGRESS_PATROL) {
780 printf("drive %s ", mfi_drive_name(NULL, device_id,
781 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
782 mfi_display_progress("Patrol Read",
783 &pinfo.prog_info.patrol);
786 if (pinfo.prog_info.active & MFI_PD_PROGRESS_CLEAR) {
787 printf("drive %s ", mfi_drive_name(NULL, device_id,
788 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
789 mfi_display_progress("Clear", &pinfo.prog_info.clear);
798 printf("No activity in progress for adapter mfi%d\n", mfi_unit);
802 MFI_COMMAND(show, progress, show_progress);