rl.c revision 1.17 1 1.17 jdolecek /* $NetBSD: rl.c,v 1.17 2002/10/23 09:13:37 jdolecek Exp $ */
2 1.1 ragge
3 1.1 ragge /*
4 1.1 ragge * Copyright (c) 2000 Ludd, University of Lule}, Sweden. All rights reserved.
5 1.1 ragge *
6 1.1 ragge * Redistribution and use in source and binary forms, with or without
7 1.1 ragge * modification, are permitted provided that the following conditions
8 1.1 ragge * are met:
9 1.1 ragge * 1. Redistributions of source code must retain the above copyright
10 1.1 ragge * notice, this list of conditions and the following disclaimer.
11 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 ragge * notice, this list of conditions and the following disclaimer in the
13 1.1 ragge * documentation and/or other materials provided with the distribution.
14 1.1 ragge * 3. All advertising materials mentioning features or use of this software
15 1.1 ragge * must display the following acknowledgement:
16 1.1 ragge * This product includes software developed at Ludd, University of
17 1.1 ragge * Lule}, Sweden and its contributors.
18 1.1 ragge * 4. The name of the author may not be used to endorse or promote products
19 1.1 ragge * derived from this software without specific prior written permission
20 1.1 ragge *
21 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 ragge */
32 1.1 ragge
33 1.1 ragge /*
34 1.1 ragge * RL11/RLV11/RLV12 disk controller driver and
35 1.1 ragge * RL01/RL02 disk device driver.
36 1.1 ragge *
37 1.1 ragge * TODO:
38 1.1 ragge * Handle disk errors more gracefully
39 1.1 ragge * Do overlapping seeks on multiple drives
40 1.1 ragge *
41 1.1 ragge * Implementation comments:
42 1.1 ragge *
43 1.1 ragge */
44 1.10 lukem
45 1.10 lukem #include <sys/cdefs.h>
46 1.17 jdolecek __KERNEL_RCSID(0, "$NetBSD: rl.c,v 1.17 2002/10/23 09:13:37 jdolecek Exp $");
47 1.1 ragge
48 1.1 ragge #include <sys/param.h>
49 1.1 ragge #include <sys/device.h>
50 1.1 ragge #include <sys/systm.h>
51 1.1 ragge #include <sys/conf.h>
52 1.1 ragge #include <sys/disk.h>
53 1.1 ragge #include <sys/disklabel.h>
54 1.1 ragge #include <sys/buf.h>
55 1.1 ragge #include <sys/stat.h>
56 1.1 ragge #include <sys/dkio.h>
57 1.1 ragge #include <sys/fcntl.h>
58 1.17 jdolecek #include <sys/event.h>
59 1.1 ragge
60 1.1 ragge #include <ufs/ufs/dinode.h>
61 1.1 ragge #include <ufs/ffs/fs.h>
62 1.1 ragge
63 1.1 ragge #include <machine/bus.h>
64 1.1 ragge
65 1.1 ragge #include <dev/qbus/ubavar.h>
66 1.1 ragge #include <dev/qbus/rlreg.h>
67 1.11 ragge #include <dev/qbus/rlvar.h>
68 1.1 ragge
69 1.1 ragge #include "ioconf.h"
70 1.1 ragge #include "locators.h"
71 1.1 ragge
72 1.1 ragge static int rlcmatch(struct device *, struct cfdata *, void *);
73 1.1 ragge static void rlcattach(struct device *, struct device *, void *);
74 1.1 ragge static int rlcprint(void *, const char *);
75 1.1 ragge static void rlcintr(void *);
76 1.1 ragge static int rlmatch(struct device *, struct cfdata *, void *);
77 1.1 ragge static void rlattach(struct device *, struct device *, void *);
78 1.1 ragge static void rlcstart(struct rlc_softc *, struct buf *);
79 1.1 ragge static void waitcrdy(struct rlc_softc *);
80 1.11 ragge static void rlcreset(struct device *);
81 1.1 ragge
82 1.15 thorpej CFATTACH_DECL(rlc, sizeof(struct rlc_softc),
83 1.16 thorpej rlcmatch, rlcattach, NULL, NULL);
84 1.15 thorpej
85 1.15 thorpej CFATTACH_DECL(rl, sizeof(struct rl_softc),
86 1.16 thorpej rlmatch, rlattach, NULL, NULL);
87 1.1 ragge
88 1.13 gehenna dev_type_open(rlopen);
89 1.13 gehenna dev_type_close(rlclose);
90 1.13 gehenna dev_type_read(rlread);
91 1.13 gehenna dev_type_write(rlwrite);
92 1.13 gehenna dev_type_ioctl(rlioctl);
93 1.13 gehenna dev_type_strategy(rlstrategy);
94 1.13 gehenna dev_type_dump(rldump);
95 1.13 gehenna dev_type_size(rlsize);
96 1.13 gehenna
97 1.13 gehenna const struct bdevsw rl_bdevsw = {
98 1.13 gehenna rlopen, rlclose, rlstrategy, rlioctl, rldump, rlsize, D_DISK
99 1.13 gehenna };
100 1.13 gehenna
101 1.13 gehenna const struct cdevsw rl_cdevsw = {
102 1.13 gehenna rlopen, rlclose, rlread, rlwrite, rlioctl,
103 1.17 jdolecek nostop, notty, nopoll, nommap, nokqfilter, D_DISK
104 1.13 gehenna };
105 1.13 gehenna
106 1.1 ragge #define MAXRLXFER (RL_BPS * RL_SPT)
107 1.1 ragge
108 1.1 ragge #define RL_WREG(reg, val) \
109 1.1 ragge bus_space_write_2(sc->sc_iot, sc->sc_ioh, (reg), (val))
110 1.1 ragge #define RL_RREG(reg) \
111 1.1 ragge bus_space_read_2(sc->sc_iot, sc->sc_ioh, (reg))
112 1.1 ragge
113 1.11 ragge static char *rlstates[] = {
114 1.11 ragge "drive not loaded",
115 1.11 ragge "drive spinning up",
116 1.11 ragge "drive brushes out",
117 1.11 ragge "drive loading heads",
118 1.11 ragge "drive seeking",
119 1.11 ragge "drive ready",
120 1.11 ragge "drive unloading heads",
121 1.11 ragge "drive spun down",
122 1.11 ragge };
123 1.11 ragge
124 1.11 ragge static char *
125 1.11 ragge rlstate(struct rlc_softc *sc, int unit)
126 1.11 ragge {
127 1.11 ragge int i = 0;
128 1.11 ragge
129 1.11 ragge do {
130 1.11 ragge RL_WREG(RL_DA, RLDA_GS);
131 1.11 ragge RL_WREG(RL_CS, RLCS_GS|(unit << RLCS_USHFT));
132 1.11 ragge waitcrdy(sc);
133 1.11 ragge } while (((RL_RREG(RL_CS) & RLCS_ERR) != 0) && i++ < 10);
134 1.11 ragge if (i == 10)
135 1.11 ragge return NULL;
136 1.11 ragge i = RL_RREG(RL_MP) & RLMP_STATUS;
137 1.11 ragge return rlstates[i];
138 1.11 ragge }
139 1.11 ragge
140 1.1 ragge void
141 1.1 ragge waitcrdy(struct rlc_softc *sc)
142 1.1 ragge {
143 1.1 ragge int i;
144 1.1 ragge
145 1.1 ragge for (i = 0; i < 1000; i++) {
146 1.1 ragge DELAY(10000);
147 1.1 ragge if (RL_RREG(RL_CS) & RLCS_CRDY)
148 1.1 ragge return;
149 1.1 ragge }
150 1.1 ragge printf("%s: never got ready\n", sc->sc_dev.dv_xname); /* ?panic? */
151 1.1 ragge }
152 1.1 ragge
153 1.1 ragge int
154 1.1 ragge rlcprint(void *aux, const char *name)
155 1.1 ragge {
156 1.1 ragge struct rlc_attach_args *ra = aux;
157 1.1 ragge
158 1.1 ragge if (name)
159 1.1 ragge printf("RL0%d at %s", ra->type & RLMP_DT ? '2' : '1', name);
160 1.1 ragge printf(" drive %d", ra->hwid);
161 1.1 ragge return UNCONF;
162 1.1 ragge }
163 1.1 ragge
164 1.1 ragge /*
165 1.1 ragge * Force the controller to interrupt.
166 1.1 ragge */
167 1.1 ragge int
168 1.1 ragge rlcmatch(struct device *parent, struct cfdata *cf, void *aux)
169 1.1 ragge {
170 1.1 ragge struct uba_attach_args *ua = aux;
171 1.1 ragge struct rlc_softc ssc, *sc = &ssc;
172 1.1 ragge int i;
173 1.1 ragge
174 1.1 ragge sc->sc_iot = ua->ua_iot;
175 1.1 ragge sc->sc_ioh = ua->ua_ioh;
176 1.1 ragge /* Force interrupt by issuing a "Get Status" command */
177 1.1 ragge RL_WREG(RL_DA, RLDA_GS);
178 1.1 ragge RL_WREG(RL_CS, RLCS_GS|RLCS_IE);
179 1.1 ragge
180 1.1 ragge for (i = 0; i < 100; i++) {
181 1.1 ragge DELAY(100000);
182 1.1 ragge if (RL_RREG(RL_CS) & RLCS_CRDY)
183 1.1 ragge return 1;
184 1.1 ragge }
185 1.1 ragge return 0;
186 1.1 ragge }
187 1.1 ragge
188 1.1 ragge void
189 1.1 ragge rlcattach(struct device *parent, struct device *self, void *aux)
190 1.1 ragge {
191 1.1 ragge struct rlc_softc *sc = (struct rlc_softc *)self;
192 1.1 ragge struct uba_attach_args *ua = aux;
193 1.1 ragge struct rlc_attach_args ra;
194 1.1 ragge int i, error;
195 1.1 ragge
196 1.1 ragge sc->sc_iot = ua->ua_iot;
197 1.1 ragge sc->sc_ioh = ua->ua_ioh;
198 1.1 ragge sc->sc_dmat = ua->ua_dmat;
199 1.4 matt uba_intr_establish(ua->ua_icookie, ua->ua_cvec,
200 1.4 matt rlcintr, sc, &sc->sc_intrcnt);
201 1.5 matt evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
202 1.5 matt sc->sc_dev.dv_xname, "intr");
203 1.11 ragge uba_reset_establish(rlcreset, self);
204 1.11 ragge
205 1.1 ragge printf("\n");
206 1.1 ragge
207 1.1 ragge /*
208 1.1 ragge * The RL11 can only have one transfer going at a time,
209 1.1 ragge * and max transfer size is one track, so only one dmamap
210 1.1 ragge * is needed.
211 1.1 ragge */
212 1.1 ragge error = bus_dmamap_create(sc->sc_dmat, MAXRLXFER, 1, MAXRLXFER, 0,
213 1.1 ragge BUS_DMA_ALLOCNOW, &sc->sc_dmam);
214 1.1 ragge if (error) {
215 1.1 ragge printf(": Failed to allocate DMA map, error %d\n", error);
216 1.1 ragge return;
217 1.1 ragge }
218 1.12 hannken bufq_alloc(&sc->sc_q, BUFQ_DISKSORT|BUFQ_SORT_CYLINDER);
219 1.1 ragge for (i = 0; i < RL_MAXDPC; i++) {
220 1.1 ragge waitcrdy(sc);
221 1.1 ragge RL_WREG(RL_DA, RLDA_GS|RLDA_RST);
222 1.1 ragge RL_WREG(RL_CS, RLCS_GS|(i << RLCS_USHFT));
223 1.1 ragge waitcrdy(sc);
224 1.1 ragge ra.type = RL_RREG(RL_MP);
225 1.1 ragge ra.hwid = i;
226 1.1 ragge if ((RL_RREG(RL_CS) & RLCS_ERR) == 0)
227 1.1 ragge config_found(&sc->sc_dev, &ra, rlcprint);
228 1.1 ragge }
229 1.1 ragge }
230 1.1 ragge
231 1.1 ragge int
232 1.1 ragge rlmatch(struct device *parent, struct cfdata *cf, void *aux)
233 1.1 ragge {
234 1.1 ragge struct rlc_attach_args *ra = aux;
235 1.1 ragge
236 1.1 ragge if (cf->cf_loc[RLCCF_DRIVE] != RLCCF_DRIVE_DEFAULT &&
237 1.1 ragge cf->cf_loc[RLCCF_DRIVE] != ra->hwid)
238 1.1 ragge return 0;
239 1.1 ragge return 1;
240 1.1 ragge }
241 1.1 ragge
242 1.1 ragge void
243 1.1 ragge rlattach(struct device *parent, struct device *self, void *aux)
244 1.1 ragge {
245 1.1 ragge struct rl_softc *rc = (struct rl_softc *)self;
246 1.1 ragge struct rlc_attach_args *ra = aux;
247 1.1 ragge struct disklabel *dl;
248 1.1 ragge
249 1.1 ragge rc->rc_hwid = ra->hwid;
250 1.1 ragge rc->rc_disk.dk_name = rc->rc_dev.dv_xname;
251 1.1 ragge disk_attach(&rc->rc_disk);
252 1.1 ragge dl = rc->rc_disk.dk_label;
253 1.1 ragge dl->d_npartitions = 3;
254 1.1 ragge strcpy(dl->d_typename, "RL01");
255 1.1 ragge if (ra->type & RLMP_DT)
256 1.1 ragge dl->d_typename[3] = '2';
257 1.1 ragge dl->d_secsize = DEV_BSIZE; /* XXX - wrong, but OK for now */
258 1.1 ragge dl->d_nsectors = RL_SPT/2;
259 1.1 ragge dl->d_ntracks = RL_SPD;
260 1.1 ragge dl->d_ncylinders = ra->type & RLMP_DT ? RL_TPS02 : RL_TPS01;
261 1.1 ragge dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
262 1.1 ragge dl->d_secperunit = dl->d_ncylinders * dl->d_secpercyl;
263 1.1 ragge dl->d_partitions[0].p_size = dl->d_partitions[2].p_size =
264 1.1 ragge dl->d_secperunit;
265 1.1 ragge dl->d_partitions[0].p_offset = dl->d_partitions[2].p_offset = 0;
266 1.1 ragge dl->d_interleave = dl->d_headswitch = 1;
267 1.1 ragge dl->d_bbsize = BBSIZE;
268 1.1 ragge dl->d_sbsize = SBSIZE;
269 1.1 ragge dl->d_rpm = 2400;
270 1.1 ragge dl->d_type = DTYPE_DEC;
271 1.11 ragge printf(": %s, %s\n", dl->d_typename,
272 1.11 ragge rlstate((struct rlc_softc *)parent, ra->hwid));
273 1.1 ragge }
274 1.1 ragge
275 1.1 ragge int
276 1.1 ragge rlopen(dev_t dev, int flag, int fmt, struct proc *p)
277 1.1 ragge {
278 1.1 ragge int part, unit, mask;
279 1.1 ragge struct disklabel *dl;
280 1.1 ragge struct rlc_softc *sc;
281 1.1 ragge struct rl_softc *rc;
282 1.1 ragge char *msg;
283 1.11 ragge
284 1.1 ragge /*
285 1.1 ragge * Make sure this is a reasonable open request.
286 1.1 ragge */
287 1.1 ragge unit = DISKUNIT(dev);
288 1.1 ragge if (unit >= rl_cd.cd_ndevs)
289 1.1 ragge return ENXIO;
290 1.1 ragge rc = rl_cd.cd_devs[unit];
291 1.1 ragge if (rc == 0)
292 1.1 ragge return ENXIO;
293 1.1 ragge
294 1.1 ragge sc = (struct rlc_softc *)rc->rc_dev.dv_parent;
295 1.11 ragge /* Check that the disk actually is useable */
296 1.11 ragge msg = rlstate(sc, rc->rc_hwid);
297 1.11 ragge if (msg == NULL || msg == rlstates[RLMP_UNLOAD] ||
298 1.11 ragge msg == rlstates[RLMP_SPUNDOWN])
299 1.11 ragge return ENXIO;
300 1.1 ragge /*
301 1.1 ragge * If this is the first open; read in where on the disk we are.
302 1.1 ragge */
303 1.1 ragge dl = rc->rc_disk.dk_label;
304 1.1 ragge if (rc->rc_state == DK_CLOSED) {
305 1.1 ragge u_int16_t mp;
306 1.13 gehenna int maj;
307 1.1 ragge RL_WREG(RL_CS, RLCS_RHDR|(rc->rc_hwid << RLCS_USHFT));
308 1.1 ragge waitcrdy(sc);
309 1.1 ragge mp = RL_RREG(RL_MP);
310 1.1 ragge rc->rc_head = ((mp & RLMP_HS) == RLMP_HS);
311 1.1 ragge rc->rc_cyl = (mp >> 7) & 0777;
312 1.1 ragge rc->rc_state = DK_OPEN;
313 1.1 ragge /* Get disk label */
314 1.1 ragge printf("%s: ", rc->rc_dev.dv_xname);
315 1.13 gehenna maj = cdevsw_lookup_major(&rl_cdevsw);
316 1.13 gehenna if ((msg = readdisklabel(MAKEDISKDEV(maj,
317 1.1 ragge rc->rc_dev.dv_unit, RAW_PART), rlstrategy, dl, NULL)))
318 1.1 ragge printf("%s: ", msg);
319 1.1 ragge printf("size %d sectors\n", dl->d_secperunit);
320 1.1 ragge }
321 1.1 ragge part = DISKPART(dev);
322 1.1 ragge if (part >= dl->d_npartitions)
323 1.1 ragge return ENXIO;
324 1.1 ragge
325 1.1 ragge mask = 1 << part;
326 1.1 ragge switch (fmt) {
327 1.1 ragge case S_IFCHR:
328 1.1 ragge rc->rc_disk.dk_copenmask |= mask;
329 1.1 ragge break;
330 1.1 ragge case S_IFBLK:
331 1.1 ragge rc->rc_disk.dk_bopenmask |= mask;
332 1.1 ragge break;
333 1.1 ragge }
334 1.1 ragge rc->rc_disk.dk_openmask |= mask;
335 1.1 ragge return 0;
336 1.1 ragge }
337 1.1 ragge
338 1.1 ragge int
339 1.1 ragge rlclose(dev_t dev, int flag, int fmt, struct proc *p)
340 1.1 ragge {
341 1.1 ragge int unit = DISKUNIT(dev);
342 1.1 ragge struct rl_softc *rc = rl_cd.cd_devs[unit];
343 1.1 ragge int mask = (1 << DISKPART(dev));
344 1.1 ragge
345 1.1 ragge switch (fmt) {
346 1.1 ragge case S_IFCHR:
347 1.1 ragge rc->rc_disk.dk_copenmask &= ~mask;
348 1.1 ragge break;
349 1.1 ragge case S_IFBLK:
350 1.1 ragge rc->rc_disk.dk_bopenmask &= ~mask;
351 1.1 ragge break;
352 1.1 ragge }
353 1.1 ragge rc->rc_disk.dk_openmask =
354 1.1 ragge rc->rc_disk.dk_copenmask | rc->rc_disk.dk_bopenmask;
355 1.1 ragge
356 1.1 ragge if (rc->rc_disk.dk_openmask == 0)
357 1.1 ragge rc->rc_state = DK_CLOSED; /* May change pack */
358 1.1 ragge return 0;
359 1.1 ragge }
360 1.1 ragge
361 1.1 ragge void
362 1.1 ragge rlstrategy(struct buf *bp)
363 1.1 ragge {
364 1.1 ragge struct disklabel *lp;
365 1.1 ragge struct rlc_softc *sc;
366 1.1 ragge struct rl_softc *rc;
367 1.1 ragge int unit, s, err;
368 1.1 ragge /*
369 1.1 ragge * Make sure this is a reasonable drive to use.
370 1.1 ragge */
371 1.1 ragge unit = DISKUNIT(bp->b_dev);
372 1.1 ragge if (unit > rl_cd.cd_ndevs || (rc = rl_cd.cd_devs[unit]) == NULL) {
373 1.1 ragge bp->b_error = ENXIO;
374 1.1 ragge bp->b_flags |= B_ERROR;
375 1.1 ragge goto done;
376 1.1 ragge }
377 1.1 ragge if (rc->rc_state != DK_OPEN) /* How did we end up here at all? */
378 1.1 ragge panic("rlstrategy: state impossible");
379 1.1 ragge
380 1.1 ragge lp = rc->rc_disk.dk_label;
381 1.1 ragge if ((err = bounds_check_with_label(bp, lp, 1)) <= 0)
382 1.1 ragge goto done;
383 1.1 ragge
384 1.1 ragge if (bp->b_bcount == 0)
385 1.1 ragge goto done;
386 1.1 ragge
387 1.1 ragge bp->b_rawblkno =
388 1.1 ragge bp->b_blkno + lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
389 1.1 ragge bp->b_cylinder = bp->b_rawblkno / lp->d_secpercyl;
390 1.1 ragge sc = (struct rlc_softc *)rc->rc_dev.dv_parent;
391 1.1 ragge
392 1.8 thorpej s = splbio();
393 1.12 hannken BUFQ_PUT(&sc->sc_q, bp);
394 1.1 ragge rlcstart(sc, 0);
395 1.1 ragge splx(s);
396 1.1 ragge return;
397 1.1 ragge
398 1.1 ragge done: biodone(bp);
399 1.1 ragge }
400 1.1 ragge
401 1.1 ragge int
402 1.1 ragge rlioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
403 1.1 ragge {
404 1.1 ragge struct rl_softc *rc = rl_cd.cd_devs[DISKUNIT(dev)];
405 1.1 ragge struct disklabel *lp = rc->rc_disk.dk_label;
406 1.1 ragge int err = 0;
407 1.6 fvdl #ifdef __HAVE_OLD_DISKLABEL
408 1.6 fvdl struct disklabel newlabel;
409 1.6 fvdl #endif
410 1.1 ragge
411 1.1 ragge switch (cmd) {
412 1.1 ragge case DIOCGDINFO:
413 1.1 ragge bcopy(lp, addr, sizeof (struct disklabel));
414 1.1 ragge break;
415 1.1 ragge
416 1.6 fvdl #ifdef __HAVE_OLD_DISKLABEL
417 1.6 fvdl case ODIOCGDINFO:
418 1.6 fvdl newlabel = *lp;
419 1.6 fvdl if (newlabel.d_npartitions > OLDMAXPARTITIONS)
420 1.7 fvdl return ENOTTY;
421 1.6 fvdl bcopy(&newlabel, addr, sizeof (struct olddisklabel));
422 1.6 fvdl break;
423 1.6 fvdl #endif
424 1.6 fvdl
425 1.1 ragge case DIOCGPART:
426 1.1 ragge ((struct partinfo *)addr)->disklab = lp;
427 1.1 ragge ((struct partinfo *)addr)->part =
428 1.1 ragge &lp->d_partitions[DISKPART(dev)];
429 1.1 ragge break;
430 1.1 ragge
431 1.1 ragge case DIOCSDINFO:
432 1.1 ragge case DIOCWDINFO:
433 1.6 fvdl #ifdef __HAVE_OLD_DISKLABEL
434 1.6 fvdl case ODIOCWDINFO:
435 1.6 fvdl case ODIOCSDINFO:
436 1.6 fvdl #endif
437 1.6 fvdl {
438 1.6 fvdl struct disklabel *tp;
439 1.6 fvdl
440 1.6 fvdl #ifdef __HAVE_OLD_DISKLABEL
441 1.6 fvdl if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
442 1.6 fvdl memset(&newlabel, 0, sizeof newlabel);
443 1.6 fvdl memcpy(&newlabel, addr, sizeof (struct olddisklabel));
444 1.6 fvdl tp = &newlabel;
445 1.6 fvdl } else
446 1.6 fvdl #endif
447 1.6 fvdl tp = (struct disklabel *)addr;
448 1.6 fvdl
449 1.1 ragge if ((flag & FWRITE) == 0)
450 1.1 ragge err = EBADF;
451 1.1 ragge else
452 1.6 fvdl err = ((
453 1.6 fvdl #ifdef __HAVE_OLD_DISKLABEL
454 1.6 fvdl cmd == ODIOCSDINFO ||
455 1.6 fvdl #endif
456 1.6 fvdl cmd == DIOCSDINFO) ?
457 1.6 fvdl setdisklabel(lp, tp, 0, 0) :
458 1.1 ragge writedisklabel(dev, rlstrategy, lp, 0));
459 1.1 ragge break;
460 1.6 fvdl }
461 1.1 ragge
462 1.1 ragge case DIOCWLABEL:
463 1.1 ragge if ((flag & FWRITE) == 0)
464 1.1 ragge err = EBADF;
465 1.1 ragge break;
466 1.1 ragge
467 1.1 ragge default:
468 1.1 ragge err = ENOTTY;
469 1.1 ragge }
470 1.1 ragge return err;
471 1.1 ragge }
472 1.1 ragge
473 1.1 ragge int
474 1.1 ragge rlsize(dev_t dev)
475 1.1 ragge {
476 1.1 ragge struct disklabel *dl;
477 1.1 ragge struct rl_softc *rc;
478 1.1 ragge int size, unit = DISKUNIT(dev);
479 1.1 ragge
480 1.1 ragge if ((unit >= rl_cd.cd_ndevs) || ((rc = rl_cd.cd_devs[unit]) == 0))
481 1.1 ragge return -1;
482 1.1 ragge dl = rc->rc_disk.dk_label;
483 1.1 ragge size = dl->d_partitions[DISKPART(dev)].p_size *
484 1.1 ragge (dl->d_secsize / DEV_BSIZE);
485 1.1 ragge return size;
486 1.1 ragge }
487 1.1 ragge
488 1.1 ragge int
489 1.1 ragge rldump(dev_t dev, daddr_t blkno, caddr_t va, size_t size)
490 1.1 ragge {
491 1.1 ragge /* Not likely... */
492 1.1 ragge return 0;
493 1.1 ragge }
494 1.1 ragge
495 1.1 ragge int
496 1.1 ragge rlread(dev_t dev, struct uio *uio, int ioflag)
497 1.1 ragge {
498 1.1 ragge return (physio(rlstrategy, NULL, dev, B_READ, minphys, uio));
499 1.1 ragge }
500 1.1 ragge
501 1.1 ragge int
502 1.1 ragge rlwrite(dev_t dev, struct uio *uio, int ioflag)
503 1.1 ragge {
504 1.1 ragge return (physio(rlstrategy, NULL, dev, B_WRITE, minphys, uio));
505 1.1 ragge }
506 1.1 ragge
507 1.1 ragge static char *rlerr[] = {
508 1.1 ragge "no",
509 1.1 ragge "operation incomplete",
510 1.1 ragge "read data CRC",
511 1.1 ragge "header CRC",
512 1.1 ragge "data late",
513 1.1 ragge "header not found",
514 1.1 ragge "",
515 1.1 ragge "",
516 1.9 wiz "non-existent memory",
517 1.1 ragge "memory parity error",
518 1.1 ragge "",
519 1.1 ragge "",
520 1.1 ragge "",
521 1.1 ragge "",
522 1.1 ragge "",
523 1.1 ragge "",
524 1.1 ragge };
525 1.1 ragge
526 1.1 ragge void
527 1.1 ragge rlcintr(void *arg)
528 1.1 ragge {
529 1.1 ragge struct rlc_softc *sc = arg;
530 1.1 ragge struct buf *bp;
531 1.1 ragge u_int16_t cs;
532 1.1 ragge
533 1.1 ragge bp = sc->sc_active;
534 1.1 ragge if (bp == 0) {
535 1.1 ragge printf("%s: strange interrupt\n", sc->sc_dev.dv_xname);
536 1.1 ragge return;
537 1.1 ragge }
538 1.1 ragge bus_dmamap_unload(sc->sc_dmat, sc->sc_dmam);
539 1.1 ragge sc->sc_active = 0;
540 1.1 ragge cs = RL_RREG(RL_CS);
541 1.1 ragge if (cs & RLCS_ERR) {
542 1.1 ragge int error = (cs & RLCS_ERRMSK) >> 10;
543 1.1 ragge
544 1.1 ragge printf("%s: %s\n", sc->sc_dev.dv_xname, rlerr[error]);
545 1.1 ragge bp->b_flags |= B_ERROR;
546 1.1 ragge bp->b_error = EIO;
547 1.1 ragge bp->b_resid = bp->b_bcount;
548 1.1 ragge sc->sc_bytecnt = 0;
549 1.1 ragge }
550 1.1 ragge if (sc->sc_bytecnt == 0) /* Finished transfer */
551 1.1 ragge biodone(bp);
552 1.1 ragge rlcstart(sc, sc->sc_bytecnt ? bp : 0);
553 1.1 ragge }
554 1.1 ragge
555 1.1 ragge /*
556 1.1 ragge * Start routine. First position the disk to the given position,
557 1.1 ragge * then start reading/writing. An optimization would be to be able
558 1.1 ragge * to handle overlapping seeks between disks.
559 1.1 ragge */
560 1.1 ragge void
561 1.1 ragge rlcstart(struct rlc_softc *sc, struct buf *ob)
562 1.1 ragge {
563 1.1 ragge struct disklabel *lp;
564 1.1 ragge struct rl_softc *rc;
565 1.1 ragge struct buf *bp;
566 1.1 ragge int bn, cn, sn, tn, blks, err;
567 1.1 ragge
568 1.1 ragge if (sc->sc_active)
569 1.1 ragge return; /* Already doing something */
570 1.1 ragge
571 1.1 ragge if (ob == 0) {
572 1.12 hannken bp = BUFQ_GET(&sc->sc_q);
573 1.1 ragge if (bp == NULL)
574 1.1 ragge return; /* Nothing to do */
575 1.3 thorpej sc->sc_bufaddr = bp->b_data;
576 1.1 ragge sc->sc_diskblk = bp->b_rawblkno;
577 1.1 ragge sc->sc_bytecnt = bp->b_bcount;
578 1.1 ragge bp->b_resid = 0;
579 1.1 ragge } else
580 1.1 ragge bp = ob;
581 1.1 ragge sc->sc_active = bp;
582 1.1 ragge
583 1.1 ragge rc = rl_cd.cd_devs[DISKUNIT(bp->b_dev)];
584 1.1 ragge bn = sc->sc_diskblk;
585 1.1 ragge lp = rc->rc_disk.dk_label;
586 1.1 ragge if (bn) {
587 1.1 ragge cn = bn / lp->d_secpercyl;
588 1.1 ragge sn = bn % lp->d_secpercyl;
589 1.1 ragge tn = sn / lp->d_nsectors;
590 1.1 ragge sn = sn % lp->d_nsectors;
591 1.1 ragge } else
592 1.1 ragge cn = sn = tn = 0;
593 1.1 ragge
594 1.1 ragge /*
595 1.1 ragge * Check if we have to position disk first.
596 1.1 ragge */
597 1.1 ragge if (rc->rc_cyl != cn || rc->rc_head != tn) {
598 1.1 ragge u_int16_t da = RLDA_SEEK;
599 1.1 ragge if (cn > rc->rc_cyl)
600 1.1 ragge da |= ((cn - rc->rc_cyl) << RLDA_CYLSHFT) | RLDA_DIR;
601 1.1 ragge else
602 1.1 ragge da |= ((rc->rc_cyl - cn) << RLDA_CYLSHFT);
603 1.1 ragge if (tn)
604 1.1 ragge da |= RLDA_HSSEEK;
605 1.1 ragge waitcrdy(sc);
606 1.1 ragge RL_WREG(RL_DA, da);
607 1.1 ragge RL_WREG(RL_CS, RLCS_SEEK | (rc->rc_hwid << RLCS_USHFT));
608 1.1 ragge waitcrdy(sc);
609 1.1 ragge rc->rc_cyl = cn;
610 1.1 ragge rc->rc_head = tn;
611 1.1 ragge }
612 1.1 ragge RL_WREG(RL_DA, (cn << RLDA_CYLSHFT) | (tn ? RLDA_HSRW : 0) | (sn << 1));
613 1.1 ragge blks = sc->sc_bytecnt/DEV_BSIZE;
614 1.1 ragge
615 1.1 ragge if (sn + blks > RL_SPT/2)
616 1.1 ragge blks = RL_SPT/2 - sn;
617 1.1 ragge RL_WREG(RL_MP, -(blks*DEV_BSIZE)/2);
618 1.1 ragge err = bus_dmamap_load(sc->sc_dmat, sc->sc_dmam, sc->sc_bufaddr,
619 1.11 ragge (blks*DEV_BSIZE), (bp->b_flags & B_PHYS ? bp->b_proc : 0),
620 1.11 ragge BUS_DMA_NOWAIT);
621 1.1 ragge if (err)
622 1.1 ragge panic("%s: bus_dmamap_load failed: %d",
623 1.1 ragge sc->sc_dev.dv_xname, err);
624 1.1 ragge RL_WREG(RL_BA, (sc->sc_dmam->dm_segs[0].ds_addr & 0xffff));
625 1.1 ragge
626 1.1 ragge /* Count up vars */
627 1.1 ragge sc->sc_bufaddr += (blks*DEV_BSIZE);
628 1.1 ragge sc->sc_diskblk += blks;
629 1.1 ragge sc->sc_bytecnt -= (blks*DEV_BSIZE);
630 1.1 ragge
631 1.1 ragge if (bp->b_flags & B_READ)
632 1.1 ragge RL_WREG(RL_CS, RLCS_IE|RLCS_RD|(rc->rc_hwid << RLCS_USHFT));
633 1.1 ragge else
634 1.1 ragge RL_WREG(RL_CS, RLCS_IE|RLCS_WD|(rc->rc_hwid << RLCS_USHFT));
635 1.2 ragge }
636 1.2 ragge
637 1.11 ragge /*
638 1.11 ragge * Called once per controller when an ubareset occurs.
639 1.11 ragge * Retracts all disks and restarts active transfers.
640 1.11 ragge */
641 1.2 ragge void
642 1.11 ragge rlcreset(struct device *dev)
643 1.2 ragge {
644 1.11 ragge struct rlc_softc *sc = (struct rlc_softc *)dev;
645 1.11 ragge struct rl_softc *rc;
646 1.11 ragge int i;
647 1.2 ragge u_int16_t mp;
648 1.2 ragge
649 1.11 ragge for (i = 0; i < rl_cd.cd_ndevs; i++) {
650 1.11 ragge if ((rc = rl_cd.cd_devs[i]) == NULL)
651 1.11 ragge continue;
652 1.11 ragge if (rc->rc_state != DK_OPEN)
653 1.11 ragge continue;
654 1.11 ragge
655 1.11 ragge printf(" %s", rc->rc_dev.dv_xname);
656 1.11 ragge RL_WREG(RL_CS, RLCS_RHDR|(rc->rc_hwid << RLCS_USHFT));
657 1.11 ragge waitcrdy(sc);
658 1.11 ragge mp = RL_RREG(RL_MP);
659 1.11 ragge rc->rc_head = ((mp & RLMP_HS) == RLMP_HS);
660 1.11 ragge rc->rc_cyl = (mp >> 7) & 0777;
661 1.11 ragge }
662 1.2 ragge if (sc->sc_active == 0)
663 1.2 ragge return;
664 1.2 ragge
665 1.12 hannken BUFQ_PUT(&sc->sc_q, sc->sc_active);
666 1.2 ragge sc->sc_active = 0;
667 1.2 ragge rlcstart(sc, 0);
668 1.1 ragge }
669