| 1 | /* $NetBSD: ccdvar.h,v 1.35 2015/09/06 06:00:59 dholland Exp $ */ |
| 2 | |
| 3 | /*- |
| 4 | * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 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 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | * POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | * Copyright (c) 1988 University of Utah. |
| 34 | * Copyright (c) 1990, 1993 |
| 35 | * The Regents of the University of California. All rights reserved. |
| 36 | * |
| 37 | * This code is derived from software contributed to Berkeley by |
| 38 | * the Systems Programming Group of the University of Utah Computer |
| 39 | * Science Department. |
| 40 | * |
| 41 | * Redistribution and use in source and binary forms, with or without |
| 42 | * modification, are permitted provided that the following conditions |
| 43 | * are met: |
| 44 | * 1. Redistributions of source code must retain the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer. |
| 46 | * 2. Redistributions in binary form must reproduce the above copyright |
| 47 | * notice, this list of conditions and the following disclaimer in the |
| 48 | * documentation and/or other materials provided with the distribution. |
| 49 | * 3. Neither the name of the University nor the names of its contributors |
| 50 | * may be used to endorse or promote products derived from this software |
| 51 | * without specific prior written permission. |
| 52 | * |
| 53 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 63 | * SUCH DAMAGE. |
| 64 | * |
| 65 | * from: Utah $Hdr: cdvar.h 1.1 90/07/09$ |
| 66 | * |
| 67 | * @(#)cdvar.h 8.1 (Berkeley) 6/10/93 |
| 68 | */ |
| 69 | |
| 70 | #ifndef _DEV_CCDVAR_H_ |
| 71 | #define _DEV_CCDVAR_H_ |
| 72 | |
| 73 | #include <sys/buf.h> |
| 74 | #include <sys/ioccom.h> |
| 75 | #include <sys/mutex.h> |
| 76 | #include <sys/queue.h> |
| 77 | #include <sys/condvar.h> |
| 78 | |
| 79 | /* |
| 80 | * Dynamic configuration and disklabel support by: |
| 81 | * Jason R. Thorpe <thorpej@nas.nasa.gov> |
| 82 | * Numerical Aerodynamic Simulation Facility |
| 83 | * Mail Stop 258-6 |
| 84 | * NASA Ames Research Center |
| 85 | * Moffett Field, CA 94035 |
| 86 | */ |
| 87 | |
| 88 | /* |
| 89 | * This structure is used to configure a ccd via ioctl(2). |
| 90 | */ |
| 91 | struct ccd_ioctl { |
| 92 | char **ccio_disks; /* pointer to component paths */ |
| 93 | u_int ccio_ndisks; /* number of disks to concatenate */ |
| 94 | int ccio_ileave; /* interleave (DEV_BSIZE blocks) */ |
| 95 | int ccio_flags; /* see sc_flags below */ |
| 96 | int ccio_unit; /* unit number: use varies */ |
| 97 | uint64_t ccio_size; /* (returned) size of ccd */ |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | /* |
| 102 | * Component info table. |
| 103 | * Describes a single component of a concatenated disk. |
| 104 | */ |
| 105 | struct ccdcinfo { |
| 106 | struct vnode *ci_vp; /* device's vnode */ |
| 107 | dev_t ci_dev; /* XXX: device's dev_t */ |
| 108 | uint64_t ci_size; /* size */ |
| 109 | char *ci_path; /* path to component */ |
| 110 | size_t ci_pathlen; /* length of component path */ |
| 111 | }; |
| 112 | |
| 113 | /* |
| 114 | * Interleave description table. |
| 115 | * Computed at boot time to speed irregular-interleave lookups. |
| 116 | * The idea is that we interleave in "groups". First we interleave |
| 117 | * evenly over all component disks up to the size of the smallest |
| 118 | * component (the first group), then we interleave evenly over all |
| 119 | * remaining disks up to the size of the next-smallest (second group), |
| 120 | * and so on. |
| 121 | * |
| 122 | * Each table entry describes the interleave characteristics of one |
| 123 | * of these groups. For example if a concatenated disk consisted of |
| 124 | * three components of 5, 3, and 7 DEV_BSIZE blocks interleaved at |
| 125 | * DEV_BSIZE (1), the table would have three entries: |
| 126 | * |
| 127 | * ndisk startblk startoff dev |
| 128 | * 3 0 0 0, 1, 2 |
| 129 | * 2 9 3 0, 2 |
| 130 | * 1 13 5 2 |
| 131 | * 0 - - - |
| 132 | * |
| 133 | * which says that the first nine blocks (0-8) are interleaved over |
| 134 | * 3 disks (0, 1, 2) starting at block offset 0 on any component disk, |
| 135 | * the next 4 blocks (9-12) are interleaved over 2 disks (0, 2) starting |
| 136 | * at component block 3, and the remaining blocks (13-14) are on disk |
| 137 | * 2 starting at offset 5. |
| 138 | */ |
| 139 | struct ccdiinfo { |
| 140 | int ii_ndisk; /* # of disks range is interleaved over */ |
| 141 | daddr_t ii_startblk; /* starting scaled block # for range */ |
| 142 | daddr_t ii_startoff; /* starting component offset (block #) */ |
| 143 | int *ii_index; /* ordered list of components in range */ |
| 144 | size_t ii_indexsz; /* size of memory area */ |
| 145 | }; |
| 146 | |
| 147 | /* |
| 148 | * Concatenated disk pseudo-geometry information. |
| 149 | */ |
| 150 | struct ccdgeom { |
| 151 | u_int32_t ccg_secsize; /* # bytes per sector */ |
| 152 | u_int32_t ccg_nsectors; /* # data sectors per track */ |
| 153 | u_int32_t ccg_ntracks; /* # tracks per cylinder */ |
| 154 | u_int32_t ccg_ncylinders; /* # cylinders per unit */ |
| 155 | }; |
| 156 | |
| 157 | struct ccdbuf; |
| 158 | |
| 159 | /* |
| 160 | * A concatenated disk is described after initialization by this structure. |
| 161 | */ |
| 162 | struct ccd_softc { |
| 163 | int sc_unit; |
| 164 | int sc_flags; /* flags */ |
| 165 | uint64_t sc_size; /* size of ccd */ |
| 166 | int sc_ileave; /* interleave */ |
| 167 | u_int sc_nccdisks; /* number of components */ |
| 168 | #define CCD_MAXNDISKS 65536 |
| 169 | struct ccdcinfo *sc_cinfo; /* component info */ |
| 170 | struct ccdiinfo *sc_itable; /* interleave table */ |
| 171 | struct ccdgeom sc_geom; /* pseudo geometry info */ |
| 172 | char sc_xname[8]; /* XXX external name */ |
| 173 | struct disk sc_dkdev; /* generic disk device info */ |
| 174 | kmutex_t sc_dvlock; /* lock on device node */ |
| 175 | struct bufq_state *sc_bufq; /* buffer queue */ |
| 176 | kmutex_t *sc_iolock; /* lock on I/O start/stop */ |
| 177 | kcondvar_t sc_stop; /* when inflight goes zero */ |
| 178 | struct lwp *sc_thread; /* for deferred I/O */ |
| 179 | kcondvar_t sc_push; /* for deferred I/O */ |
| 180 | bool sc_zap; /* for deferred I/O */ |
| 181 | LIST_ENTRY(ccd_softc) sc_link; |
| 182 | }; |
| 183 | |
| 184 | /* sc_flags */ |
| 185 | #define CCDF_UNIFORM 0x002 /* use LCCD of sizes for uniform interleave */ |
| 186 | #define CCDF_NOLABEL 0x004 /* ignore on-disk (raw) disklabel */ |
| 187 | |
| 188 | #define CCDF_INITED 0x010 /* unit has been initialized */ |
| 189 | #define CCDF_WLABEL 0x020 /* label area is writable */ |
| 190 | #define CCDF_LABELLING 0x040 /* unit is currently being labelled */ |
| 191 | #define CCDF_KLABEL 0x080 /* keep label on close */ |
| 192 | #define CCDF_VLABEL 0x100 /* label is valid */ |
| 193 | #define CCDF_RLABEL 0x200 /* currently reading label */ |
| 194 | |
| 195 | /* Mask of user-settable ccd flags. */ |
| 196 | #define CCDF_USERMASK (CCDF_UNIFORM|CCDF_NOLABEL) |
| 197 | |
| 198 | /* |
| 199 | * Before you can use a unit, it must be configured with CCDIOCSET. |
| 200 | * The configuration persists across opens and closes of the device; |
| 201 | * a CCDIOCCLR must be used to reset a configuration. An attempt to |
| 202 | * CCDIOCSET an already active unit will return EBUSY. Attempts to |
| 203 | * CCDIOCCLR an inactive unit will return ENXIO. |
| 204 | */ |
| 205 | #define CCDIOCSET _IOWR('F', 16, struct ccd_ioctl) /* enable ccd */ |
| 206 | #define CCDIOCCLR _IOW('F', 17, struct ccd_ioctl) /* disable ccd */ |
| 207 | |
| 208 | #if defined(COMPAT_60) && !defined(_LP64) |
| 209 | /* |
| 210 | * Old version with incorrect ccio_size |
| 211 | */ |
| 212 | struct ccd_ioctl_60 { |
| 213 | char **ccio_disks; /* pointer to component paths */ |
| 214 | u_int ccio_ndisks; /* number of disks to concatenate */ |
| 215 | int ccio_ileave; /* interleave (DEV_BSIZE blocks) */ |
| 216 | int ccio_flags; /* see sc_flags below */ |
| 217 | int ccio_unit; /* unit number: use varies */ |
| 218 | size_t ccio_size; /* (returned) size of ccd */ |
| 219 | }; |
| 220 | |
| 221 | #define CCDIOCSET_60 _IOWR('F', 16, struct ccd_ioctl_60) /* enable ccd */ |
| 222 | #define CCDIOCCLR_60 _IOW('F', 17, struct ccd_ioctl_60) /* disable ccd */ |
| 223 | #endif /* COMPAT_60 && !LP64*/ |
| 224 | /* |
| 225 | * Sysctl information |
| 226 | */ |
| 227 | struct ccddiskinfo { |
| 228 | int ccd_ileave; |
| 229 | u_int ccd_ndisks; |
| 230 | uint64_t ccd_size; |
| 231 | int ccd_flags; |
| 232 | }; |
| 233 | |
| 234 | #endif /* _DEV_CCDVAR_H_ */ |
| 235 | |