1 /* $OpenBSD: biovar.h,v 1.42 2012/01/20 12:38:19 jsing Exp $ */ 2 3 /* 4 * Copyright (c) 2002 Niklas Hallqvist. All rights reserved. 5 * Copyright (c) 2005 Marco Peereboom. All rights reserved. 6 * Copyright (c) 2012 Joel Sing <jsing@openbsd.org>. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /* 30 * Devices getting ioctls through this interface should use ioctl class 'B' 31 * and command numbers starting from 32, lower ones are reserved for generic 32 * ioctls. All ioctl data must be structures which start with a struct bio. 33 */ 34 35 #include <sys/types.h> 36 37 #define BIO_MSG_COUNT 5 38 #define BIO_MSG_LEN 128 39 40 struct bio_msg { 41 int bm_type; 42 #define BIO_MSG_INFO 1 43 #define BIO_MSG_WARN 2 44 #define BIO_MSG_ERROR 3 45 char bm_msg[BIO_MSG_LEN]; 46 }; 47 48 struct bio_status { 49 char bs_controller[16]; 50 int bs_status; 51 #define BIO_STATUS_UNKNOWN 0 52 #define BIO_STATUS_SUCCESS 1 53 #define BIO_STATUS_ERROR 2 54 int bs_msg_count; 55 struct bio_msg bs_msgs[BIO_MSG_COUNT]; 56 }; 57 58 struct bio { 59 void *bio_cookie; 60 struct bio_status bio_status; 61 }; 62 63 /* convert name to a cookie */ 64 #define BIOCLOCATE _IOWR('B', 0, struct bio_locate) 65 struct bio_locate { 66 struct bio bl_bio; 67 char *bl_name; 68 }; 69 70 #define BIOCINQ _IOWR('B', 32, struct bioc_inq) 71 struct bioc_inq { 72 struct bio bi_bio; 73 74 char bi_dev[16]; /* controller device */ 75 int bi_novol; /* nr of volumes */ 76 int bi_nodisk; /* nr of total disks */ 77 }; 78 79 #define BIOCDISK _IOWR('B', 33, struct bioc_disk) 80 /* structure that represents a disk in a RAID volume */ 81 struct bioc_disk { 82 struct bio bd_bio; 83 84 u_int16_t bd_channel; 85 u_int16_t bd_target; 86 u_int16_t bd_lun; 87 u_int16_t bd_other_id; /* unused for now */ 88 89 int bd_volid; /* associate with volume */ 90 int bd_diskid; /* virtual disk */ 91 int bd_status; /* current status */ 92 #define BIOC_SDONLINE 0x00 93 #define BIOC_SDONLINE_S "Online" 94 #define BIOC_SDOFFLINE 0x01 95 #define BIOC_SDOFFLINE_S "Offline" 96 #define BIOC_SDFAILED 0x02 97 #define BIOC_SDFAILED_S "Failed" 98 #define BIOC_SDREBUILD 0x03 99 #define BIOC_SDREBUILD_S "Rebuild" 100 #define BIOC_SDHOTSPARE 0x04 101 #define BIOC_SDHOTSPARE_S "Hot spare" 102 #define BIOC_SDUNUSED 0x05 103 #define BIOC_SDUNUSED_S "Unused" 104 #define BIOC_SDSCRUB 0x06 105 #define BIOC_SDSCRUB_S "Scrubbing" 106 #define BIOC_SDINVALID 0xff 107 #define BIOC_SDINVALID_S "Invalid" 108 u_quad_t bd_size; /* size of the disk */ 109 110 char bd_vendor[32]; /* scsi string */ 111 char bd_serial[32]; /* serial number */ 112 char bd_procdev[16]; /* processor device */ 113 }; 114 115 #define BIOCVOL _IOWR('B', 34, struct bioc_vol) 116 /* structure that represents a RAID volume */ 117 struct bioc_vol { 118 struct bio bv_bio; 119 int bv_volid; /* volume id */ 120 121 int16_t bv_percent; /* percent done operation */ 122 u_int16_t bv_seconds; /* seconds of progress so far */ 123 124 int bv_status; /* current status */ 125 #define BIOC_SVONLINE 0x00 126 #define BIOC_SVONLINE_S "Online" 127 #define BIOC_SVOFFLINE 0x01 128 #define BIOC_SVOFFLINE_S "Offline" 129 #define BIOC_SVDEGRADED 0x02 130 #define BIOC_SVDEGRADED_S "Degraded" 131 #define BIOC_SVBUILDING 0x03 132 #define BIOC_SVBUILDING_S "Building" 133 #define BIOC_SVSCRUB 0x04 134 #define BIOC_SVSCRUB_S "Scrubbing" 135 #define BIOC_SVREBUILD 0x05 136 #define BIOC_SVREBUILD_S "Rebuild" 137 #define BIOC_SVINVALID 0xff 138 #define BIOC_SVINVALID_S "Invalid" 139 u_quad_t bv_size; /* size of the disk */ 140 int bv_level; /* raid level */ 141 int bv_nodisk; /* nr of drives */ 142 143 char bv_dev[16]; /* device */ 144 char bv_vendor[32]; /* scsi string */ 145 }; 146 147 #define BIOCALARM _IOWR('B', 35, struct bioc_alarm) 148 struct bioc_alarm { 149 struct bio ba_bio; 150 int ba_opcode; 151 152 int ba_status; /* only used with get state */ 153 #define BIOC_SADISABLE 0x00 /* disable alarm */ 154 #define BIOC_SAENABLE 0x01 /* enable alarm */ 155 #define BIOC_SASILENCE 0x02 /* silence alarm */ 156 #define BIOC_GASTATUS 0x03 /* get status */ 157 #define BIOC_SATEST 0x04 /* test alarm */ 158 }; 159 160 #define BIOCBLINK _IOWR('B', 36, struct bioc_blink) 161 struct bioc_blink { 162 struct bio bb_bio; 163 u_int16_t bb_channel; 164 u_int16_t bb_target; 165 166 int bb_status; /* current status */ 167 #define BIOC_SBUNBLINK 0x00 /* disable blinking */ 168 #define BIOC_SBBLINK 0x01 /* enable blink */ 169 #define BIOC_SBALARM 0x02 /* enable alarm blink */ 170 }; 171 172 #define BIOCSETSTATE _IOWR('B', 37, struct bioc_setstate) 173 struct bioc_setstate { 174 struct bio bs_bio; 175 u_int16_t bs_channel; 176 u_int16_t bs_target; 177 u_int16_t bs_lun; 178 u_int16_t bs_other_id_type; /* use other_id instead of ctl */ 179 #define BIOC_SSOTHER_UNUSED 0x00 180 #define BIOC_SSOTHER_DEVT 0x01 181 int bs_other_id; /* cram dev_t or other id in here */ 182 183 int bs_status; /* change to this status */ 184 #define BIOC_SSONLINE 0x00 /* online disk */ 185 #define BIOC_SSOFFLINE 0x01 /* offline disk */ 186 #define BIOC_SSHOTSPARE 0x02 /* mark as hotspare */ 187 #define BIOC_SSREBUILD 0x03 /* rebuild on this disk */ 188 int bs_volid; /* volume id for rebuild */ 189 }; 190 191 #define BIOCCREATERAID _IOWR('B', 38, struct bioc_createraid) 192 struct bioc_createraid { 193 struct bio bc_bio; 194 void *bc_dev_list; 195 u_int16_t bc_dev_list_len; 196 int32_t bc_key_disk; 197 #define BIOC_CRMAXLEN 1024 198 u_int16_t bc_level; 199 u_int32_t bc_flags; 200 #define BIOC_SCFORCE 0x01 /* do not assemble, force create */ 201 #define BIOC_SCDEVT 0x02 /* dev_t array or string in dev_list */ 202 #define BIOC_SCNOAUTOASSEMBLE 0x04 /* do not assemble during autoconf */ 203 #define BIOC_SCBOOTABLE 0x08 /* device is bootable */ 204 u_int32_t bc_opaque_size; 205 u_int32_t bc_opaque_flags; 206 #define BIOC_SOINVALID 0x00 /* no opaque pointer */ 207 #define BIOC_SOIN 0x01 /* kernel perspective direction */ 208 #define BIOC_SOOUT 0x02 /* kernel perspective direction */ 209 u_int32_t bc_opaque_status; 210 #define BIOC_SOINOUT_FAILED 0x00 /* operation failed */ 211 #define BIOC_SOINOUT_OK 0x01 /* operation succeeded */ 212 void *bc_opaque; 213 }; 214 215 #define BIOCDELETERAID _IOWR('B', 39, struct bioc_deleteraid) 216 struct bioc_deleteraid { 217 struct bio bd_bio; 218 u_int32_t bd_flags; 219 #define BIOC_SDCLEARMETA 0x01 /* clear metadata region */ 220 char bd_dev[16]; /* device */ 221 }; 222 223 #define BIOCDISCIPLINE _IOWR('B', 40, struct bioc_discipline) 224 struct bioc_discipline { 225 struct bio bd_bio; 226 char bd_dev[16]; 227 u_int32_t bd_cmd; 228 u_int32_t bd_size; 229 void *bd_data; 230 }; 231 232 #define BIOCINSTALLBOOT _IOWR('B', 41, struct bioc_installboot) 233 struct bioc_installboot { 234 struct bio bb_bio; 235 char bb_dev[16]; 236 void *bb_bootblk; 237 void *bb_bootldr; 238 u_int32_t bb_bootblk_size; 239 u_int32_t bb_bootldr_size; 240 }; 241 242 /* kernel and userspace defines */ 243 #define BIOC_INQ 0x0001 244 #define BIOC_DISK 0x0002 245 #define BIOC_VOL 0x0004 246 #define BIOC_ALARM 0x0008 247 #define BIOC_BLINK 0x0010 248 #define BIOC_SETSTATE 0x0020 249 #define BIOC_CREATERAID 0x0040 250 #define BIOC_DELETERAID 0x0080 251 #define BIOC_DISCIPLINE 0x0100 252 #define BIOC_INSTALLBOOT 0x0200 253 254 /* user space defines */ 255 #define BIOC_DEVLIST 0x10000 256 257 #ifdef _KERNEL 258 int bio_register(struct device *, int (*)(struct device *, u_long, 259 caddr_t)); 260 void bio_unregister(struct device *); 261 262 void bio_status_init(struct bio_status *, struct device *); 263 void bio_status(struct bio_status *, int, int, const char *, va_list *); 264 265 void bio_info(struct bio_status *, int, const char *, ...); 266 void bio_warn(struct bio_status *, int, const char *, ...); 267 void bio_error(struct bio_status *, int, const char *, ...); 268 #endif 269