1 /*	$OpenBSD: ccdvar.h,v 1.8 2005/03/25 17:51:16 mickey Exp $	*/
2 /*	$NetBSD: ccdvar.h,v 1.11 1996/02/28 01:08:32 thorpej Exp $	*/
3 
4 /*-
5  * Copyright (c) 1996 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Jason R. Thorpe.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *        This product includes software developed by the NetBSD
22  *        Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
31  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * Copyright (c) 1988 University of Utah.
42  * Copyright (c) 1990, 1993
43  *	The Regents of the University of California.  All rights reserved.
44  *
45  * This code is derived from software contributed to Berkeley by
46  * the Systems Programming Group of the University of Utah Computer
47  * Science Department.
48  *
49  * Redistribution and use in source and binary forms, with or without
50  * modification, are permitted provided that the following conditions
51  * are met:
52  * 1. Redistributions of source code must retain the above copyright
53  *    notice, this list of conditions and the following disclaimer.
54  * 2. Redistributions in binary form must reproduce the above copyright
55  *    notice, this list of conditions and the following disclaimer in the
56  *    documentation and/or other materials provided with the distribution.
57  * 3. Neither the name of the University nor the names of its contributors
58  *    may be used to endorse or promote products derived from this software
59  *    without specific prior written permission.
60  *
61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71  * SUCH DAMAGE.
72  *
73  * from: Utah $Hdr: cdvar.h 1.1 90/07/09$
74  *
75  *	@(#)cdvar.h	8.1 (Berkeley) 6/10/93
76  */
77 
78 /*
79  * Dynamic configuration and disklabel support by:
80  *	Jason R. Thorpe <thorpej@nas.nasa.gov>
81  *	Numerical Aerodynamic Simulation Facility
82  *	Mail Stop 258-6
83  *	NASA Ames Research Center
84  *	Moffett Field, CA 94035
85  */
86 
87 /*
88  * A concatenated disk is described at initialization time by this structure.
89  */
90 struct ccddevice {
91 	struct vnode	**ccd_vpp;	/* array of component vnodes */
92 	char		**ccd_cpp;	/* array of component pathnames */
93 	int		ccd_unit;	/* logical unit of this ccd */
94 	int		ccd_interleave;	/* interleave (DEV_BSIZE blocks) */
95 	int		ccd_flags;	/* misc. information */
96 	int		ccd_ndev;	/* number of component devices */
97 };
98 
99 /*
100  * This structure is used to configure a ccd via ioctl(2).
101  */
102 struct ccd_ioctl {
103 	char	**ccio_disks;		/* pointer to component paths */
104 	u_int	ccio_ndisks;		/* number of disks to concatenate */
105 	int	ccio_ileave;		/* interleave (DEV_BSIZE blocks) */
106 	int	ccio_flags;		/* misc. information */
107 	int	ccio_unit;		/* unit number: use varies */
108 	size_t	ccio_size;		/* (returned) size of ccd */
109 };
110 
111 /* ccd_flags */
112 #define	CCDF_SWAP	0x01	/* interleave should be dmmax */
113 #define CCDF_UNIFORM	0x02	/* use LCCD of sizes for uniform interleave */
114 #define CCDF_MIRROR	0x04	/* enable data mirroring */
115 #define CCDF_OLD	0x08	/* use slower but less restrictive I/O code */
116 #define	CCDF_BITS \
117     "\020\01swap\02uniform\03mirror\04old"
118 
119 /* Mask of user-settable ccd flags. */
120 #define CCDF_USERMASK \
121     (CCDF_SWAP|CCDF_UNIFORM|CCDF_MIRROR|CCDF_OLD)
122 
123 /*
124  * Component info table.
125  * Describes a single component of a concatenated disk.
126  */
127 struct ccdcinfo {
128 	struct vnode	*ci_vp;			/* device's vnode */
129 	char		*ci_path;		/* path to component */
130 	size_t		ci_size; 		/* size */
131 	size_t		ci_pathlen;		/* length of component path */
132 	dev_t		ci_dev;			/* XXX: device's dev_t */
133 	int		ci_flags;		/* see below */
134 };
135 
136 #define	CCIF_FAILED	0x01	/* had a B_ERROR on this one */
137 
138 /*
139  * Interleave description table.
140  * Computed at boot time to speed irregular-interleave lookups.
141  * The idea is that we interleave in "groups".  First we interleave
142  * evenly over all component disks up to the size of the smallest
143  * component (the first group), then we interleave evenly over all
144  * remaining disks up to the size of the next-smallest (second group),
145  * and so on.
146  *
147  * Each table entry describes the interleave characteristics of one
148  * of these groups.  For example if a concatenated disk consisted of
149  * three components of 5, 3, and 7 DEV_BSIZE blocks interleaved at
150  * DEV_BSIZE (1), the table would have three entries:
151  *
152  *	ndisk	startblk	startoff	dev
153  *	3	0		0		0, 1, 2
154  *	2	9		3		0, 2
155  *	1	13		5		2
156  *	0	-		-		-
157  *
158  * which says that the first nine blocks (0-8) are interleaved over
159  * 3 disks (0, 1, 2) starting at block offset 0 on any component disk,
160  * the next 4 blocks (9-12) are interleaved over 2 disks (0, 2) starting
161  * at component block 3, and the remaining blocks (13-14) are on disk
162  * 2 starting at offset 5.
163  */
164 struct ccdiinfo {
165 	daddr_t	ii_startblk;	/* starting scaled block # for range */
166 	daddr_t	ii_startoff;	/* starting component offset (block #) */
167 	int	*ii_index;	/* ordered list of components in range */
168 	int	*ii_parity;	/* list of parity shifts */
169 	int	ii_ndisk;	/* # of disks range is interleaved over */
170 };
171 
172 /*
173  * Concatenated disk pseudo-geometry information.
174  */
175 struct ccdgeom {
176 	u_int32_t	ccg_secsize;	/* # bytes per sector */
177 	u_int32_t	ccg_nsectors;	/* # data sectors per track */
178 	u_int32_t	ccg_ntracks;	/* # tracks per cylinder */
179 	u_int32_t	ccg_ncylinders;	/* # cylinders per unit */
180 	u_int16_t	ccg_rpm;
181 };
182 
183 /*
184  * A concatenated disk is described after initialization by this structure.
185  */
186 struct ccd_softc {
187 	struct disk	sc_dkdev;		/* generic disk device info */
188 	struct ccdgeom	sc_geom;		/* pseudo geometry info */
189 	struct ccdcinfo	*sc_cinfo;		/* component info */
190 	struct ccdiinfo	*sc_itable;		/* interleave table */
191 	char		sc_xname[8];		/* XXX external name */
192 	size_t		sc_size;		/* size of ccd */
193 	int		sc_flags;		/* flags */
194 	int		sc_cflags;		/* copy of ccd_flags */
195 	int		sc_ileave;		/* interleave */
196 	u_int		sc_nccdisks;		/* # of components */
197 	u_int		sc_nccunits;		/* # of components for data */
198 };
199 
200 /* sc_flags */
201 #define CCDF_INITED	0x01	/* unit has been initialized */
202 #define CCDF_WLABEL	0x02	/* label area is writable */
203 #define CCDF_LABELLING	0x04	/* unit is currently being labelled */
204 #define CCDF_WANTED	0x40	/* someone is waiting to obtain a lock */
205 #define CCDF_LOCKED	0x80	/* unit is locked */
206 
207 /*
208  * Before you can use a unit, it must be configured with CCDIOCSET.
209  * The configuration persists across opens and closes of the device;
210  * a CCDIOCCLR must be used to reset a configuration.  An attempt to
211  * CCDIOCSET an already active unit will return EBUSY.  Attempts to
212  * CCDIOCCLR an inactive unit will return ENXIO.
213  */
214 #define CCDIOCSET	_IOWR('F', 16, struct ccd_ioctl)   /* enable ccd */
215 #define CCDIOCCLR	_IOW('F', 17, struct ccd_ioctl)    /* disable ccd */
216