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#ifndef __MFIUTIL_H__ 33196200Sscottl#define __MFIUTIL_H__ 34196200Sscottl 35196200Sscottl#include <sys/cdefs.h> 36196200Sscottl#include <sys/linker_set.h> 37196200Sscottl 38196200Sscottl#include <dev/mfi/mfireg.h> 39196200Sscottl 40196200Sscottl/* 4.x compat */ 41196200Sscottl#ifndef SET_DECLARE 42196200Sscottl 43196200Sscottl/* <sys/cdefs.h> */ 44196200Sscottl#define __used 45196200Sscottl#define __section(x) __attribute__((__section__(x))) 46196200Sscottl 47196200Sscottl/* <sys/linker_set.h> */ 48196200Sscottl#undef __MAKE_SET 49196200Sscottl#undef DATA_SET 50196200Sscottl 51196200Sscottl#define __MAKE_SET(set, sym) \ 52196200Sscottl static void const * const __set_##set##_sym_##sym \ 53196200Sscottl __section("set_" #set) __used = &sym 54196200Sscottl 55196200Sscottl#define DATA_SET(set, sym) __MAKE_SET(set, sym) 56196200Sscottl 57196200Sscottl#define SET_DECLARE(set, ptype) \ 58196200Sscottl extern ptype *__CONCAT(__start_set_,set); \ 59196200Sscottl extern ptype *__CONCAT(__stop_set_,set) 60196200Sscottl 61196200Sscottl#define SET_BEGIN(set) \ 62196200Sscottl (&__CONCAT(__start_set_,set)) 63196200Sscottl#define SET_LIMIT(set) \ 64196200Sscottl (&__CONCAT(__stop_set_,set)) 65196200Sscottl 66196200Sscottl#define SET_FOREACH(pvar, set) \ 67196200Sscottl for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) 68196200Sscottl 69196200Sscottlint humanize_number(char *_buf, size_t _len, int64_t _number, 70196200Sscottl const char *_suffix, int _scale, int _flags); 71196200Sscottl 72196200Sscottl/* humanize_number(3) */ 73196200Sscottl#define HN_DECIMAL 0x01 74196200Sscottl#define HN_NOSPACE 0x02 75196200Sscottl#define HN_B 0x04 76196200Sscottl#define HN_DIVISOR_1000 0x08 77196200Sscottl 78196200Sscottl#define HN_GETSCALE 0x10 79196200Sscottl#define HN_AUTOSCALE 0x20 80196200Sscottl 81196200Sscottl#endif 82196200Sscottl 83196200Sscottl/* Constants for DDF RAID levels. */ 84196200Sscottl#define DDF_RAID0 0x00 85196200Sscottl#define DDF_RAID1 0x01 86196200Sscottl#define DDF_RAID3 0x03 87196200Sscottl#define DDF_RAID5 0x05 88196200Sscottl#define DDF_RAID6 0x06 89196200Sscottl#define DDF_RAID1E 0x11 90196200Sscottl#define DDF_JBOD 0x0f 91196200Sscottl#define DDF_CONCAT 0x1f 92196200Sscottl#define DDF_RAID5E 0x15 93196200Sscottl#define DDF_RAID5EE 0x25 94196200Sscottl 95196200Sscottlstruct mfiutil_command { 96196200Sscottl const char *name; 97196200Sscottl int (*handler)(int ac, char **av); 98196200Sscottl}; 99196200Sscottl 100196200Sscottl#define MFI_DATASET(name) mfiutil_ ## name ## _table 101196200Sscottl 102196200Sscottl#define MFI_COMMAND(set, name, function) \ 103196200Sscottl static struct mfiutil_command function ## _mfiutil_command = \ 104196200Sscottl { #name, function }; \ 105196200Sscottl DATA_SET(MFI_DATASET(set), function ## _mfiutil_command) 106196200Sscottl 107196200Sscottl#define MFI_TABLE(set, name) \ 108196200Sscottl SET_DECLARE(MFI_DATASET(name), struct mfiutil_command); \ 109196200Sscottl \ 110196200Sscottl static int \ 111196200Sscottl mfiutil_ ## name ## _table_handler(int ac, char **av) \ 112196200Sscottl { \ 113196200Sscottl return (mfi_table_handler(SET_BEGIN(MFI_DATASET(name)), \ 114196200Sscottl SET_LIMIT(MFI_DATASET(name)), ac, av)); \ 115196200Sscottl } \ 116196200Sscottl MFI_COMMAND(set, name, mfiutil_ ## name ## _table_handler) 117196200Sscottl 118223345Sbz/* Drive name printing options */ 119223345Sbz#define MFI_DNAME_ES 0x0001 /* E%u:S%u */ 120223345Sbz#define MFI_DNAME_DEVICE_ID 0x0002 /* %u */ 121223345Sbz#define MFI_DNAME_HONOR_OPTS 0x8000 /* Allow cmd line to override default */ 122223345Sbz 123196200Sscottlextern int mfi_unit; 124241776Sed 125223345Sbzextern u_int mfi_opts; 126196200Sscottl 127251516Ssbruno/* We currently don't know the full details of the following struct */ 128251516Ssbrunostruct mfi_foreign_scan_cfg { 129251516Ssbruno char data[24]; 130251516Ssbruno}; 131251516Ssbruno 132251516Ssbrunostruct mfi_foreign_scan_info { 133251516Ssbruno uint32_t count; /* Number of foreign configs found */ 134251516Ssbruno struct mfi_foreign_scan_cfg cfgs[8]; 135251516Ssbruno}; 136251516Ssbruno 137196200Sscottlvoid mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref); 138196200Sscottlvoid mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref); 139196200Sscottlvoid mfi_display_progress(const char *label, struct mfi_progress *prog); 140196200Sscottlint mfi_table_handler(struct mfiutil_command **start, 141196200Sscottl struct mfiutil_command **end, int ac, char **av); 142196200Sscottlconst char *mfi_raid_level(uint8_t primary_level, uint8_t secondary_level); 143196200Sscottlconst char *mfi_ldstate(enum mfi_ld_state state); 144196200Sscottlconst char *mfi_pdstate(enum mfi_pd_state state); 145196200Sscottlconst char *mfi_pd_inq_string(struct mfi_pd_info *info); 146196200Sscottlconst char *mfi_volume_name(int fd, uint8_t target_id); 147196200Sscottlint mfi_volume_busy(int fd, uint8_t target_id); 148196200Sscottlint mfi_config_read(int fd, struct mfi_config_data **configp); 149251516Ssbrunoint mfi_config_read_opcode(int fd, uint32_t opcode, 150251516Ssbruno struct mfi_config_data **configp, uint8_t *mbox, size_t mboxlen); 151196200Sscottlint mfi_lookup_drive(int fd, char *drive, uint16_t *device_id); 152196200Sscottlint mfi_lookup_volume(int fd, const char *name, uint8_t *target_id); 153196200Sscottlint mfi_dcmd_command(int fd, uint32_t opcode, void *buf, size_t bufsize, 154196200Sscottl uint8_t *mbox, size_t mboxlen, uint8_t *statusp); 155237259Seadlerint mfi_open(int unit, int acs); 156196200Sscottlint mfi_ctrl_get_info(int fd, struct mfi_ctrl_info *info, uint8_t *statusp); 157196200Sscottlint mfi_ld_get_info(int fd, uint8_t target_id, struct mfi_ld_info *info, 158196200Sscottl uint8_t *statusp); 159196200Sscottlint mfi_ld_get_list(int fd, struct mfi_ld_list *list, uint8_t *statusp); 160196200Sscottlint mfi_pd_get_info(int fd, uint16_t device_id, struct mfi_pd_info *info, 161196200Sscottl uint8_t *statusp); 162196200Sscottlint mfi_pd_get_list(int fd, struct mfi_pd_list **listp, uint8_t *statusp); 163196200Sscottlint mfi_reconfig_supported(void); 164196200Sscottlconst char *mfi_status(u_int status_code); 165223345Sbzconst char *mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id, 166223345Sbz uint32_t def); 167251516Ssbrunovoid format_stripe(char *buf, size_t buflen, uint8_t stripe); 168251516Ssbrunovoid print_ld(struct mfi_ld_info *info, int state_len); 169251516Ssbrunovoid print_pd(struct mfi_pd_info *info, int state_len); 170251516Ssbrunovoid dump_config(int fd, struct mfi_config_data *config, const char *msg_prefix); 171249257Smarkjint mfi_bbu_get_props(int fd, struct mfi_bbu_properties *props, 172249257Smarkj uint8_t *statusp); 173249257Smarkjint mfi_bbu_set_props(int fd, struct mfi_bbu_properties *props, 174249257Smarkj uint8_t *statusp); 175249257Smarkjvoid mfi_autolearn_period(uint32_t, char *, size_t); 176249257Smarkjvoid mfi_next_learn_time(uint32_t, char *, size_t); 177249257Smarkjvoid mfi_autolearn_mode(uint8_t, char *, size_t); 178196200Sscottl 179241776Sedvoid scan_firmware(struct mfi_info_component *comp); 180241776Sedvoid display_firmware(struct mfi_info_component *comp, const char *tag); 181241776Sed 182251516Ssbrunoint display_format(int ac, char **av, int diagnostic, mfi_dcmd_t display_cmd); 183196200Sscottl#endif /* !__MFIUTIL_H__ */ 184