mfiutil.h revision 196200
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: head/usr.sbin/mfiutil/mfiutil.h 196200 2009-08-13 23:18:45Z scottl $ 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 118196200Sscottlextern int mfi_unit; 119196200Sscottl 120196200Sscottlvoid mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref); 121196200Sscottlvoid mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref); 122196200Sscottlvoid mfi_display_progress(const char *label, struct mfi_progress *prog); 123196200Sscottlint mfi_table_handler(struct mfiutil_command **start, 124196200Sscottl struct mfiutil_command **end, int ac, char **av); 125196200Sscottlconst char *mfi_raid_level(uint8_t primary_level, uint8_t secondary_level); 126196200Sscottlconst char *mfi_ldstate(enum mfi_ld_state state); 127196200Sscottlconst char *mfi_pdstate(enum mfi_pd_state state); 128196200Sscottlconst char *mfi_pd_inq_string(struct mfi_pd_info *info); 129196200Sscottlconst char *mfi_volume_name(int fd, uint8_t target_id); 130196200Sscottlint mfi_volume_busy(int fd, uint8_t target_id); 131196200Sscottlint mfi_config_read(int fd, struct mfi_config_data **configp); 132196200Sscottlint mfi_lookup_drive(int fd, char *drive, uint16_t *device_id); 133196200Sscottlint mfi_lookup_volume(int fd, const char *name, uint8_t *target_id); 134196200Sscottlint mfi_dcmd_command(int fd, uint32_t opcode, void *buf, size_t bufsize, 135196200Sscottl uint8_t *mbox, size_t mboxlen, uint8_t *statusp); 136196200Sscottlint mfi_open(int unit); 137196200Sscottlint mfi_ctrl_get_info(int fd, struct mfi_ctrl_info *info, uint8_t *statusp); 138196200Sscottlint mfi_ld_get_info(int fd, uint8_t target_id, struct mfi_ld_info *info, 139196200Sscottl uint8_t *statusp); 140196200Sscottlint mfi_ld_get_list(int fd, struct mfi_ld_list *list, uint8_t *statusp); 141196200Sscottlint mfi_pd_get_info(int fd, uint16_t device_id, struct mfi_pd_info *info, 142196200Sscottl uint8_t *statusp); 143196200Sscottlint mfi_pd_get_list(int fd, struct mfi_pd_list **listp, uint8_t *statusp); 144196200Sscottlint mfi_reconfig_supported(void); 145196200Sscottlconst char *mfi_status(u_int status_code); 146196200Sscottl 147196200Sscottl#endif /* !__MFIUTIL_H__ */ 148