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