ccd.c revision 1.1 1 1.1 hpeyerl /*
2 1.1 hpeyerl * Copyright (c) 1988 University of Utah.
3 1.1 hpeyerl * Copyright (c) 1990 The Regents of the University of California.
4 1.1 hpeyerl * All rights reserved.
5 1.1 hpeyerl *
6 1.1 hpeyerl * This code is derived from software contributed to Berkeley by
7 1.1 hpeyerl * the Systems Programming Group of the University of Utah Computer
8 1.1 hpeyerl * Science Department.
9 1.1 hpeyerl *
10 1.1 hpeyerl * Redistribution and use in source and binary forms, with or without
11 1.1 hpeyerl * modification, are permitted provided that the following conditions
12 1.1 hpeyerl * are met:
13 1.1 hpeyerl * 1. Redistributions of source code must retain the above copyright
14 1.1 hpeyerl * notice, this list of conditions and the following disclaimer.
15 1.1 hpeyerl * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 hpeyerl * notice, this list of conditions and the following disclaimer in the
17 1.1 hpeyerl * documentation and/or other materials provided with the distribution.
18 1.1 hpeyerl * 3. All advertising materials mentioning features or use of this software
19 1.1 hpeyerl * must display the following acknowledgement:
20 1.1 hpeyerl * This product includes software developed by the University of
21 1.1 hpeyerl * California, Berkeley and its contributors.
22 1.1 hpeyerl * 4. Neither the name of the University nor the names of its contributors
23 1.1 hpeyerl * may be used to endorse or promote products derived from this software
24 1.1 hpeyerl * without specific prior written permission.
25 1.1 hpeyerl *
26 1.1 hpeyerl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 hpeyerl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 hpeyerl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 hpeyerl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 hpeyerl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 hpeyerl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 hpeyerl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 hpeyerl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 hpeyerl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 hpeyerl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 hpeyerl * SUCH DAMAGE.
37 1.1 hpeyerl *
38 1.1 hpeyerl * from: Utah Hdr: ccd.c 1.6 90/11/28
39 1.1 hpeyerl * from: @(#)cd.c 7.4 (Berkeley) 5/7/91
40 1.1 hpeyerl * $Id: ccd.c,v 1.1 1994/06/24 14:11:02 hpeyerl Exp $
41 1.1 hpeyerl */
42 1.1 hpeyerl
43 1.1 hpeyerl /*
44 1.1 hpeyerl * "Concatenated" disk driver.
45 1.1 hpeyerl */
46 1.1 hpeyerl #include "ccd.h"
47 1.1 hpeyerl #if NCCD > 0
48 1.1 hpeyerl
49 1.1 hpeyerl #include <sys/param.h>
50 1.1 hpeyerl #include <sys/systm.h>
51 1.1 hpeyerl #include <sys/errno.h>
52 1.1 hpeyerl #include <sys/dkstat.h>
53 1.1 hpeyerl #include <sys/buf.h>
54 1.1 hpeyerl #include <sys/malloc.h>
55 1.1 hpeyerl #include <sys/conf.h>
56 1.1 hpeyerl
57 1.1 hpeyerl #include <dev/ccdvar.h>
58 1.1 hpeyerl
59 1.1 hpeyerl #ifdef DEBUG
60 1.1 hpeyerl int ccddebug = 0x00;
61 1.1 hpeyerl #define CDB_FOLLOW 0x01
62 1.1 hpeyerl #define CDB_INIT 0x02
63 1.1 hpeyerl #define CDB_IO 0x04
64 1.1 hpeyerl #endif
65 1.1 hpeyerl
66 1.1 hpeyerl struct buf ccdbuf[NCCD];
67 1.1 hpeyerl struct buf *ccdbuffer();
68 1.1 hpeyerl char *ccddevtostr();
69 1.1 hpeyerl int ccdiodone();
70 1.1 hpeyerl
71 1.1 hpeyerl #define ccdunit(x) ((minor(x) >> 3) & 0x7) /* for consistency */
72 1.1 hpeyerl
73 1.1 hpeyerl #define getcbuf() \
74 1.1 hpeyerl ((struct buf *)malloc(sizeof(struct buf), M_DEVBUF, M_WAITOK))
75 1.1 hpeyerl #define putcbuf(bp) \
76 1.1 hpeyerl free((caddr_t)(bp), M_DEVBUF)
77 1.1 hpeyerl
78 1.1 hpeyerl struct ccd_softc {
79 1.1 hpeyerl int sc_flags; /* flags */
80 1.1 hpeyerl size_t sc_size; /* size of ccd */
81 1.1 hpeyerl int sc_ileave; /* interleave */
82 1.1 hpeyerl int sc_nccdisks; /* number of components */
83 1.1 hpeyerl struct ccdcinfo sc_cinfo[NCCDISKS]; /* component info */
84 1.1 hpeyerl struct ccdiinfo *sc_itable; /* interleave table */
85 1.1 hpeyerl int sc_usecnt; /* number of requests active */
86 1.1 hpeyerl struct buf *sc_bp; /* "current" request */
87 1.1 hpeyerl int sc_dk; /* disk index */
88 1.1 hpeyerl } ccd_softc[NCCD];
89 1.1 hpeyerl
90 1.1 hpeyerl /* sc_flags */
91 1.1 hpeyerl #define CDF_ALIVE 0x01
92 1.1 hpeyerl #define CDF_INITED 0x02
93 1.1 hpeyerl
94 1.1 hpeyerl /*
95 1.1 hpeyerl * ccdattach() is called at boot time in new systems. We do
96 1.1 hpeyerl * nothing here since old systems will not call this.
97 1.1 hpeyerl */
98 1.1 hpeyerl
99 1.1 hpeyerl void
100 1.1 hpeyerl ccdattach(n)
101 1.1 hpeyerl int n;
102 1.1 hpeyerl {
103 1.1 hpeyerl }
104 1.1 hpeyerl
105 1.1 hpeyerl ccdinit(ccd)
106 1.1 hpeyerl struct ccddevice *ccd;
107 1.1 hpeyerl {
108 1.1 hpeyerl register struct ccd_softc *cs = &ccd_softc[ccd->ccd_unit];
109 1.1 hpeyerl register struct ccdcinfo *ci;
110 1.1 hpeyerl register size_t size;
111 1.1 hpeyerl register int ix;
112 1.1 hpeyerl size_t minsize;
113 1.1 hpeyerl dev_t dev;
114 1.1 hpeyerl
115 1.1 hpeyerl #ifdef DEBUG
116 1.1 hpeyerl if (ccddebug & (CDB_FOLLOW|CDB_INIT))
117 1.1 hpeyerl printf("ccdinit: unit %d\n", ccd->ccd_unit);
118 1.1 hpeyerl #endif
119 1.1 hpeyerl cs->sc_dk = ccd->ccd_dk;
120 1.1 hpeyerl cs->sc_size = 0;
121 1.1 hpeyerl cs->sc_ileave = ccd->ccd_interleave;
122 1.1 hpeyerl cs->sc_nccdisks = 0;
123 1.1 hpeyerl /*
124 1.1 hpeyerl * Verify that each component piece exists and record
125 1.1 hpeyerl * relevant information about it.
126 1.1 hpeyerl */
127 1.1 hpeyerl minsize = 0;
128 1.1 hpeyerl for (ix = 0; ix < NCCDISKS; ix++) {
129 1.1 hpeyerl if ((dev = ccd->ccd_dev[ix]) == NODEV)
130 1.1 hpeyerl break;
131 1.1 hpeyerl ci = &cs->sc_cinfo[ix];
132 1.1 hpeyerl ci->ci_dev = dev;
133 1.1 hpeyerl /*
134 1.1 hpeyerl * Calculate size (truncated to interleave boundary
135 1.1 hpeyerl * if necessary.
136 1.1 hpeyerl */
137 1.1 hpeyerl if (bdevsw[major(dev)].d_psize) {
138 1.1 hpeyerl size = (size_t) (*bdevsw[major(dev)].d_psize)(dev);
139 1.1 hpeyerl if ((int)size < 0)
140 1.1 hpeyerl size = 0;
141 1.1 hpeyerl } else
142 1.1 hpeyerl size = 0;
143 1.1 hpeyerl if (cs->sc_ileave > 1)
144 1.1 hpeyerl size -= size % cs->sc_ileave;
145 1.1 hpeyerl if (size == 0) {
146 1.1 hpeyerl printf("ccd%d: not configured (component %s missing)\n",
147 1.1 hpeyerl ccd->ccd_unit, ccddevtostr(ci->ci_dev));
148 1.1 hpeyerl return(0);
149 1.1 hpeyerl }
150 1.1 hpeyerl if (minsize == 0 || size < minsize)
151 1.1 hpeyerl minsize = size;
152 1.1 hpeyerl ci->ci_size = size;
153 1.1 hpeyerl cs->sc_size += size;
154 1.1 hpeyerl cs->sc_nccdisks++;
155 1.1 hpeyerl }
156 1.1 hpeyerl /*
157 1.1 hpeyerl * If uniform interleave is desired set all sizes to that of
158 1.1 hpeyerl * the smallest component.
159 1.1 hpeyerl */
160 1.1 hpeyerl if (ccd->ccd_flags & CDF_UNIFORM) {
161 1.1 hpeyerl for (ci = cs->sc_cinfo;
162 1.1 hpeyerl ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
163 1.1 hpeyerl ci->ci_size = minsize;
164 1.1 hpeyerl cs->sc_size = cs->sc_nccdisks * minsize;
165 1.1 hpeyerl }
166 1.1 hpeyerl /*
167 1.1 hpeyerl * Construct the interleave table
168 1.1 hpeyerl */
169 1.1 hpeyerl if (!ccdinterleave(cs))
170 1.1 hpeyerl return(0);
171 1.1 hpeyerl if (ccd->ccd_dk >= 0)
172 1.1 hpeyerl dk_wpms[ccd->ccd_dk] = 32 * (60 * DEV_BSIZE / 2); /* XXX */
173 1.1 hpeyerl printf("ccd%d: %d components ", ccd->ccd_unit, cs->sc_nccdisks);
174 1.1 hpeyerl for (ix = 0; ix < cs->sc_nccdisks; ix++)
175 1.1 hpeyerl printf("%c%s%c",
176 1.1 hpeyerl ix == 0 ? '(' : ' ',
177 1.1 hpeyerl ccddevtostr(cs->sc_cinfo[ix].ci_dev),
178 1.1 hpeyerl ix == cs->sc_nccdisks - 1 ? ')' : ',');
179 1.1 hpeyerl printf(", %d blocks ", cs->sc_size);
180 1.1 hpeyerl if (cs->sc_ileave)
181 1.1 hpeyerl printf("interleaved at %d blocks\n", cs->sc_ileave);
182 1.1 hpeyerl else
183 1.1 hpeyerl printf("concatenated\n");
184 1.1 hpeyerl cs->sc_flags = CDF_ALIVE | CDF_INITED;
185 1.1 hpeyerl return(1);
186 1.1 hpeyerl }
187 1.1 hpeyerl
188 1.1 hpeyerl /*
189 1.1 hpeyerl * XXX not really ccd specific.
190 1.1 hpeyerl */
191 1.1 hpeyerl char *
192 1.1 hpeyerl ccddevtostr(dev)
193 1.1 hpeyerl dev_t dev;
194 1.1 hpeyerl {
195 1.1 hpeyerl static char dbuf[5];
196 1.1 hpeyerl
197 1.1 hpeyerl dbuf[1] = 'd';
198 1.1 hpeyerl switch (major(dev)) {
199 1.1 hpeyerl case 2:
200 1.1 hpeyerl dbuf[0] = 'r';
201 1.1 hpeyerl break;
202 1.1 hpeyerl case 4:
203 1.1 hpeyerl dbuf[0] = 's';
204 1.1 hpeyerl break;
205 1.1 hpeyerl case 5:
206 1.1 hpeyerl dbuf[0] = 'c';
207 1.1 hpeyerl break;
208 1.1 hpeyerl default:
209 1.1 hpeyerl dbuf[0] = dbuf[1] = '?';
210 1.1 hpeyerl break;
211 1.1 hpeyerl }
212 1.1 hpeyerl dbuf[2] = (minor(dev) >> 3) + '0';
213 1.1 hpeyerl dbuf[3] = (minor(dev) & 7) + 'a';
214 1.1 hpeyerl dbuf[4] = '\0';
215 1.1 hpeyerl return (dbuf);
216 1.1 hpeyerl }
217 1.1 hpeyerl
218 1.1 hpeyerl ccdinterleave(cs)
219 1.1 hpeyerl register struct ccd_softc *cs;
220 1.1 hpeyerl {
221 1.1 hpeyerl register struct ccdcinfo *ci, *smallci;
222 1.1 hpeyerl register struct ccdiinfo *ii;
223 1.1 hpeyerl register daddr_t bn, lbn;
224 1.1 hpeyerl register int ix;
225 1.1 hpeyerl u_long size;
226 1.1 hpeyerl
227 1.1 hpeyerl #ifdef DEBUG
228 1.1 hpeyerl if (ccddebug & CDB_INIT)
229 1.1 hpeyerl printf("ccdinterleave(%x): ileave %d\n", cs, cs->sc_ileave);
230 1.1 hpeyerl #endif
231 1.1 hpeyerl /*
232 1.1 hpeyerl * Allocate an interleave table.
233 1.1 hpeyerl * Chances are this is too big, but we don't care.
234 1.1 hpeyerl */
235 1.1 hpeyerl size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo);
236 1.1 hpeyerl cs->sc_itable = (struct ccdiinfo *)malloc(size, M_DEVBUF, M_WAITOK);
237 1.1 hpeyerl bzero((caddr_t)cs->sc_itable, size);
238 1.1 hpeyerl /*
239 1.1 hpeyerl * Trivial case: no interleave (actually interleave of disk size).
240 1.1 hpeyerl * Each table entry represent a single component in its entirety.
241 1.1 hpeyerl */
242 1.1 hpeyerl if (cs->sc_ileave == 0) {
243 1.1 hpeyerl bn = 0;
244 1.1 hpeyerl ii = cs->sc_itable;
245 1.1 hpeyerl for (ix = 0; ix < cs->sc_nccdisks; ix++) {
246 1.1 hpeyerl ii->ii_ndisk = 1;
247 1.1 hpeyerl ii->ii_startblk = bn;
248 1.1 hpeyerl ii->ii_startoff = 0;
249 1.1 hpeyerl ii->ii_index[0] = ix;
250 1.1 hpeyerl bn += cs->sc_cinfo[ix].ci_size;
251 1.1 hpeyerl ii++;
252 1.1 hpeyerl }
253 1.1 hpeyerl ii->ii_ndisk = 0;
254 1.1 hpeyerl #ifdef DEBUG
255 1.1 hpeyerl if (ccddebug & CDB_INIT)
256 1.1 hpeyerl printiinfo(cs->sc_itable);
257 1.1 hpeyerl #endif
258 1.1 hpeyerl return(1);
259 1.1 hpeyerl }
260 1.1 hpeyerl /*
261 1.1 hpeyerl * The following isn't fast or pretty; it doesn't have to be.
262 1.1 hpeyerl */
263 1.1 hpeyerl size = 0;
264 1.1 hpeyerl bn = lbn = 0;
265 1.1 hpeyerl for (ii = cs->sc_itable; ; ii++) {
266 1.1 hpeyerl /*
267 1.1 hpeyerl * Locate the smallest of the remaining components
268 1.1 hpeyerl */
269 1.1 hpeyerl smallci = NULL;
270 1.1 hpeyerl for (ci = cs->sc_cinfo;
271 1.1 hpeyerl ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
272 1.1 hpeyerl if (ci->ci_size > size &&
273 1.1 hpeyerl (smallci == NULL ||
274 1.1 hpeyerl ci->ci_size < smallci->ci_size))
275 1.1 hpeyerl smallci = ci;
276 1.1 hpeyerl /*
277 1.1 hpeyerl * Nobody left, all done
278 1.1 hpeyerl */
279 1.1 hpeyerl if (smallci == NULL) {
280 1.1 hpeyerl ii->ii_ndisk = 0;
281 1.1 hpeyerl break;
282 1.1 hpeyerl }
283 1.1 hpeyerl /*
284 1.1 hpeyerl * Record starting logical block and component offset
285 1.1 hpeyerl */
286 1.1 hpeyerl ii->ii_startblk = bn / cs->sc_ileave;
287 1.1 hpeyerl ii->ii_startoff = lbn;
288 1.1 hpeyerl /*
289 1.1 hpeyerl * Determine how many disks take part in this interleave
290 1.1 hpeyerl * and record their indices.
291 1.1 hpeyerl */
292 1.1 hpeyerl ix = 0;
293 1.1 hpeyerl for (ci = cs->sc_cinfo;
294 1.1 hpeyerl ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
295 1.1 hpeyerl if (ci->ci_size >= smallci->ci_size)
296 1.1 hpeyerl ii->ii_index[ix++] = ci - cs->sc_cinfo;
297 1.1 hpeyerl ii->ii_ndisk = ix;
298 1.1 hpeyerl bn += ix * (smallci->ci_size - size);
299 1.1 hpeyerl lbn = smallci->ci_size / cs->sc_ileave;
300 1.1 hpeyerl size = smallci->ci_size;
301 1.1 hpeyerl }
302 1.1 hpeyerl #ifdef DEBUG
303 1.1 hpeyerl if (ccddebug & CDB_INIT)
304 1.1 hpeyerl printiinfo(cs->sc_itable);
305 1.1 hpeyerl #endif
306 1.1 hpeyerl return(1);
307 1.1 hpeyerl }
308 1.1 hpeyerl
309 1.1 hpeyerl #ifdef DEBUG
310 1.1 hpeyerl printiinfo(ii)
311 1.1 hpeyerl struct ccdiinfo *ii;
312 1.1 hpeyerl {
313 1.1 hpeyerl register int ix, i;
314 1.1 hpeyerl
315 1.1 hpeyerl for (ix = 0; ii->ii_ndisk; ix++, ii++) {
316 1.1 hpeyerl printf(" itab[%d]: #dk %d sblk %d soff %d",
317 1.1 hpeyerl ix, ii->ii_ndisk, ii->ii_startblk, ii->ii_startoff);
318 1.1 hpeyerl for (i = 0; i < ii->ii_ndisk; i++)
319 1.1 hpeyerl printf(" %d", ii->ii_index[i]);
320 1.1 hpeyerl printf("\n");
321 1.1 hpeyerl }
322 1.1 hpeyerl }
323 1.1 hpeyerl #endif
324 1.1 hpeyerl
325 1.1 hpeyerl ccdopen(dev, flags)
326 1.1 hpeyerl dev_t dev;
327 1.1 hpeyerl {
328 1.1 hpeyerl int unit = ccdunit(dev);
329 1.1 hpeyerl register struct ccd_softc *cs = &ccd_softc[unit];
330 1.1 hpeyerl
331 1.1 hpeyerl #ifdef DEBUG
332 1.1 hpeyerl if (ccddebug & CDB_FOLLOW)
333 1.1 hpeyerl printf("ccdopen(%x, %x)\n", dev, flags);
334 1.1 hpeyerl #endif
335 1.1 hpeyerl if (unit >= NCCD || (cs->sc_flags & CDF_ALIVE) == 0)
336 1.1 hpeyerl return(ENXIO);
337 1.1 hpeyerl return(0);
338 1.1 hpeyerl }
339 1.1 hpeyerl
340 1.1 hpeyerl void
341 1.1 hpeyerl ccdstrategy(bp)
342 1.1 hpeyerl register struct buf *bp;
343 1.1 hpeyerl {
344 1.1 hpeyerl register int unit = ccdunit(bp->b_dev);
345 1.1 hpeyerl register struct ccd_softc *cs = &ccd_softc[unit];
346 1.1 hpeyerl register daddr_t bn;
347 1.1 hpeyerl register int sz, s;
348 1.1 hpeyerl
349 1.1 hpeyerl #ifdef DEBUG
350 1.1 hpeyerl if (ccddebug & CDB_FOLLOW)
351 1.1 hpeyerl printf("ccdstrategy(%x): unit %d\n", bp, unit);
352 1.1 hpeyerl #endif
353 1.1 hpeyerl if ((cs->sc_flags & CDF_INITED) == 0) {
354 1.1 hpeyerl bp->b_error = ENXIO;
355 1.1 hpeyerl bp->b_flags |= B_ERROR;
356 1.1 hpeyerl goto done;
357 1.1 hpeyerl }
358 1.1 hpeyerl bn = bp->b_blkno;
359 1.1 hpeyerl sz = howmany(bp->b_bcount, DEV_BSIZE);
360 1.1 hpeyerl if (bn < 0 || bn + sz > cs->sc_size) {
361 1.1 hpeyerl sz = cs->sc_size - bn;
362 1.1 hpeyerl if (sz == 0) {
363 1.1 hpeyerl bp->b_resid = bp->b_bcount;
364 1.1 hpeyerl goto done;
365 1.1 hpeyerl }
366 1.1 hpeyerl if (sz < 0) {
367 1.1 hpeyerl bp->b_error = EINVAL;
368 1.1 hpeyerl bp->b_flags |= B_ERROR;
369 1.1 hpeyerl goto done;
370 1.1 hpeyerl }
371 1.1 hpeyerl bp->b_bcount = dbtob(sz);
372 1.1 hpeyerl }
373 1.1 hpeyerl bp->b_resid = bp->b_bcount;
374 1.1 hpeyerl /*
375 1.1 hpeyerl * "Start" the unit.
376 1.1 hpeyerl * XXX: the use of sc_bp is just to retain the "traditional"
377 1.1 hpeyerl * interface to the start routine.
378 1.1 hpeyerl */
379 1.1 hpeyerl s = splbio();
380 1.1 hpeyerl cs->sc_bp = bp;
381 1.1 hpeyerl ccdstart(unit);
382 1.1 hpeyerl splx(s);
383 1.1 hpeyerl return;
384 1.1 hpeyerl done:
385 1.1 hpeyerl biodone(bp);
386 1.1 hpeyerl }
387 1.1 hpeyerl
388 1.1 hpeyerl ccdstart(unit)
389 1.1 hpeyerl int unit;
390 1.1 hpeyerl {
391 1.1 hpeyerl register struct ccd_softc *cs = &ccd_softc[unit];
392 1.1 hpeyerl register struct buf *bp = cs->sc_bp;
393 1.1 hpeyerl register long bcount, rcount;
394 1.1 hpeyerl struct buf *cbp;
395 1.1 hpeyerl caddr_t addr;
396 1.1 hpeyerl daddr_t bn;
397 1.1 hpeyerl
398 1.1 hpeyerl #ifdef DEBUG
399 1.1 hpeyerl if (ccddebug & CDB_FOLLOW)
400 1.1 hpeyerl printf("ccdstart(%d)\n", unit);
401 1.1 hpeyerl #endif
402 1.1 hpeyerl /*
403 1.1 hpeyerl * Instumentation (not real meaningful)
404 1.1 hpeyerl */
405 1.1 hpeyerl cs->sc_usecnt++;
406 1.1 hpeyerl if (cs->sc_dk >= 0) {
407 1.1 hpeyerl dk_busy |= 1 << cs->sc_dk;
408 1.1 hpeyerl dk_xfer[cs->sc_dk]++;
409 1.1 hpeyerl dk_wds[cs->sc_dk] += bp->b_bcount >> 6;
410 1.1 hpeyerl }
411 1.1 hpeyerl /*
412 1.1 hpeyerl * Allocate component buffers and fire off the requests
413 1.1 hpeyerl */
414 1.1 hpeyerl bn = bp->b_blkno;
415 1.1 hpeyerl addr = bp->b_un.b_addr;
416 1.1 hpeyerl for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) {
417 1.1 hpeyerl cbp = ccdbuffer(cs, bp, bn, addr, bcount);
418 1.1 hpeyerl rcount = cbp->b_bcount;
419 1.1 hpeyerl (*bdevsw[major(cbp->b_dev)].d_strategy)(cbp);
420 1.1 hpeyerl bn += btodb(rcount);
421 1.1 hpeyerl addr += rcount;
422 1.1 hpeyerl }
423 1.1 hpeyerl }
424 1.1 hpeyerl
425 1.1 hpeyerl /*
426 1.1 hpeyerl * Build a component buffer header.
427 1.1 hpeyerl */
428 1.1 hpeyerl struct buf *
429 1.1 hpeyerl ccdbuffer(cs, bp, bn, addr, bcount)
430 1.1 hpeyerl register struct ccd_softc *cs;
431 1.1 hpeyerl struct buf *bp;
432 1.1 hpeyerl daddr_t bn;
433 1.1 hpeyerl caddr_t addr;
434 1.1 hpeyerl long bcount;
435 1.1 hpeyerl {
436 1.1 hpeyerl register struct ccdcinfo *ci;
437 1.1 hpeyerl register struct buf *cbp;
438 1.1 hpeyerl register daddr_t cbn, cboff;
439 1.1 hpeyerl
440 1.1 hpeyerl #ifdef DEBUG
441 1.1 hpeyerl if (ccddebug & CDB_IO)
442 1.1 hpeyerl printf("ccdbuffer(%x, %x, %d, %x, %d)\n",
443 1.1 hpeyerl cs, bp, bn, addr, bcount);
444 1.1 hpeyerl #endif
445 1.1 hpeyerl /*
446 1.1 hpeyerl * Determine which component bn falls in.
447 1.1 hpeyerl */
448 1.1 hpeyerl cbn = bn;
449 1.1 hpeyerl cboff = 0;
450 1.1 hpeyerl /*
451 1.1 hpeyerl * Serially concatenated
452 1.1 hpeyerl */
453 1.1 hpeyerl if (cs->sc_ileave == 0) {
454 1.1 hpeyerl register daddr_t sblk;
455 1.1 hpeyerl
456 1.1 hpeyerl sblk = 0;
457 1.1 hpeyerl for (ci = cs->sc_cinfo; cbn >= sblk + ci->ci_size; ci++)
458 1.1 hpeyerl sblk += ci->ci_size;
459 1.1 hpeyerl cbn -= sblk;
460 1.1 hpeyerl }
461 1.1 hpeyerl /*
462 1.1 hpeyerl * Interleaved
463 1.1 hpeyerl */
464 1.1 hpeyerl else {
465 1.1 hpeyerl register struct ccdiinfo *ii;
466 1.1 hpeyerl int ccdisk, off;
467 1.1 hpeyerl
468 1.1 hpeyerl cboff = cbn % cs->sc_ileave;
469 1.1 hpeyerl cbn /= cs->sc_ileave;
470 1.1 hpeyerl for (ii = cs->sc_itable; ii->ii_ndisk; ii++)
471 1.1 hpeyerl if (ii->ii_startblk > cbn)
472 1.1 hpeyerl break;
473 1.1 hpeyerl ii--;
474 1.1 hpeyerl off = cbn - ii->ii_startblk;
475 1.1 hpeyerl if (ii->ii_ndisk == 1) {
476 1.1 hpeyerl ccdisk = ii->ii_index[0];
477 1.1 hpeyerl cbn = ii->ii_startoff + off;
478 1.1 hpeyerl } else {
479 1.1 hpeyerl ccdisk = ii->ii_index[off % ii->ii_ndisk];
480 1.1 hpeyerl cbn = ii->ii_startoff + off / ii->ii_ndisk;
481 1.1 hpeyerl }
482 1.1 hpeyerl cbn *= cs->sc_ileave;
483 1.1 hpeyerl ci = &cs->sc_cinfo[ccdisk];
484 1.1 hpeyerl }
485 1.1 hpeyerl /*
486 1.1 hpeyerl * Fill in the component buf structure.
487 1.1 hpeyerl */
488 1.1 hpeyerl cbp = getcbuf();
489 1.1 hpeyerl cbp->b_flags = bp->b_flags | B_CALL;
490 1.1 hpeyerl cbp->b_iodone = ccdiodone;
491 1.1 hpeyerl cbp->b_proc = bp->b_proc;
492 1.1 hpeyerl cbp->b_dev = ci->ci_dev;
493 1.1 hpeyerl cbp->b_blkno = cbn + cboff;
494 1.1 hpeyerl cbp->b_un.b_addr = addr;
495 1.1 hpeyerl cbp->b_vp = 0;
496 1.1 hpeyerl if (cs->sc_ileave == 0)
497 1.1 hpeyerl cbp->b_bcount = dbtob(ci->ci_size - cbn);
498 1.1 hpeyerl else
499 1.1 hpeyerl cbp->b_bcount = dbtob(cs->sc_ileave - cboff);
500 1.1 hpeyerl if (cbp->b_bcount > bcount)
501 1.1 hpeyerl cbp->b_bcount = bcount;
502 1.1 hpeyerl /*
503 1.1 hpeyerl * XXX: context for ccdiodone
504 1.1 hpeyerl */
505 1.1 hpeyerl cbp->b_saveaddr = (caddr_t)bp;
506 1.1 hpeyerl cbp->b_pfcent = ((cs - ccd_softc) << 16) | (ci - cs->sc_cinfo);
507 1.1 hpeyerl #ifdef DEBUG
508 1.1 hpeyerl if (ccddebug & CDB_IO)
509 1.1 hpeyerl printf(" dev %x(u%d): cbp %x bn %d addr %x bcnt %d\n",
510 1.1 hpeyerl ci->ci_dev, ci-cs->sc_cinfo, cbp, cbp->b_blkno,
511 1.1 hpeyerl cbp->b_un.b_addr, cbp->b_bcount);
512 1.1 hpeyerl #endif
513 1.1 hpeyerl return(cbp);
514 1.1 hpeyerl }
515 1.1 hpeyerl
516 1.1 hpeyerl ccdintr(unit)
517 1.1 hpeyerl int unit;
518 1.1 hpeyerl {
519 1.1 hpeyerl register struct ccd_softc *cs = &ccd_softc[unit];
520 1.1 hpeyerl register struct buf *bp = cs->sc_bp;
521 1.1 hpeyerl
522 1.1 hpeyerl #ifdef DEBUG
523 1.1 hpeyerl if (ccddebug & CDB_FOLLOW)
524 1.1 hpeyerl printf("ccdintr(%d): bp %x\n", unit, bp);
525 1.1 hpeyerl #endif
526 1.1 hpeyerl /*
527 1.1 hpeyerl * Request is done for better or worse, wakeup the top half.
528 1.1 hpeyerl */
529 1.1 hpeyerl if (--cs->sc_usecnt == 0 && cs->sc_dk >= 0)
530 1.1 hpeyerl dk_busy &= ~(1 << cs->sc_dk);
531 1.1 hpeyerl if (bp->b_flags & B_ERROR)
532 1.1 hpeyerl bp->b_resid = bp->b_bcount;
533 1.1 hpeyerl biodone(bp);
534 1.1 hpeyerl }
535 1.1 hpeyerl
536 1.1 hpeyerl /*
537 1.1 hpeyerl * Called by biodone at interrupt time.
538 1.1 hpeyerl * Mark the component as done and if all components are done,
539 1.1 hpeyerl * take a ccd interrupt.
540 1.1 hpeyerl */
541 1.1 hpeyerl ccdiodone(cbp)
542 1.1 hpeyerl register struct buf *cbp;
543 1.1 hpeyerl {
544 1.1 hpeyerl register struct buf *bp = (struct buf *)cbp->b_saveaddr;/* XXX */
545 1.1 hpeyerl register int unit = (cbp->b_pfcent >> 16) & 0xFFFF; /* XXX */
546 1.1 hpeyerl int count, s;
547 1.1 hpeyerl
548 1.1 hpeyerl s = splbio();
549 1.1 hpeyerl #ifdef DEBUG
550 1.1 hpeyerl if (ccddebug & CDB_FOLLOW)
551 1.1 hpeyerl printf("ccdiodone(%x)\n", cbp);
552 1.1 hpeyerl if (ccddebug & CDB_IO) {
553 1.1 hpeyerl printf("ccdiodone: bp %x bcount %d resid %d\n",
554 1.1 hpeyerl bp, bp->b_bcount, bp->b_resid);
555 1.1 hpeyerl printf(" dev %x(u%d), cbp %x bn %d addr %x bcnt %d\n",
556 1.1 hpeyerl cbp->b_dev, cbp->b_pfcent & 0xFFFF, cbp,
557 1.1 hpeyerl cbp->b_blkno, cbp->b_un.b_addr, cbp->b_bcount);
558 1.1 hpeyerl }
559 1.1 hpeyerl #endif
560 1.1 hpeyerl
561 1.1 hpeyerl if (cbp->b_flags & B_ERROR) {
562 1.1 hpeyerl bp->b_flags |= B_ERROR;
563 1.1 hpeyerl bp->b_error = biowait(cbp);
564 1.1 hpeyerl #ifdef DEBUG
565 1.1 hpeyerl printf("ccd%d: error %d on component %d\n",
566 1.1 hpeyerl unit, bp->b_error, cbp->b_pfcent & 0xFFFF);
567 1.1 hpeyerl #endif
568 1.1 hpeyerl }
569 1.1 hpeyerl count = cbp->b_bcount;
570 1.1 hpeyerl putcbuf(cbp);
571 1.1 hpeyerl
572 1.1 hpeyerl /*
573 1.1 hpeyerl * If all done, "interrupt".
574 1.1 hpeyerl * Again, sc_bp is only used to preserve the traditional interface.
575 1.1 hpeyerl */
576 1.1 hpeyerl bp->b_resid -= count;
577 1.1 hpeyerl if (bp->b_resid < 0)
578 1.1 hpeyerl panic("ccdiodone: count");
579 1.1 hpeyerl if (bp->b_resid == 0) {
580 1.1 hpeyerl ccd_softc[unit].sc_bp = bp;
581 1.1 hpeyerl ccdintr(unit);
582 1.1 hpeyerl }
583 1.1 hpeyerl splx(s);
584 1.1 hpeyerl }
585 1.1 hpeyerl
586 1.1 hpeyerl ccdioctl(dev, cmd, data, flag, p)
587 1.1 hpeyerl dev_t dev;
588 1.1 hpeyerl int cmd;
589 1.1 hpeyerl caddr_t data;
590 1.1 hpeyerl int flag;
591 1.1 hpeyerl struct proc *p;
592 1.1 hpeyerl {
593 1.1 hpeyerl return(EINVAL);
594 1.1 hpeyerl }
595 1.1 hpeyerl
596 1.1 hpeyerl ccdsize(dev)
597 1.1 hpeyerl dev_t dev;
598 1.1 hpeyerl {
599 1.1 hpeyerl int unit = ccdunit(dev);
600 1.1 hpeyerl register struct ccd_softc *cs = &ccd_softc[unit];
601 1.1 hpeyerl
602 1.1 hpeyerl if (unit >= NCCD || (cs->sc_flags & CDF_INITED) == 0)
603 1.1 hpeyerl return(-1);
604 1.1 hpeyerl return(cs->sc_size);
605 1.1 hpeyerl }
606 1.1 hpeyerl
607 1.1 hpeyerl ccddump(dev)
608 1.1 hpeyerl {
609 1.1 hpeyerl return(ENXIO);
610 1.1 hpeyerl }
611 1.1 hpeyerl #endif
612