1196200Sscottl/*- 2196200Sscottl * Copyright (c) 2008, 2009 Yahoo!, Inc. 3196200Sscottl * All rights reserved. 4196200Sscottl * 5196200Sscottl * Redistribution and use in source and binary forms, with or without 6196200Sscottl * modification, are permitted provided that the following conditions 7196200Sscottl * are met: 8196200Sscottl * 1. Redistributions of source code must retain the above copyright 9196200Sscottl * notice, this list of conditions and the following disclaimer. 10196200Sscottl * 2. Redistributions in binary form must reproduce the above copyright 11196200Sscottl * notice, this list of conditions and the following disclaimer in the 12196200Sscottl * documentation and/or other materials provided with the distribution. 13196200Sscottl * 3. The names of the authors may not be used to endorse or promote 14196200Sscottl * products derived from this software without specific prior written 15196200Sscottl * permission. 16196200Sscottl * 17196200Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18196200Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19196200Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20196200Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21196200Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22196200Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23196200Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24196200Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25196200Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26196200Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27196200Sscottl * SUCH DAMAGE. 28196200Sscottl * 29196200Sscottl * $FreeBSD$ 30196200Sscottl */ 31196200Sscottl 32196200Sscottl#include <sys/errno.h> 33196200Sscottl#include <err.h> 34196200Sscottl#include <stdio.h> 35196200Sscottl#include <stdlib.h> 36196200Sscottl#include <string.h> 37196200Sscottl#include <unistd.h> 38196200Sscottl#include "mfiutil.h" 39196200Sscottl 40196200SscottlSET_DECLARE(MFI_DATASET(top), struct mfiutil_command); 41196200Sscottl 42196200SscottlMFI_TABLE(top, start); 43196200SscottlMFI_TABLE(top, stop); 44196200SscottlMFI_TABLE(top, abort); 45196200Sscottl 46196200Sscottlint mfi_unit; 47223345Sbzu_int mfi_opts; 48241776Sedstatic int fw_name_width, fw_version_width, fw_date_width, fw_time_width; 49223345Sbz 50196200Sscottlstatic void 51196200Sscottlusage(void) 52196200Sscottl{ 53196200Sscottl 54223345Sbz fprintf(stderr, "usage: mfiutil [-de] [-u unit] <command> ...\n\n"); 55196200Sscottl fprintf(stderr, "Commands include:\n"); 56196200Sscottl fprintf(stderr, " version\n"); 57196200Sscottl fprintf(stderr, " show adapter - display controller information\n"); 58196200Sscottl fprintf(stderr, " show battery - display battery information\n"); 59196200Sscottl fprintf(stderr, " show config - display RAID configuration\n"); 60196200Sscottl fprintf(stderr, " show drives - list physical drives\n"); 61196200Sscottl fprintf(stderr, " show events - display event log\n"); 62196200Sscottl fprintf(stderr, " show firmware - list firmware images\n"); 63251516Ssbruno fprintf(stderr, " show foreign - display detected foreign volumes\n"); 64223267Sbz fprintf(stderr, " show logstate - display event log sequence numbers\n"); 65196200Sscottl fprintf(stderr, " show volumes - list logical volumes\n"); 66196200Sscottl fprintf(stderr, " show patrol - display patrol read status\n"); 67221208Sjhb fprintf(stderr, " show progress - display status of active operations\n"); 68196200Sscottl fprintf(stderr, " fail <drive> - fail a physical drive\n"); 69254906Ssbruno fprintf(stderr, " good <drive> - set a failed/SYSPD drive as UNCONFIGURED\n"); 70196200Sscottl fprintf(stderr, " rebuild <drive> - mark failed drive ready for rebuild\n"); 71254906Ssbruno fprintf(stderr, " syspd <drive> - set drive into use as SYSPD JBOD\n"); 72196200Sscottl fprintf(stderr, " drive progress <drive> - display status of active operations\n"); 73196200Sscottl fprintf(stderr, " drive clear <drive> <start|stop> - clear a drive with all 0x00\n"); 74196200Sscottl fprintf(stderr, " start rebuild <drive>\n"); 75196200Sscottl fprintf(stderr, " abort rebuild <drive>\n"); 76196200Sscottl fprintf(stderr, " locate <drive> <on|off> - toggle drive LED\n"); 77196200Sscottl fprintf(stderr, " cache <volume> [command [setting]]\n"); 78196200Sscottl fprintf(stderr, " name <volume> <name>\n"); 79196200Sscottl fprintf(stderr, " volume progress <volume> - display status of active operations\n"); 80196200Sscottl fprintf(stderr, " clear - clear volume configuration\n"); 81196200Sscottl fprintf(stderr, " create <type> [-v] <drive>[,<drive>[,...]] [<drive>[,<drive>[,...]]\n"); 82196200Sscottl fprintf(stderr, " delete <volume>\n"); 83196200Sscottl fprintf(stderr, " add <drive> [volume] - add a hot spare\n"); 84196200Sscottl fprintf(stderr, " remove <drive> - remove a hot spare\n"); 85196200Sscottl fprintf(stderr, " patrol <disable|auto|manual> [interval [start]]\n"); 86196200Sscottl fprintf(stderr, " start patrol - start a patrol read\n"); 87196200Sscottl fprintf(stderr, " stop patrol - stop a patrol read\n"); 88251516Ssbruno fprintf(stderr, " foreign scan - scan for foreign configurations\n"); 89251516Ssbruno fprintf(stderr, " foreign clear [volume] - clear foreign configurations (default all)\n"); 90251516Ssbruno fprintf(stderr, " foreign diag [volume] - diagnostic display foreign configurations (default all)\n"); 91251516Ssbruno fprintf(stderr, " foreign preview [volume] - preview foreign configurations (default all)\n"); 92251516Ssbruno fprintf(stderr, " foreign import [volume] - import foreign configurations (default all)\n"); 93196200Sscottl fprintf(stderr, " flash <firmware>\n"); 94249257Smarkj fprintf(stderr, " start learn - start a BBU relearn\n"); 95249257Smarkj fprintf(stderr, " bbu <setting> <value> - set BBU properties\n"); 96272041Ssmh fprintf(stderr, " ctrlprop rebuild [rate] - get/set the volume rebuild rate\n"); 97272041Ssmh fprintf(stderr, " ctrlprop alarm [0/1] - enable/disable controller alarms\n"); 98196200Sscottl#ifdef DEBUG 99196200Sscottl fprintf(stderr, " debug - debug 'show config'\n"); 100196200Sscottl fprintf(stderr, " dump - display 'saved' config\n"); 101196200Sscottl#endif 102196200Sscottl exit(1); 103196200Sscottl} 104196200Sscottl 105196200Sscottlstatic int 106237260Seadlerversion(int ac __unused, char **av __unused) 107196200Sscottl{ 108196200Sscottl 109254906Ssbruno printf("mfiutil version 1.0.15"); 110196200Sscottl#ifdef DEBUG 111196200Sscottl printf(" (DEBUG)"); 112196200Sscottl#endif 113196200Sscottl printf("\n"); 114196200Sscottl return (0); 115196200Sscottl} 116196200SscottlMFI_COMMAND(top, version, version); 117196200Sscottl 118196200Sscottlint 119196200Sscottlmain(int ac, char **av) 120196200Sscottl{ 121196200Sscottl struct mfiutil_command **cmd; 122196200Sscottl int ch; 123196200Sscottl 124223345Sbz while ((ch = getopt(ac, av, "deu:")) != -1) { 125196200Sscottl switch (ch) { 126223345Sbz case 'd': 127223345Sbz mfi_opts |= MFI_DNAME_DEVICE_ID; 128223345Sbz break; 129223345Sbz case 'e': 130223345Sbz mfi_opts |= MFI_DNAME_ES; 131223345Sbz break; 132196200Sscottl case 'u': 133196200Sscottl mfi_unit = atoi(optarg); 134196200Sscottl break; 135196200Sscottl case '?': 136196200Sscottl usage(); 137196200Sscottl } 138196200Sscottl } 139196200Sscottl 140196200Sscottl av += optind; 141196200Sscottl ac -= optind; 142196200Sscottl 143196200Sscottl /* getopt() eats av[0], so we can't use mfi_table_handler() directly. */ 144196200Sscottl if (ac == 0) 145196200Sscottl usage(); 146196200Sscottl 147196200Sscottl SET_FOREACH(cmd, MFI_DATASET(top)) { 148196200Sscottl if (strcmp((*cmd)->name, av[0]) == 0) { 149213672Srandi if ((*cmd)->handler(ac, av)) 150213672Srandi return (1); 151213672Srandi else 152213672Srandi return (0); 153196200Sscottl } 154196200Sscottl } 155196200Sscottl warnx("Unknown command %s.", av[0]); 156213672Srandi return (1); 157196200Sscottl} 158241776Sed 159241776Sedvoid 160241776Sedscan_firmware(struct mfi_info_component *comp) 161241776Sed{ 162241776Sed int len; 163241776Sed 164241776Sed len = strlen(comp->name); 165241776Sed if (fw_name_width < len) 166241776Sed fw_name_width = len; 167241776Sed len = strlen(comp->version); 168241776Sed if (fw_version_width < len) 169241776Sed fw_version_width = len; 170241776Sed len = strlen(comp->build_date); 171241776Sed if (fw_date_width < len) 172241776Sed fw_date_width = len; 173241776Sed len = strlen(comp->build_time); 174241776Sed if (fw_time_width < len) 175241776Sed fw_time_width = len; 176241776Sed} 177241776Sed 178241776Sedvoid 179241776Seddisplay_firmware(struct mfi_info_component *comp, const char *tag) 180241776Sed{ 181241776Sed 182241776Sed printf("%-*s %-*s %-*s %-*s %s\n", fw_name_width, comp->name, 183241776Sed fw_version_width, comp->version, fw_date_width, comp->build_date, 184241776Sed fw_time_width, comp->build_time, tag); 185241776Sed} 186