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