1 /* $OpenBSD: biovar.h,v 1.45 2016/08/14 04:08:03 dlg 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 uint64_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 struct { 115 int bdp_percent; 116 int bdp_seconds; 117 } bd_patrol; 118 }; 119 120 #define BIOCVOL _IOWR('B', 34, struct bioc_vol) 121 /* structure that represents a RAID volume */ 122 struct bioc_vol { 123 struct bio bv_bio; 124 int bv_volid; /* volume id */ 125 126 int16_t bv_percent; /* percent done operation */ 127 u_int16_t bv_seconds; /* seconds of progress so far */ 128 129 int bv_status; /* current status */ 130 #define BIOC_SVONLINE 0x00 131 #define BIOC_SVONLINE_S "Online" 132 #define BIOC_SVOFFLINE 0x01 133 #define BIOC_SVOFFLINE_S "Offline" 134 #define BIOC_SVDEGRADED 0x02 135 #define BIOC_SVDEGRADED_S "Degraded" 136 #define BIOC_SVBUILDING 0x03 137 #define BIOC_SVBUILDING_S "Building" 138 #define BIOC_SVSCRUB 0x04 139 #define BIOC_SVSCRUB_S "Scrubbing" 140 #define BIOC_SVREBUILD 0x05 141 #define BIOC_SVREBUILD_S "Rebuild" 142 #define BIOC_SVINVALID 0xff 143 #define BIOC_SVINVALID_S "Invalid" 144 uint64_t bv_size; /* size of the disk */ 145 int bv_level; /* raid level */ 146 int bv_nodisk; /* nr of drives */ 147 int bv_cache; /* cache mode */ 148 #define BIOC_CVUNKNOWN 0x00 149 #define BIOC_CVUNKNOWN_S "" 150 #define BIOC_CVWRITEBACK 0x01 151 #define BIOC_CVWRITEBACK_S "WB" 152 #define BIOC_CVWRITETHROUGH 0x02 153 #define BIOC_CVWRITETHROUGH_S "WT" 154 155 char bv_dev[16]; /* device */ 156 char bv_vendor[32]; /* scsi string */ 157 }; 158 159 #define BIOCALARM _IOWR('B', 35, struct bioc_alarm) 160 struct bioc_alarm { 161 struct bio ba_bio; 162 int ba_opcode; 163 164 int ba_status; /* only used with get state */ 165 #define BIOC_SADISABLE 0x00 /* disable alarm */ 166 #define BIOC_SAENABLE 0x01 /* enable alarm */ 167 #define BIOC_SASILENCE 0x02 /* silence alarm */ 168 #define BIOC_GASTATUS 0x03 /* get status */ 169 #define BIOC_SATEST 0x04 /* test alarm */ 170 }; 171 172 #define BIOCBLINK _IOWR('B', 36, struct bioc_blink) 173 struct bioc_blink { 174 struct bio bb_bio; 175 u_int16_t bb_channel; 176 u_int16_t bb_target; 177 178 int bb_status; /* current status */ 179 #define BIOC_SBUNBLINK 0x00 /* disable blinking */ 180 #define BIOC_SBBLINK 0x01 /* enable blink */ 181 #define BIOC_SBALARM 0x02 /* enable alarm blink */ 182 }; 183 184 #define BIOCSETSTATE _IOWR('B', 37, struct bioc_setstate) 185 struct bioc_setstate { 186 struct bio bs_bio; 187 u_int16_t bs_channel; 188 u_int16_t bs_target; 189 u_int16_t bs_lun; 190 u_int16_t bs_other_id_type; /* use other_id instead of ctl */ 191 #define BIOC_SSOTHER_UNUSED 0x00 192 #define BIOC_SSOTHER_DEVT 0x01 193 int bs_other_id; /* cram dev_t or other id in here */ 194 195 int bs_status; /* change to this status */ 196 #define BIOC_SSONLINE 0x00 /* online disk */ 197 #define BIOC_SSOFFLINE 0x01 /* offline disk */ 198 #define BIOC_SSHOTSPARE 0x02 /* mark as hotspare */ 199 #define BIOC_SSREBUILD 0x03 /* rebuild on this disk */ 200 int bs_volid; /* volume id for rebuild */ 201 }; 202 203 #define BIOCCREATERAID _IOWR('B', 38, struct bioc_createraid) 204 struct bioc_createraid { 205 struct bio bc_bio; 206 void *bc_dev_list; 207 u_int16_t bc_dev_list_len; 208 int32_t bc_key_disk; 209 #define BIOC_CRMAXLEN 1024 210 u_int16_t bc_level; 211 u_int32_t bc_flags; 212 #define BIOC_SCFORCE 0x01 /* do not assemble, force create */ 213 #define BIOC_SCDEVT 0x02 /* dev_t array or string in dev_list */ 214 #define BIOC_SCNOAUTOASSEMBLE 0x04 /* do not assemble during autoconf */ 215 #define BIOC_SCBOOTABLE 0x08 /* device is bootable */ 216 u_int32_t bc_opaque_size; 217 u_int32_t bc_opaque_flags; 218 #define BIOC_SOINVALID 0x00 /* no opaque pointer */ 219 #define BIOC_SOIN 0x01 /* kernel perspective direction */ 220 #define BIOC_SOOUT 0x02 /* kernel perspective direction */ 221 u_int32_t bc_opaque_status; 222 #define BIOC_SOINOUT_FAILED 0x00 /* operation failed */ 223 #define BIOC_SOINOUT_OK 0x01 /* operation succeeded */ 224 void *bc_opaque; 225 }; 226 227 #define BIOCDELETERAID _IOWR('B', 39, struct bioc_deleteraid) 228 struct bioc_deleteraid { 229 struct bio bd_bio; 230 u_int32_t bd_flags; 231 #define BIOC_SDCLEARMETA 0x01 /* clear metadata region */ 232 char bd_dev[16]; /* device */ 233 }; 234 235 #define BIOCDISCIPLINE _IOWR('B', 40, struct bioc_discipline) 236 struct bioc_discipline { 237 struct bio bd_bio; 238 char bd_dev[16]; 239 u_int32_t bd_cmd; 240 u_int32_t bd_size; 241 void *bd_data; 242 }; 243 244 #define BIOCINSTALLBOOT _IOWR('B', 41, struct bioc_installboot) 245 struct bioc_installboot { 246 struct bio bb_bio; 247 char bb_dev[16]; 248 void *bb_bootblk; 249 void *bb_bootldr; 250 u_int32_t bb_bootblk_size; 251 u_int32_t bb_bootldr_size; 252 }; 253 254 #define BIOCPATROL _IOWR('B', 42, struct bioc_patrol) 255 struct bioc_patrol { 256 struct bio bp_bio; 257 int bp_opcode; 258 #define BIOC_SPSTOP 0x00 /* stop patrol */ 259 #define BIOC_SPSTART 0x01 /* start patrol */ 260 #define BIOC_GPSTATUS 0x02 /* get status */ 261 #define BIOC_SPDISABLE 0x03 /* disable patrol */ 262 #define BIOC_SPAUTO 0x04 /* enable patrol as auto */ 263 #define BIOC_SPMANUAL 0x05 /* enable patrol as manual */ 264 265 int bp_mode; 266 #define BIOC_SPMAUTO 0x00 267 #define BIOC_SPMMANUAL 0x01 268 #define BIOC_SPMDISABLED 0x02 269 int bp_status; /* only used with get state */ 270 #define BIOC_SPSSTOPPED 0x00 271 #define BIOC_SPSREADY 0x01 272 #define BIOC_SPSACTIVE 0x02 273 #define BIOC_SPSABORTED 0xff 274 275 int bp_autoival; 276 int bp_autonext; 277 int bp_autonow; 278 }; 279 280 /* kernel and userspace defines */ 281 #define BIOC_INQ 0x0001 282 #define BIOC_DISK 0x0002 283 #define BIOC_VOL 0x0004 284 #define BIOC_ALARM 0x0008 285 #define BIOC_BLINK 0x0010 286 #define BIOC_SETSTATE 0x0020 287 #define BIOC_CREATERAID 0x0040 288 #define BIOC_DELETERAID 0x0080 289 #define BIOC_DISCIPLINE 0x0100 290 #define BIOC_INSTALLBOOT 0x0200 291 #define BIOC_PATROL 0x0400 292 293 /* user space defines */ 294 #define BIOC_DEVLIST 0x10000 295 296 #ifdef _KERNEL 297 int bio_register(struct device *, int (*)(struct device *, u_long, 298 caddr_t)); 299 void bio_unregister(struct device *); 300 301 void bio_status_init(struct bio_status *, struct device *); 302 void bio_status(struct bio_status *, int, int, const char *, va_list *); 303 304 void bio_info(struct bio_status *, int, const char *, ...); 305 void bio_warn(struct bio_status *, int, const char *, ...); 306 void bio_error(struct bio_status *, int, const char *, ...); 307 #endif 308