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>
45 format_stripe(char *buf, size_t buflen, uint8_t stripe)
48 humanize_number(buf, buflen, (1 << stripe) * 512, "", HN_AUTOSCALE,
53 show_adapter(int ac, char **av)
55 struct mfi_ctrl_info info;
60 warnx("show adapter: extra arguments");
64 fd = mfi_open(mfi_unit);
70 if (mfi_ctrl_get_info(fd, &info, NULL) < 0) {
71 warn("Failed to get controller info");
74 printf("mfi%d Adapter:\n", mfi_unit);
75 printf(" Product Name: %.80s\n", info.product_name);
76 printf(" Serial Number: %.32s\n", info.serial_number);
77 if (info.package_version[0] != '\0')
78 printf(" Firmware: %s\n", info.package_version);
79 printf(" RAID Levels:");
81 printf(" (%#x)", info.raid_levels);
84 if (info.raid_levels & MFI_INFO_RAID_0) {
85 printf(" JBOD, RAID0");
88 if (info.raid_levels & MFI_INFO_RAID_1) {
89 printf("%s RAID1", comma ? "," : "");
92 if (info.raid_levels & MFI_INFO_RAID_5) {
93 printf("%s RAID5", comma ? "," : "");
96 if (info.raid_levels & MFI_INFO_RAID_1E) {
97 printf("%s RAID1E", comma ? "," : "");
100 if (info.raid_levels & MFI_INFO_RAID_6) {
101 printf("%s RAID6", comma ? "," : "");
104 if ((info.raid_levels & (MFI_INFO_RAID_0 | MFI_INFO_RAID_1)) ==
105 (MFI_INFO_RAID_0 | MFI_INFO_RAID_1)) {
106 printf("%s RAID10", comma ? "," : "");
109 if ((info.raid_levels & (MFI_INFO_RAID_0 | MFI_INFO_RAID_5)) ==
110 (MFI_INFO_RAID_0 | MFI_INFO_RAID_5)) {
111 printf("%s RAID50", comma ? "," : "");
115 printf(" Battery Backup: ");
116 if (info.hw_present & MFI_INFO_HW_BBU)
119 printf("not present\n");
120 if (info.hw_present & MFI_INFO_HW_NVRAM)
121 printf(" NVRAM: %uK\n", info.nvram_size);
122 printf(" Onboard Memory: %uM\n", info.memory_size);
123 format_stripe(stripe, sizeof(stripe), info.stripe_sz_ops.min);
124 printf(" Minimum Stripe: %s\n", stripe);
125 format_stripe(stripe, sizeof(stripe), info.stripe_sz_ops.max);
126 printf(" Maximum Stripe: %s\n", stripe);
132 MFI_COMMAND(show, adapter, show_adapter);
135 show_battery(int ac, char **av)
137 struct mfi_bbu_capacity_info cap;
138 struct mfi_bbu_design_info design;
143 warnx("show battery: extra arguments");
147 fd = mfi_open(mfi_unit);
153 if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_CAPACITY_INFO, &cap,
154 sizeof(cap), NULL, 0, &status) < 0) {
155 if (status == MFI_STAT_NO_HW_PRESENT) {
156 printf("mfi%d: No battery present\n", mfi_unit);
159 warn("Failed to get capacity info");
163 if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_DESIGN_INFO, &design,
164 sizeof(design), NULL, 0, NULL) < 0) {
165 warn("Failed to get design info");
169 printf("mfi%d: Battery State:\n", mfi_unit);
170 printf(" Manufacture Date: %d/%d/%d\n", design.mfg_date >> 5 & 0x0f,
171 design.mfg_date & 0x1f, design.mfg_date >> 9 & 0xffff);
172 printf(" Serial Number: %d\n", design.serial_number);
173 printf(" Manufacturer: %s\n", design.mfg_name);
174 printf(" Model: %s\n", design.device_name);
175 printf(" Chemistry: %s\n", design.device_chemistry);
176 printf(" Design Capacity: %d mAh\n", design.design_capacity);
177 printf(" Design Voltage: %d mV\n", design.design_voltage);
178 printf(" Current Charge: %d%%\n", cap.relative_charge);
184 MFI_COMMAND(show, battery, show_battery);
187 print_ld(struct mfi_ld_info *info, int state_len)
189 struct mfi_ld_params *params = &info->ld_config.params;
191 char size[6], stripe[5];
193 humanize_number(size, sizeof(size), info->size * 512,
194 "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
195 format_stripe(stripe, sizeof(stripe),
196 info->ld_config.params.stripe_size);
197 level = mfi_raid_level(params->primary_raid_level,
198 params->secondary_raid_level);
200 printf("(%6s) %-8s %6s %-*s", size, level, stripe, state_len,
201 mfi_ldstate(params->state));
203 printf("(%s) %s %s %s", size, level, stripe,
204 mfi_ldstate(params->state));
208 print_pd(struct mfi_pd_info *info, int state_len, int location)
213 humanize_number(buf, sizeof(buf), info->raw_size * 512, "",
214 HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
215 printf("(%6s) ", buf);
217 printf("%-*s", state_len, mfi_pdstate(info->fw_state));
219 printf("%s", mfi_pdstate(info->fw_state));
220 s = mfi_pd_inq_string(info);
225 if (info->encl_device_id == 0xffff)
226 printf(" slot %d", info->slot_number);
227 else if (info->encl_device_id == info->ref.v.device_id)
228 printf(" enclosure %d", info->encl_index);
230 printf(" enclosure %d, slot %d", info->encl_index,
235 show_config(int ac, char **av)
237 struct mfi_config_data *config;
238 struct mfi_array *ar;
239 struct mfi_ld_config *ld;
240 struct mfi_spare *sp;
241 struct mfi_ld_info linfo;
242 struct mfi_pd_info pinfo;
248 warnx("show config: extra arguments");
252 fd = mfi_open(mfi_unit);
258 /* Get the config from the controller. */
259 if (mfi_config_read(fd, &config) < 0) {
260 warn("Failed to get config");
264 /* Dump out the configuration. */
265 printf("mfi%d Configuration: %d arrays, %d volumes, %d spares\n",
266 mfi_unit, config->array_count, config->log_drv_count,
267 config->spares_count);
268 p = (char *)config->array;
270 for (i = 0; i < config->array_count; i++) {
271 ar = (struct mfi_array *)p;
272 printf(" array %u of %u drives:\n", ar->array_ref,
274 for (j = 0; j < ar->num_drives; j++) {
275 device_id = ar->pd[j].ref.v.device_id;
276 if (device_id == 0xffff)
277 printf(" drive MISSING\n");
279 printf(" drive %u ", device_id);
280 if (mfi_pd_get_info(fd, device_id, &pinfo,
283 mfi_pdstate(ar->pd[j].fw_state));
285 print_pd(&pinfo, -1, 1);
289 p += config->array_size;
292 for (i = 0; i < config->log_drv_count; i++) {
293 ld = (struct mfi_ld_config *)p;
294 printf(" volume %s ",
295 mfi_volume_name(fd, ld->properties.ld.v.target_id));
296 if (mfi_ld_get_info(fd, ld->properties.ld.v.target_id, &linfo,
299 mfi_raid_level(ld->params.primary_raid_level,
300 ld->params.secondary_raid_level),
301 mfi_ldstate(ld->params.state));
303 print_ld(&linfo, -1);
304 if (ld->properties.name[0] != '\0')
305 printf(" <%s>", ld->properties.name);
307 for (j = 0; j < ld->params.span_depth; j++)
308 printf(" array %u\n", ld->span[j].array_ref);
309 p += config->log_drv_size;
312 for (i = 0; i < config->spares_count; i++) {
313 sp = (struct mfi_spare *)p;
314 printf(" %s spare %u ",
315 sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" :
316 "global", sp->ref.v.device_id);
317 if (mfi_pd_get_info(fd, sp->ref.v.device_id, &pinfo, NULL) < 0)
318 printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE));
320 print_pd(&pinfo, -1, 1);
321 if (sp->spare_type & MFI_SPARE_DEDICATED) {
323 for (j = 0; j < sp->array_count; j++)
324 printf(" array %u\n", sp->array_ref[j]);
327 p += config->spares_size;
333 MFI_COMMAND(show, config, show_config);
336 show_volumes(int ac, char **av)
338 struct mfi_ld_list list;
339 struct mfi_ld_info info;
340 u_int i, len, state_len;
344 warnx("show volumes: extra arguments");
348 fd = mfi_open(mfi_unit);
354 /* Get the logical drive list from the controller. */
355 if (mfi_ld_get_list(fd, &list, NULL) < 0) {
356 warn("Failed to get volume list");
360 /* List the volumes. */
361 printf("mfi%d Volumes:\n", mfi_unit);
362 state_len = strlen("State");
363 for (i = 0; i < list.ld_count; i++) {
364 len = strlen(mfi_ldstate(list.ld_list[i].state));
368 printf(" Id Size Level Stripe ");
369 len = state_len - strlen("State");
370 for (i = 0; i < (len + 1) / 2; i++)
373 for (i = 0; i < len / 2; i++)
375 printf(" Cache Name\n");
376 for (i = 0; i < list.ld_count; i++) {
377 if (mfi_ld_get_info(fd, list.ld_list[i].ld.v.target_id, &info,
379 warn("Failed to get info for volume %d",
380 list.ld_list[i].ld.v.target_id);
384 mfi_volume_name(fd, list.ld_list[i].ld.v.target_id));
385 print_ld(&info, state_len);
386 switch (info.ld_config.properties.current_cache_policy &
387 (MR_LD_CACHE_ALLOW_WRITE_CACHE |
388 MR_LD_CACHE_ALLOW_READ_CACHE)) {
392 case MR_LD_CACHE_ALLOW_READ_CACHE:
395 case MR_LD_CACHE_ALLOW_WRITE_CACHE:
398 case MR_LD_CACHE_ALLOW_WRITE_CACHE |
399 MR_LD_CACHE_ALLOW_READ_CACHE:
403 if (info.ld_config.properties.name[0] != '\0')
404 printf(" <%s>", info.ld_config.properties.name);
411 MFI_COMMAND(show, volumes, show_volumes);
414 show_drives(int ac, char **av)
416 struct mfi_pd_list *list;
417 struct mfi_pd_info info;
418 u_int i, len, state_len;
422 warnx("show drives: extra arguments");
426 fd = mfi_open(mfi_unit);
432 if (mfi_pd_get_list(fd, &list, NULL) < 0) {
433 warn("Failed to get drive list");
437 /* Walk the list of drives to determine width of state column. */
439 for (i = 0; i < list->count; i++) {
440 if (list->addr[i].scsi_dev_type != 0)
443 if (mfi_pd_get_info(fd, list->addr[i].device_id, &info,
445 warn("Failed to fetch info for drive %u",
446 list->addr[i].device_id);
449 len = strlen(mfi_pdstate(info.fw_state));
454 /* List the drives. */
455 printf("mfi%d Physical Drives:\n", mfi_unit);
456 for (i = 0; i < list->count; i++) {
458 /* Skip non-hard disks. */
459 if (list->addr[i].scsi_dev_type != 0)
462 /* Fetch details for this drive. */
463 if (mfi_pd_get_info(fd, list->addr[i].device_id, &info,
465 warn("Failed to fetch info for drive %u",
466 list->addr[i].device_id);
470 print_pd(&info, state_len, 1);
477 MFI_COMMAND(show, drives, show_drives);
479 int fw_name_width, fw_version_width, fw_date_width, fw_time_width;
482 scan_firmware(struct mfi_info_component *comp)
486 len = strlen(comp->name);
487 if (fw_name_width < len)
489 len = strlen(comp->version);
490 if (fw_version_width < len)
491 fw_version_width = len;
492 len = strlen(comp->build_date);
493 if (fw_date_width < len)
495 len = strlen(comp->build_time);
496 if (fw_time_width < len)
501 display_firmware(struct mfi_info_component *comp, const char *tag)
504 printf("%-*s %-*s %-*s %-*s %s\n", fw_name_width, comp->name,
505 fw_version_width, comp->version, fw_date_width, comp->build_date,
506 fw_time_width, comp->build_time, tag);
510 show_firmware(int ac, char **av)
512 struct mfi_ctrl_info info;
513 struct mfi_info_component header;
518 warnx("show drives: extra arguments");
522 fd = mfi_open(mfi_unit);
528 if (mfi_ctrl_get_info(fd, &info, NULL) < 0) {
529 warn("Failed to get controller info");
533 if (info.package_version[0] != '\0')
534 printf("mfi%d Firmware Package Version: %s\n", mfi_unit,
535 info.package_version);
536 printf("mfi%d Firmware Images:\n", mfi_unit);
537 strcpy(header.name, "Name");
538 strcpy(header.version, "Version");
539 strcpy(header.build_date, "Date");
540 strcpy(header.build_time, "Time");
541 scan_firmware(&header);
542 if (info.image_component_count > 8)
543 info.image_component_count = 8;
544 for (i = 0; i < info.image_component_count; i++)
545 scan_firmware(&info.image_component[i]);
546 if (info.pending_image_component_count > 8)
547 info.pending_image_component_count = 8;
548 for (i = 0; i < info.pending_image_component_count; i++)
549 scan_firmware(&info.pending_image_component[i]);
550 display_firmware(&header, "Status");
551 for (i = 0; i < info.image_component_count; i++)
552 display_firmware(&info.image_component[i], "active");
553 for (i = 0; i < info.pending_image_component_count; i++)
554 display_firmware(&info.pending_image_component[i], "pending");
560 MFI_COMMAND(show, firmware, show_firmware);