1/*	$OpenBSD: biovar.h,v 1.46 2020/06/07 16:51:43 kn 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#ifndef _SYS_DEV_BIOVAR_H_
30#define _SYS_DEV_BIOVAR_H_
31
32/*
33 * Devices getting ioctls through this interface should use ioctl class 'B'
34 * and command numbers starting from 32, lower ones are reserved for generic
35 * ioctls. All ioctl data must be structures which start with a struct bio.
36 */
37
38#include <sys/types.h>
39
40#define	BIO_MSG_COUNT	5
41#define	BIO_MSG_LEN	128
42
43struct bio_msg {
44	int		bm_type;
45#define	BIO_MSG_INFO	1
46#define	BIO_MSG_WARN	2
47#define	BIO_MSG_ERROR	3
48	char		bm_msg[BIO_MSG_LEN];
49};
50
51struct bio_status {
52	char		bs_controller[16];
53	int		bs_status;
54#define	BIO_STATUS_UNKNOWN	0
55#define	BIO_STATUS_SUCCESS	1
56#define	BIO_STATUS_ERROR	2
57	int		bs_msg_count;
58	struct bio_msg	bs_msgs[BIO_MSG_COUNT];
59};
60
61struct bio {
62	void			*bio_cookie;
63	struct bio_status	bio_status;
64};
65
66/* convert name to a cookie */
67#define BIOCLOCATE _IOWR('B', 0, struct bio_locate)
68struct bio_locate {
69	struct bio	bl_bio;
70	char		*bl_name;
71};
72
73#define BIOCINQ _IOWR('B', 32, struct bioc_inq)
74struct bioc_inq {
75	struct bio	bi_bio;
76
77	char		bi_dev[16];	/* controller device */
78	int		bi_novol;	/* nr of volumes */
79	int		bi_nodisk;	/* nr of total disks */
80};
81
82#define BIOCDISK _IOWR('B', 33, struct bioc_disk)
83/* structure that represents a disk in a RAID volume */
84struct bioc_disk {
85	struct bio	bd_bio;
86
87	u_int16_t	bd_channel;
88	u_int16_t	bd_target;
89	u_int16_t	bd_lun;
90	u_int16_t	bd_other_id;	/* unused for now  */
91
92	int		bd_volid;	/* associate with volume */
93	int		bd_diskid;	/* virtual disk */
94	int		bd_status;	/* current status */
95#define BIOC_SDONLINE		0x00
96#define BIOC_SDONLINE_S		"Online"
97#define BIOC_SDOFFLINE		0x01
98#define BIOC_SDOFFLINE_S	"Offline"
99#define BIOC_SDFAILED		0x02
100#define BIOC_SDFAILED_S		"Failed"
101#define BIOC_SDREBUILD		0x03
102#define BIOC_SDREBUILD_S	"Rebuild"
103#define BIOC_SDHOTSPARE		0x04
104#define BIOC_SDHOTSPARE_S	"Hot spare"
105#define BIOC_SDUNUSED		0x05
106#define BIOC_SDUNUSED_S		"Unused"
107#define BIOC_SDSCRUB		0x06
108#define BIOC_SDSCRUB_S		"Scrubbing"
109#define BIOC_SDINVALID		0xff
110#define BIOC_SDINVALID_S	"Invalid"
111	uint64_t	bd_size;	/* size of the disk */
112
113	char		bd_vendor[32];	/* scsi string */
114	char		bd_serial[32];	/* serial number */
115	char		bd_procdev[16];	/* processor device */
116
117	struct {
118		int		bdp_percent;
119		int		bdp_seconds;
120	}		bd_patrol;
121};
122
123#define BIOCVOL _IOWR('B', 34, struct bioc_vol)
124/* structure that represents a RAID volume */
125struct bioc_vol {
126	struct bio	bv_bio;
127	int		bv_volid;	/* volume id */
128
129	int16_t		bv_percent;	/* percent done operation */
130	u_int16_t	bv_seconds;	/* seconds of progress so far */
131
132	int		bv_status;	/* current status */
133#define BIOC_SVONLINE		0x00
134#define BIOC_SVONLINE_S		"Online"
135#define BIOC_SVOFFLINE		0x01
136#define BIOC_SVOFFLINE_S	"Offline"
137#define BIOC_SVDEGRADED		0x02
138#define BIOC_SVDEGRADED_S	"Degraded"
139#define BIOC_SVBUILDING		0x03
140#define BIOC_SVBUILDING_S	"Building"
141#define BIOC_SVSCRUB		0x04
142#define BIOC_SVSCRUB_S		"Scrubbing"
143#define BIOC_SVREBUILD		0x05
144#define BIOC_SVREBUILD_S	"Rebuild"
145#define BIOC_SVINVALID		0xff
146#define BIOC_SVINVALID_S	"Invalid"
147	uint64_t	bv_size;	/* size of the disk */
148	int		bv_level;	/* raid level */
149	int		bv_nodisk;	/* nr of drives */
150	int		bv_cache;	/* cache mode */
151#define BIOC_CVUNKNOWN		0x00
152#define BIOC_CVUNKNOWN_S	""
153#define BIOC_CVWRITEBACK	0x01
154#define BIOC_CVWRITEBACK_S	"WB"
155#define BIOC_CVWRITETHROUGH	0x02
156#define BIOC_CVWRITETHROUGH_S	"WT"
157
158	char		bv_dev[16];	/* device */
159	char		bv_vendor[32];	/* scsi string */
160};
161
162#define BIOCALARM _IOWR('B', 35, struct bioc_alarm)
163struct bioc_alarm {
164	struct bio	ba_bio;
165	int		ba_opcode;
166
167	int		ba_status;	/* only used with get state */
168#define BIOC_SADISABLE		0x00	/* disable alarm */
169#define BIOC_SAENABLE		0x01	/* enable alarm */
170#define BIOC_SASILENCE		0x02	/* silence alarm */
171#define BIOC_GASTATUS		0x03	/* get status */
172#define BIOC_SATEST		0x04	/* test alarm */
173};
174
175#define BIOCBLINK _IOWR('B', 36, struct bioc_blink)
176struct bioc_blink {
177	struct bio	bb_bio;
178	u_int16_t	bb_channel;
179	u_int16_t	bb_target;
180
181	int		bb_status;	/* current status */
182#define BIOC_SBUNBLINK		0x00	/* disable blinking */
183#define BIOC_SBBLINK		0x01	/* enable blink */
184#define BIOC_SBALARM		0x02	/* enable alarm blink */
185};
186
187#define BIOCSETSTATE _IOWR('B', 37, struct bioc_setstate)
188struct bioc_setstate {
189	struct bio	bs_bio;
190	u_int16_t	bs_channel;
191	u_int16_t	bs_target;
192	u_int16_t	bs_lun;
193	u_int16_t	bs_other_id_type; /* use other_id instead of ctl */
194#define BIOC_SSOTHER_UNUSED	0x00
195#define BIOC_SSOTHER_DEVT	0x01
196	int		bs_other_id;	/* cram dev_t or other id in here */
197
198	int		bs_status;	/* change to this status */
199#define BIOC_SSONLINE		0x00	/* online disk */
200#define BIOC_SSOFFLINE		0x01	/* offline disk */
201#define BIOC_SSHOTSPARE		0x02	/* mark as hotspare */
202#define BIOC_SSREBUILD		0x03	/* rebuild on this disk */
203	int		bs_volid;	/* volume id for rebuild */
204};
205
206#define BIOCCREATERAID _IOWR('B', 38, struct bioc_createraid)
207struct bioc_createraid {
208	struct bio	bc_bio;
209	void		*bc_dev_list;
210	u_int16_t	bc_dev_list_len;
211	int32_t		bc_key_disk;
212#define BIOC_CRMAXLEN		1024
213	u_int16_t	bc_level;
214	u_int32_t	bc_flags;
215#define BIOC_SCFORCE		0x01	/* do not assemble, force create */
216#define BIOC_SCDEVT		0x02	/* dev_t array or string in dev_list */
217#define BIOC_SCNOAUTOASSEMBLE	0x04	/* do not assemble during autoconf */
218#define BIOC_SCBOOTABLE		0x08	/* device is bootable */
219	u_int32_t	bc_opaque_size;
220	u_int32_t	bc_opaque_flags;
221#define	BIOC_SOINVALID		0x00	/* no opaque pointer */
222#define	BIOC_SOIN		0x01	/* kernel perspective direction */
223#define BIOC_SOOUT		0x02	/* kernel perspective direction */
224	u_int32_t	bc_opaque_status;
225#define	BIOC_SOINOUT_FAILED	0x00	/* operation failed */
226#define	BIOC_SOINOUT_OK		0x01	/* operation succeeded */
227	void		*bc_opaque;
228};
229
230#define BIOCDELETERAID _IOWR('B', 39, struct bioc_deleteraid)
231struct bioc_deleteraid {
232	struct bio	bd_bio;
233	u_int32_t	bd_flags;
234#define BIOC_SDCLEARMETA	0x01	/* clear metadata region */
235	char		bd_dev[16];	/* device */
236};
237
238#define BIOCDISCIPLINE _IOWR('B', 40, struct bioc_discipline)
239struct bioc_discipline {
240	struct bio	bd_bio;
241	char		bd_dev[16];
242	u_int32_t	bd_cmd;
243	u_int32_t	bd_size;
244	void		*bd_data;
245};
246
247#define BIOCINSTALLBOOT _IOWR('B', 41, struct bioc_installboot)
248struct bioc_installboot {
249	struct bio	bb_bio;
250	char		bb_dev[16];
251	void		*bb_bootblk;
252	void		*bb_bootldr;
253	u_int32_t	bb_bootblk_size;
254	u_int32_t	bb_bootldr_size;
255};
256
257#define BIOCPATROL _IOWR('B', 42, struct bioc_patrol)
258struct bioc_patrol {
259	struct bio	bp_bio;
260	int		bp_opcode;
261#define BIOC_SPSTOP		0x00	/* stop patrol */
262#define BIOC_SPSTART		0x01	/* start patrol */
263#define BIOC_GPSTATUS		0x02	/* get status */
264#define BIOC_SPDISABLE		0x03	/* disable patrol */
265#define BIOC_SPAUTO		0x04	/* enable patrol as auto */
266#define BIOC_SPMANUAL		0x05	/* enable patrol as manual */
267
268	int		bp_mode;
269#define	BIOC_SPMAUTO		0x00
270#define	BIOC_SPMMANUAL		0x01
271#define BIOC_SPMDISABLED	0x02
272	int		bp_status;	/* only used with get state */
273#define	BIOC_SPSSTOPPED		0x00
274#define	BIOC_SPSREADY		0x01
275#define BIOC_SPSACTIVE		0x02
276#define BIOC_SPSABORTED		0xff
277
278	int		bp_autoival;
279	int		bp_autonext;
280	int		bp_autonow;
281};
282
283/* kernel and userspace defines */
284#define BIOC_INQ		0x0001
285#define BIOC_DISK		0x0002
286#define BIOC_VOL		0x0004
287#define BIOC_ALARM		0x0008
288#define BIOC_BLINK		0x0010
289#define BIOC_SETSTATE		0x0020
290#define BIOC_CREATERAID		0x0040
291#define BIOC_DELETERAID		0x0080
292#define BIOC_DISCIPLINE		0x0100
293#define BIOC_INSTALLBOOT	0x0200
294#define BIOC_PATROL		0x0400
295
296/* user space defines */
297#define BIOC_DEVLIST		0x10000
298
299#ifdef _KERNEL
300int	bio_register(struct device *, int (*)(struct device *, u_long,
301	    caddr_t));
302void	bio_unregister(struct device *);
303
304void	bio_status_init(struct bio_status *, struct device *);
305void	bio_status(struct bio_status *, int, int, const char *, va_list *);
306
307void	bio_info(struct bio_status *, int, const char *, ...);
308void	bio_warn(struct bio_status *, int, const char *, ...);
309void	bio_error(struct bio_status *, int, const char *, ...);
310#endif
311
312#endif /* _SYS_DEV_BIOVAR_H_ */
313