1763fae79SScott Long /*- 21de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 31de7b4b8SPedro F. Giffuni * 4763fae79SScott Long * Copyright (c) 2008, 2009 Yahoo!, Inc. 5763fae79SScott Long * All rights reserved. 6763fae79SScott Long * 7763fae79SScott Long * Redistribution and use in source and binary forms, with or without 8763fae79SScott Long * modification, are permitted provided that the following conditions 9763fae79SScott Long * are met: 10763fae79SScott Long * 1. Redistributions of source code must retain the above copyright 11763fae79SScott Long * notice, this list of conditions and the following disclaimer. 12763fae79SScott Long * 2. Redistributions in binary form must reproduce the above copyright 13763fae79SScott Long * notice, this list of conditions and the following disclaimer in the 14763fae79SScott Long * documentation and/or other materials provided with the distribution. 15763fae79SScott Long * 3. The names of the authors may not be used to endorse or promote 16763fae79SScott Long * products derived from this software without specific prior written 17763fae79SScott Long * permission. 18763fae79SScott Long * 19763fae79SScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20763fae79SScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21763fae79SScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22763fae79SScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23763fae79SScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24763fae79SScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25763fae79SScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26763fae79SScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27763fae79SScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28763fae79SScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29763fae79SScott Long * SUCH DAMAGE. 30763fae79SScott Long */ 31763fae79SScott Long 32763fae79SScott Long #ifndef __MFIUTIL_H__ 33763fae79SScott Long #define __MFIUTIL_H__ 34763fae79SScott Long 35763fae79SScott Long #include <sys/cdefs.h> 36763fae79SScott Long #include <sys/linker_set.h> 37763fae79SScott Long 38763fae79SScott Long #include <dev/mfi/mfireg.h> 39763fae79SScott Long 40*7e0f8b79SDoug Ambrisko #define MRSAS_TYPE "mrsas" 41*7e0f8b79SDoug Ambrisko #define MFI_TYPE "mfi" 42*7e0f8b79SDoug Ambrisko 43763fae79SScott Long /* 4.x compat */ 44763fae79SScott Long #ifndef SET_DECLARE 45763fae79SScott Long 46763fae79SScott Long /* <sys/cdefs.h> */ 47763fae79SScott Long #define __used 48763fae79SScott Long #define __section(x) __attribute__((__section__(x))) 49763fae79SScott Long 50763fae79SScott Long /* <sys/linker_set.h> */ 51763fae79SScott Long #undef __MAKE_SET 52763fae79SScott Long #undef DATA_SET 53763fae79SScott Long 54763fae79SScott Long #define __MAKE_SET(set, sym) \ 55763fae79SScott Long static void const * const __set_##set##_sym_##sym \ 56763fae79SScott Long __section("set_" #set) __used = &sym 57763fae79SScott Long 58763fae79SScott Long #define DATA_SET(set, sym) __MAKE_SET(set, sym) 59763fae79SScott Long 60763fae79SScott Long #define SET_DECLARE(set, ptype) \ 61763fae79SScott Long extern ptype *__CONCAT(__start_set_,set); \ 62763fae79SScott Long extern ptype *__CONCAT(__stop_set_,set) 63763fae79SScott Long 64763fae79SScott Long #define SET_BEGIN(set) \ 65763fae79SScott Long (&__CONCAT(__start_set_,set)) 66763fae79SScott Long #define SET_LIMIT(set) \ 67763fae79SScott Long (&__CONCAT(__stop_set_,set)) 68763fae79SScott Long 69763fae79SScott Long #define SET_FOREACH(pvar, set) \ 70763fae79SScott Long for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) 71763fae79SScott Long 72763fae79SScott Long int humanize_number(char *_buf, size_t _len, int64_t _number, 73763fae79SScott Long const char *_suffix, int _scale, int _flags); 74763fae79SScott Long 75763fae79SScott Long /* humanize_number(3) */ 76763fae79SScott Long #define HN_DECIMAL 0x01 77763fae79SScott Long #define HN_NOSPACE 0x02 78763fae79SScott Long #define HN_B 0x04 79763fae79SScott Long #define HN_DIVISOR_1000 0x08 80763fae79SScott Long 81763fae79SScott Long #define HN_GETSCALE 0x10 82763fae79SScott Long #define HN_AUTOSCALE 0x20 83763fae79SScott Long 84763fae79SScott Long #endif 85763fae79SScott Long 86763fae79SScott Long /* Constants for DDF RAID levels. */ 87763fae79SScott Long #define DDF_RAID0 0x00 88763fae79SScott Long #define DDF_RAID1 0x01 89763fae79SScott Long #define DDF_RAID3 0x03 90763fae79SScott Long #define DDF_RAID5 0x05 91763fae79SScott Long #define DDF_RAID6 0x06 92763fae79SScott Long #define DDF_RAID1E 0x11 93763fae79SScott Long #define DDF_JBOD 0x0f 94763fae79SScott Long #define DDF_CONCAT 0x1f 95763fae79SScott Long #define DDF_RAID5E 0x15 96763fae79SScott Long #define DDF_RAID5EE 0x25 97763fae79SScott Long 98763fae79SScott Long struct mfiutil_command { 99763fae79SScott Long const char *name; 100763fae79SScott Long int (*handler)(int ac, char **av); 101763fae79SScott Long }; 102763fae79SScott Long 103763fae79SScott Long #define MFI_DATASET(name) mfiutil_ ## name ## _table 104763fae79SScott Long 105763fae79SScott Long #define MFI_COMMAND(set, name, function) \ 106763fae79SScott Long static struct mfiutil_command function ## _mfiutil_command = \ 107763fae79SScott Long { #name, function }; \ 108763fae79SScott Long DATA_SET(MFI_DATASET(set), function ## _mfiutil_command) 109763fae79SScott Long 110763fae79SScott Long #define MFI_TABLE(set, name) \ 111763fae79SScott Long SET_DECLARE(MFI_DATASET(name), struct mfiutil_command); \ 112763fae79SScott Long \ 113763fae79SScott Long static int \ 114763fae79SScott Long mfiutil_ ## name ## _table_handler(int ac, char **av) \ 115763fae79SScott Long { \ 116763fae79SScott Long return (mfi_table_handler(SET_BEGIN(MFI_DATASET(name)), \ 117763fae79SScott Long SET_LIMIT(MFI_DATASET(name)), ac, av)); \ 118763fae79SScott Long } \ 119763fae79SScott Long MFI_COMMAND(set, name, mfiutil_ ## name ## _table_handler) 120763fae79SScott Long 1217bbae305SBjoern A. Zeeb /* Drive name printing options */ 1227bbae305SBjoern A. Zeeb #define MFI_DNAME_ES 0x0001 /* E%u:S%u */ 1237bbae305SBjoern A. Zeeb #define MFI_DNAME_DEVICE_ID 0x0002 /* %u */ 1247bbae305SBjoern A. Zeeb #define MFI_DNAME_HONOR_OPTS 0x8000 /* Allow cmd line to override default */ 1257bbae305SBjoern A. Zeeb 126*7e0f8b79SDoug Ambrisko extern char *mfi_device; 127186475e2SEd Schouten 1287bbae305SBjoern A. Zeeb extern u_int mfi_opts; 129763fae79SScott Long 13006f1884fSSean Bruno /* We currently don't know the full details of the following struct */ 13106f1884fSSean Bruno struct mfi_foreign_scan_cfg { 13206f1884fSSean Bruno char data[24]; 13306f1884fSSean Bruno }; 13406f1884fSSean Bruno 13506f1884fSSean Bruno struct mfi_foreign_scan_info { 13606f1884fSSean Bruno uint32_t count; /* Number of foreign configs found */ 13706f1884fSSean Bruno struct mfi_foreign_scan_cfg cfgs[8]; 13806f1884fSSean Bruno }; 13906f1884fSSean Bruno 140763fae79SScott Long void mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref); 141763fae79SScott Long void mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref); 142763fae79SScott Long void mfi_display_progress(const char *label, struct mfi_progress *prog); 143763fae79SScott Long int mfi_table_handler(struct mfiutil_command **start, 144763fae79SScott Long struct mfiutil_command **end, int ac, char **av); 145763fae79SScott Long const char *mfi_raid_level(uint8_t primary_level, uint8_t secondary_level); 146763fae79SScott Long const char *mfi_ldstate(enum mfi_ld_state state); 147763fae79SScott Long const char *mfi_pdstate(enum mfi_pd_state state); 148763fae79SScott Long const char *mfi_pd_inq_string(struct mfi_pd_info *info); 149763fae79SScott Long const char *mfi_volume_name(int fd, uint8_t target_id); 150763fae79SScott Long int mfi_volume_busy(int fd, uint8_t target_id); 151763fae79SScott Long int mfi_config_read(int fd, struct mfi_config_data **configp); 15206f1884fSSean Bruno int mfi_config_read_opcode(int fd, uint32_t opcode, 15306f1884fSSean Bruno struct mfi_config_data **configp, uint8_t *mbox, size_t mboxlen); 154763fae79SScott Long int mfi_lookup_drive(int fd, char *drive, uint16_t *device_id); 155763fae79SScott Long int mfi_lookup_volume(int fd, const char *name, uint8_t *target_id); 156763fae79SScott Long int mfi_dcmd_command(int fd, uint32_t opcode, void *buf, size_t bufsize, 157763fae79SScott Long uint8_t *mbox, size_t mboxlen, uint8_t *statusp); 158*7e0f8b79SDoug Ambrisko int mfi_open(char *dev, int acs); 159763fae79SScott Long int mfi_ctrl_get_info(int fd, struct mfi_ctrl_info *info, uint8_t *statusp); 160763fae79SScott Long int mfi_ld_get_info(int fd, uint8_t target_id, struct mfi_ld_info *info, 161763fae79SScott Long uint8_t *statusp); 162763fae79SScott Long int mfi_ld_get_list(int fd, struct mfi_ld_list *list, uint8_t *statusp); 163763fae79SScott Long int mfi_pd_get_info(int fd, uint16_t device_id, struct mfi_pd_info *info, 164763fae79SScott Long uint8_t *statusp); 165763fae79SScott Long int mfi_pd_get_list(int fd, struct mfi_pd_list **listp, uint8_t *statusp); 166*7e0f8b79SDoug Ambrisko int mfi_reconfig_supported(const char *mfi_device); 167763fae79SScott Long const char *mfi_status(u_int status_code); 1687bbae305SBjoern A. Zeeb const char *mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id, 1697bbae305SBjoern A. Zeeb uint32_t def); 17006f1884fSSean Bruno void format_stripe(char *buf, size_t buflen, uint8_t stripe); 17106f1884fSSean Bruno void print_ld(struct mfi_ld_info *info, int state_len); 17206f1884fSSean Bruno void print_pd(struct mfi_pd_info *info, int state_len); 17306f1884fSSean Bruno void dump_config(int fd, struct mfi_config_data *config, const char *msg_prefix); 174dee3e845SMark Johnston int mfi_bbu_get_props(int fd, struct mfi_bbu_properties *props, 175dee3e845SMark Johnston uint8_t *statusp); 176dee3e845SMark Johnston int mfi_bbu_set_props(int fd, struct mfi_bbu_properties *props, 177dee3e845SMark Johnston uint8_t *statusp); 178dee3e845SMark Johnston void mfi_autolearn_period(uint32_t, char *, size_t); 179dee3e845SMark Johnston void mfi_next_learn_time(uint32_t, char *, size_t); 180dee3e845SMark Johnston void mfi_autolearn_mode(uint8_t, char *, size_t); 181*7e0f8b79SDoug Ambrisko int get_mfi_unit(const char *dev); 182*7e0f8b79SDoug Ambrisko char *get_mfi_type(const char *dev); 183763fae79SScott Long 184186475e2SEd Schouten void scan_firmware(struct mfi_info_component *comp); 185186475e2SEd Schouten void display_firmware(struct mfi_info_component *comp, const char *tag); 186186475e2SEd Schouten 18706f1884fSSean Bruno int display_format(int ac, char **av, int diagnostic, mfi_dcmd_t display_cmd); 188763fae79SScott Long #endif /* !__MFIUTIL_H__ */ 189