xy.c revision 1.99 1 1.99 mlelstv /* $NetBSD: xy.c,v 1.99 2015/04/26 15:15:20 mlelstv Exp $ */
2 1.1 pk
3 1.1 pk /*
4 1.1 pk * Copyright (c) 1995 Charles D. Cranor
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * Redistribution and use in source and binary forms, with or without
8 1.1 pk * modification, are permitted provided that the following conditions
9 1.1 pk * are met:
10 1.1 pk * 1. Redistributions of source code must retain the above copyright
11 1.1 pk * notice, this list of conditions and the following disclaimer.
12 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 pk * notice, this list of conditions and the following disclaimer in the
14 1.1 pk * documentation and/or other materials provided with the distribution.
15 1.1 pk *
16 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 pk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 pk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 pk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 pk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 pk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 pk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 pk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 pk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 pk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 pk */
27 1.1 pk
28 1.1 pk /*
29 1.1 pk *
30 1.1 pk * x y . c x y l o g i c s 4 5 0 / 4 5 1 s m d d r i v e r
31 1.1 pk *
32 1.91 chuck * author: Chuck Cranor <chuck@netbsd>
33 1.1 pk * started: 14-Sep-95
34 1.1 pk * references: [1] Xylogics Model 753 User's Manual
35 1.1 pk * part number: 166-753-001, Revision B, May 21, 1988.
36 1.1 pk * "Your Partner For Performance"
37 1.1 pk * [2] other NetBSD disk device drivers
38 1.1 pk * [3] Xylogics Model 450 User's Manual
39 1.1 pk * part number: 166-017-001, Revision B, 1983.
40 1.1 pk * [4] Addendum to Xylogics Model 450 Disk Controller User's
41 1.1 pk * Manual, Jan. 1985.
42 1.1 pk * [5] The 451 Controller, Rev. B3, September 2, 1986.
43 1.1 pk * [6] David Jones <dej (at) achilles.net>'s unfinished 450/451 driver
44 1.1 pk *
45 1.1 pk */
46 1.38 lukem
47 1.38 lukem #include <sys/cdefs.h>
48 1.99 mlelstv __KERNEL_RCSID(0, "$NetBSD: xy.c,v 1.99 2015/04/26 15:15:20 mlelstv Exp $");
49 1.1 pk
50 1.1 pk #undef XYC_DEBUG /* full debug */
51 1.1 pk #undef XYC_DIAG /* extra sanity checks */
52 1.1 pk #if defined(DIAGNOSTIC) && !defined(XYC_DIAG)
53 1.1 pk #define XYC_DIAG /* link in with master DIAG option */
54 1.1 pk #endif
55 1.1 pk
56 1.1 pk #include <sys/param.h>
57 1.1 pk #include <sys/proc.h>
58 1.1 pk #include <sys/systm.h>
59 1.1 pk #include <sys/kernel.h>
60 1.1 pk #include <sys/file.h>
61 1.1 pk #include <sys/stat.h>
62 1.1 pk #include <sys/ioctl.h>
63 1.1 pk #include <sys/buf.h>
64 1.56 yamt #include <sys/bufq.h>
65 1.1 pk #include <sys/uio.h>
66 1.1 pk #include <sys/malloc.h>
67 1.1 pk #include <sys/device.h>
68 1.1 pk #include <sys/disklabel.h>
69 1.1 pk #include <sys/disk.h>
70 1.1 pk #include <sys/syslog.h>
71 1.1 pk #include <sys/dkbad.h>
72 1.1 pk #include <sys/conf.h>
73 1.65 yamt #include <sys/kauth.h>
74 1.1 pk
75 1.74 ad #include <sys/bus.h>
76 1.74 ad #include <sys/intr.h>
77 1.9 mrg
78 1.25 chs #if defined(__sparc__) || defined(sun3)
79 1.9 mrg #include <dev/sun/disklabel.h>
80 1.11 pk #endif
81 1.1 pk
82 1.28 pk #include <dev/vme/vmereg.h>
83 1.1 pk #include <dev/vme/vmevar.h>
84 1.12 drochner
85 1.1 pk #include <dev/vme/xyreg.h>
86 1.1 pk #include <dev/vme/xyvar.h>
87 1.1 pk #include <dev/vme/xio.h>
88 1.1 pk
89 1.1 pk #include "locators.h"
90 1.1 pk
91 1.1 pk /*
92 1.1 pk * macros
93 1.1 pk */
94 1.1 pk
95 1.1 pk /*
96 1.1 pk * XYC_GO: start iopb ADDR (DVMA addr in a u_long) on XYC
97 1.1 pk */
98 1.1 pk #define XYC_GO(XYC, ADDR) { \
99 1.63 skrll u_long addr = (u_long)ADDR; \
100 1.63 skrll (XYC)->xyc_addr_lo = ((addr) & 0xff); \
101 1.63 skrll (addr) = ((addr) >> 8); \
102 1.63 skrll (XYC)->xyc_addr_hi = ((addr) & 0xff); \
103 1.63 skrll (addr) = ((addr) >> 8); \
104 1.63 skrll (XYC)->xyc_reloc_lo = ((addr) & 0xff); \
105 1.63 skrll (addr) = ((addr) >> 8); \
106 1.63 skrll (XYC)->xyc_reloc_hi = (addr); \
107 1.1 pk (XYC)->xyc_csr = XYC_GBSY; /* go! */ \
108 1.1 pk }
109 1.1 pk
110 1.1 pk /*
111 1.1 pk * XYC_DONE: don't need IORQ, get error code and free (done after xyc_cmd)
112 1.1 pk */
113 1.1 pk
114 1.1 pk #define XYC_DONE(SC,ER) { \
115 1.1 pk if ((ER) == XY_ERR_AOK) { \
116 1.67 christos (ER) = (SC)->ciorq->errnum; \
117 1.1 pk (SC)->ciorq->mode = XY_SUB_FREE; \
118 1.1 pk wakeup((SC)->ciorq); \
119 1.1 pk } \
120 1.1 pk }
121 1.1 pk
122 1.1 pk /*
123 1.1 pk * XYC_ADVANCE: advance iorq's pointers by a number of sectors
124 1.1 pk */
125 1.1 pk
126 1.1 pk #define XYC_ADVANCE(IORQ, N) { \
127 1.1 pk if (N) { \
128 1.1 pk (IORQ)->sectcnt -= (N); \
129 1.1 pk (IORQ)->blockno += (N); \
130 1.1 pk (IORQ)->dbuf += ((N)*XYFM_BPS); \
131 1.1 pk } \
132 1.1 pk }
133 1.1 pk
134 1.1 pk /*
135 1.1 pk * note - addresses you can sleep on:
136 1.1 pk * [1] & of xy_softc's "state" (waiting for a chance to attach a drive)
137 1.1 pk * [2] & an iorq (waiting for an XY_SUB_WAIT iorq to finish)
138 1.1 pk */
139 1.1 pk
140 1.1 pk
141 1.1 pk /*
142 1.1 pk * function prototypes
143 1.1 pk * "xyc_*" functions are internal, all others are external interfaces
144 1.1 pk */
145 1.1 pk
146 1.1 pk extern int pil_to_vme[]; /* from obio.c */
147 1.1 pk
148 1.1 pk /* internals */
149 1.57 perry struct xy_iopb *xyc_chain(struct xyc_softc *, struct xy_iorq *);
150 1.57 perry int xyc_cmd(struct xyc_softc *, int, int, int, int, int, char *, int);
151 1.59 tsutsui const char *xyc_e2str(int);
152 1.57 perry int xyc_entoact(int);
153 1.57 perry int xyc_error(struct xyc_softc *, struct xy_iorq *,
154 1.57 perry struct xy_iopb *, int);
155 1.57 perry int xyc_ioctlcmd(struct xy_softc *, dev_t dev, struct xd_iocmd *);
156 1.57 perry void xyc_perror(struct xy_iorq *, struct xy_iopb *, int);
157 1.57 perry int xyc_piodriver(struct xyc_softc *, struct xy_iorq *);
158 1.57 perry int xyc_remove_iorq(struct xyc_softc *);
159 1.57 perry int xyc_reset(struct xyc_softc *, int, struct xy_iorq *, int,
160 1.57 perry struct xy_softc *);
161 1.57 perry inline void xyc_rqinit(struct xy_iorq *, struct xyc_softc *,
162 1.57 perry struct xy_softc *, int, u_long, int,
163 1.69 christos void *, struct buf *);
164 1.57 perry void xyc_rqtopb(struct xy_iorq *, struct xy_iopb *, int, int);
165 1.57 perry void xyc_start(struct xyc_softc *, struct xy_iorq *);
166 1.57 perry int xyc_startbuf(struct xyc_softc *, struct xy_softc *, struct buf *);
167 1.57 perry int xyc_submit_iorq(struct xyc_softc *, struct xy_iorq *, int);
168 1.57 perry void xyc_tick(void *);
169 1.57 perry int xyc_unbusy(struct xyc *, int);
170 1.57 perry void xyc_xyreset(struct xyc_softc *, struct xy_softc *);
171 1.19 pk int xy_dmamem_alloc(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
172 1.69 christos int *, bus_size_t, void **, bus_addr_t *);
173 1.19 pk void xy_dmamem_free(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
174 1.69 christos int, bus_size_t, void *);
175 1.1 pk
176 1.1 pk /* machine interrupt hook */
177 1.57 perry int xycintr(void *);
178 1.1 pk
179 1.1 pk /* autoconf */
180 1.90 cegger int xycmatch(device_t, cfdata_t, void *);
181 1.90 cegger void xycattach(device_t, device_t, void *);
182 1.90 cegger int xymatch(device_t, cfdata_t, void *);
183 1.90 cegger void xyattach(device_t, device_t, void *);
184 1.57 perry static int xyc_probe(void *, bus_space_tag_t, bus_space_handle_t);
185 1.1 pk
186 1.57 perry static void xydummystrat(struct buf *);
187 1.57 perry int xygetdisklabel(struct xy_softc *, void *);
188 1.1 pk
189 1.1 pk /*
190 1.3 thorpej * cfattach's: device driver interface to autoconfig
191 1.1 pk */
192 1.1 pk
193 1.93 chs CFATTACH_DECL_NEW(xyc, sizeof(struct xyc_softc),
194 1.45 thorpej xycmatch, xycattach, NULL, NULL);
195 1.44 thorpej
196 1.93 chs CFATTACH_DECL_NEW(xy, sizeof(struct xy_softc),
197 1.45 thorpej xymatch, xyattach, NULL, NULL);
198 1.1 pk
199 1.3 thorpej extern struct cfdriver xy_cd;
200 1.41 gehenna
201 1.41 gehenna dev_type_open(xyopen);
202 1.41 gehenna dev_type_close(xyclose);
203 1.41 gehenna dev_type_read(xyread);
204 1.41 gehenna dev_type_write(xywrite);
205 1.41 gehenna dev_type_ioctl(xyioctl);
206 1.41 gehenna dev_type_strategy(xystrategy);
207 1.41 gehenna dev_type_dump(xydump);
208 1.41 gehenna dev_type_size(xysize);
209 1.41 gehenna
210 1.41 gehenna const struct bdevsw xy_bdevsw = {
211 1.95 dholland .d_open = xyopen,
212 1.95 dholland .d_close = xyclose,
213 1.95 dholland .d_strategy = xystrategy,
214 1.95 dholland .d_ioctl = xyioctl,
215 1.95 dholland .d_dump = xydump,
216 1.95 dholland .d_psize = xysize,
217 1.96 dholland .d_discard = nodiscard,
218 1.95 dholland .d_flag = D_DISK
219 1.41 gehenna };
220 1.41 gehenna
221 1.41 gehenna const struct cdevsw xy_cdevsw = {
222 1.95 dholland .d_open = xyopen,
223 1.95 dholland .d_close = xyclose,
224 1.95 dholland .d_read = xyread,
225 1.95 dholland .d_write = xywrite,
226 1.95 dholland .d_ioctl = xyioctl,
227 1.95 dholland .d_stop = nostop,
228 1.95 dholland .d_tty = notty,
229 1.95 dholland .d_poll = nopoll,
230 1.95 dholland .d_mmap = nommap,
231 1.95 dholland .d_kqfilter = nokqfilter,
232 1.97 dholland .d_discard = nodiscard,
233 1.95 dholland .d_flag = D_DISK
234 1.41 gehenna };
235 1.1 pk
236 1.1 pk struct xyc_attach_args { /* this is the "aux" args to xyattach */
237 1.1 pk int driveno; /* unit number */
238 1.1 pk int fullmode; /* submit mode */
239 1.1 pk int booting; /* are we booting or not? */
240 1.1 pk };
241 1.1 pk
242 1.1 pk /*
243 1.1 pk * dkdriver
244 1.1 pk */
245 1.1 pk
246 1.99 mlelstv struct dkdriver xydkdriver = {
247 1.99 mlelstv .d_strategy = xystrategy
248 1.99 mlelstv };
249 1.1 pk
250 1.1 pk /*
251 1.1 pk * start: disk label fix code (XXX)
252 1.1 pk */
253 1.1 pk
254 1.1 pk static void *xy_labeldata;
255 1.1 pk
256 1.1 pk static void
257 1.84 dsl xydummystrat(struct buf *bp)
258 1.1 pk {
259 1.1 pk if (bp->b_bcount != XYFM_BPS)
260 1.1 pk panic("xydummystrat");
261 1.88 tsutsui memcpy(bp->b_data, xy_labeldata, XYFM_BPS);
262 1.75 ad bp->b_oflags |= BO_DONE;
263 1.75 ad bp->b_cflags &= ~BC_BUSY;
264 1.1 pk }
265 1.1 pk
266 1.1 pk int
267 1.84 dsl xygetdisklabel(struct xy_softc *xy, void *b)
268 1.1 pk {
269 1.48 dsl const char *err;
270 1.25 chs #if defined(__sparc__) || defined(sun3)
271 1.1 pk struct sun_disklabel *sdl;
272 1.11 pk #endif
273 1.1 pk
274 1.1 pk /* We already have the label data in `b'; setup for dummy strategy */
275 1.1 pk xy_labeldata = b;
276 1.1 pk
277 1.1 pk /* Required parameter for readdisklabel() */
278 1.1 pk xy->sc_dk.dk_label->d_secsize = XYFM_BPS;
279 1.1 pk
280 1.93 chs err = readdisklabel(MAKEDISKDEV(0, device_unit(xy->sc_dev), RAW_PART),
281 1.1 pk xydummystrat,
282 1.1 pk xy->sc_dk.dk_label, xy->sc_dk.dk_cpulabel);
283 1.1 pk if (err) {
284 1.93 chs printf("%s: %s\n", device_xname(xy->sc_dev), err);
285 1.1 pk return(XY_ERR_FAIL);
286 1.1 pk }
287 1.1 pk
288 1.25 chs #if defined(__sparc__) || defined(sun3)
289 1.1 pk /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */
290 1.1 pk sdl = (struct sun_disklabel *)xy->sc_dk.dk_cpulabel->cd_block;
291 1.11 pk if (sdl->sl_magic == SUN_DKMAGIC) {
292 1.1 pk xy->pcyl = sdl->sl_pcylinders;
293 1.11 pk } else
294 1.14 drochner #endif
295 1.11 pk {
296 1.1 pk printf("%s: WARNING: no `pcyl' in disk label.\n",
297 1.93 chs device_xname(xy->sc_dev));
298 1.1 pk xy->pcyl = xy->sc_dk.dk_label->d_ncylinders +
299 1.1 pk xy->sc_dk.dk_label->d_acylinders;
300 1.1 pk printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n",
301 1.93 chs device_xname(xy->sc_dev), xy->pcyl);
302 1.1 pk }
303 1.1 pk
304 1.1 pk xy->ncyl = xy->sc_dk.dk_label->d_ncylinders;
305 1.1 pk xy->acyl = xy->sc_dk.dk_label->d_acylinders;
306 1.1 pk xy->nhead = xy->sc_dk.dk_label->d_ntracks;
307 1.1 pk xy->nsect = xy->sc_dk.dk_label->d_nsectors;
308 1.1 pk xy->sectpercyl = xy->nhead * xy->nsect;
309 1.1 pk xy->sc_dk.dk_label->d_secsize = XYFM_BPS; /* not handled by
310 1.1 pk * sun->bsd */
311 1.1 pk return(XY_ERR_AOK);
312 1.1 pk }
313 1.1 pk
314 1.1 pk /*
315 1.1 pk * end: disk label fix code (XXX)
316 1.1 pk */
317 1.1 pk
318 1.1 pk /*
319 1.19 pk * Shorthand for allocating, mapping and loading a DMA buffer
320 1.19 pk */
321 1.19 pk int
322 1.84 dsl xy_dmamem_alloc(bus_dma_tag_t tag, bus_dmamap_t map, bus_dma_segment_t *seg, int *nsegp, bus_size_t len, void * *kvap, bus_addr_t *dmap)
323 1.19 pk {
324 1.19 pk int nseg;
325 1.19 pk int error;
326 1.19 pk
327 1.20 pk if ((error = bus_dmamem_alloc(tag, len, 0, 0,
328 1.19 pk seg, 1, &nseg, BUS_DMA_NOWAIT)) != 0) {
329 1.19 pk return (error);
330 1.19 pk }
331 1.19 pk
332 1.34 thorpej if ((error = bus_dmamem_map(tag, seg, nseg,
333 1.34 thorpej len, kvap,
334 1.34 thorpej BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
335 1.19 pk bus_dmamem_free(tag, seg, nseg);
336 1.19 pk return (error);
337 1.19 pk }
338 1.19 pk
339 1.35 chs if ((error = bus_dmamap_load(tag, map, *kvap, len, NULL,
340 1.34 thorpej BUS_DMA_NOWAIT)) != 0) {
341 1.34 thorpej bus_dmamem_unmap(tag, *kvap, len);
342 1.19 pk bus_dmamem_free(tag, seg, nseg);
343 1.19 pk return (error);
344 1.19 pk }
345 1.19 pk
346 1.19 pk *dmap = map->dm_segs[0].ds_addr;
347 1.19 pk *nsegp = nseg;
348 1.19 pk return (0);
349 1.19 pk }
350 1.19 pk
351 1.19 pk void
352 1.84 dsl xy_dmamem_free(bus_dma_tag_t tag, bus_dmamap_t map, bus_dma_segment_t *seg, int nseg, bus_size_t len, void * kva)
353 1.19 pk {
354 1.19 pk
355 1.19 pk bus_dmamap_unload(tag, map);
356 1.19 pk bus_dmamem_unmap(tag, kva, len);
357 1.19 pk bus_dmamem_free(tag, seg, nseg);
358 1.19 pk }
359 1.19 pk
360 1.19 pk
361 1.19 pk /*
362 1.1 pk * a u t o c o n f i g f u n c t i o n s
363 1.1 pk */
364 1.1 pk
365 1.1 pk /*
366 1.1 pk * xycmatch: determine if xyc is present or not. we do a
367 1.1 pk * soft reset to detect the xyc.
368 1.1 pk */
369 1.6 pk int
370 1.84 dsl xyc_probe(void *arg, bus_space_tag_t tag, bus_space_handle_t handle)
371 1.6 pk {
372 1.12 drochner struct xyc *xyc = (void *)handle; /* XXX */
373 1.6 pk
374 1.12 drochner return ((xyc_unbusy(xyc, XYC_RESETUSEC) != XY_ERR_FAIL) ? 0 : EIO);
375 1.6 pk }
376 1.1 pk
377 1.92 matt int
378 1.92 matt xycmatch(device_t parent, cfdata_t cf, void *aux)
379 1.1 pk {
380 1.1 pk struct vme_attach_args *va = aux;
381 1.12 drochner vme_chipset_tag_t ct = va->va_vct;
382 1.12 drochner vme_am_t mod;
383 1.12 drochner int error;
384 1.12 drochner
385 1.28 pk mod = VME_AM_A16 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
386 1.28 pk if (vme_space_alloc(ct, va->r[0].offset, sizeof(struct xyc), mod))
387 1.12 drochner return (0);
388 1.28 pk
389 1.12 drochner error = vme_probe(ct, va->r[0].offset, sizeof(struct xyc),
390 1.28 pk mod, VME_D16, xyc_probe, 0);
391 1.12 drochner vme_space_free(va->va_vct, va->r[0].offset, sizeof(struct xyc), mod);
392 1.12 drochner
393 1.12 drochner return (error == 0);
394 1.1 pk }
395 1.1 pk
396 1.1 pk /*
397 1.1 pk * xycattach: attach controller
398 1.1 pk */
399 1.1 pk void
400 1.90 cegger xycattach(device_t parent, device_t self, void *aux)
401 1.1 pk {
402 1.81 drochner struct xyc_softc *xyc = device_private(self);
403 1.1 pk struct vme_attach_args *va = aux;
404 1.12 drochner vme_chipset_tag_t ct = va->va_vct;
405 1.12 drochner bus_space_tag_t bt;
406 1.1 pk bus_space_handle_t bh;
407 1.1 pk vme_intr_handle_t ih;
408 1.12 drochner vme_am_t mod;
409 1.1 pk struct xyc_attach_args xa;
410 1.19 pk int lcv, res, error;
411 1.2 pk bus_dma_segment_t seg;
412 1.2 pk int rseg;
413 1.12 drochner vme_mapresc_t resc;
414 1.52 mrg bus_addr_t busaddr;
415 1.1 pk
416 1.93 chs xyc->sc_dev = self;
417 1.93 chs
418 1.1 pk /* get addressing and intr level stuff from autoconfig and load it
419 1.1 pk * into our xyc_softc. */
420 1.1 pk
421 1.28 pk mod = VME_AM_A16 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
422 1.1 pk
423 1.28 pk if (vme_space_alloc(ct, va->r[0].offset, sizeof(struct xyc), mod))
424 1.12 drochner panic("xyc: vme alloc");
425 1.28 pk
426 1.12 drochner if (vme_space_map(ct, va->r[0].offset, sizeof(struct xyc),
427 1.28 pk mod, VME_D16, 0, &bt, &bh, &resc) != 0)
428 1.1 pk panic("xyc: vme_map");
429 1.1 pk
430 1.12 drochner xyc->xyc = (struct xyc *) bh; /* XXX */
431 1.12 drochner xyc->ipl = va->ilevel;
432 1.12 drochner xyc->vector = va->ivector;
433 1.1 pk xyc->no_ols = 0; /* XXX should be from config */
434 1.1 pk
435 1.1 pk for (lcv = 0; lcv < XYC_MAXDEV; lcv++)
436 1.93 chs xyc->sc_drives[lcv] = NULL;
437 1.1 pk
438 1.1 pk /*
439 1.1 pk * allocate and zero buffers
440 1.1 pk * check boundaries of the KVA's ... all IOPBs must reside in
441 1.1 pk * the same 64K region.
442 1.1 pk */
443 1.1 pk
444 1.19 pk /* Get DMA handle for misc. transfers */
445 1.28 pk if ((error = vme_dmamap_create(
446 1.28 pk ct, /* VME chip tag */
447 1.28 pk MAXPHYS, /* size */
448 1.28 pk VME_AM_A24, /* address modifier */
449 1.28 pk VME_D16, /* data size */
450 1.28 pk 0, /* swap */
451 1.19 pk 1, /* nsegments */
452 1.28 pk MAXPHYS, /* maxsegsz */
453 1.19 pk 0, /* boundary */
454 1.19 pk BUS_DMA_NOWAIT,
455 1.55 pk &xyc->auxmap)) != 0) {
456 1.28 pk
457 1.93 chs aprint_error_dev(xyc->sc_dev, "DMA buffer map create error %d\n",
458 1.79 cegger error);
459 1.19 pk return;
460 1.19 pk }
461 1.2 pk
462 1.19 pk /* Get DMA handle for mapping iorq descriptors */
463 1.28 pk if ((error = vme_dmamap_create(
464 1.28 pk ct, /* VME chip tag */
465 1.19 pk XYC_MAXIOPB * sizeof(struct xy_iopb),
466 1.28 pk VME_AM_A24, /* address modifier */
467 1.28 pk VME_D16, /* data size */
468 1.28 pk 0, /* swap */
469 1.19 pk 1, /* nsegments */
470 1.19 pk XYC_MAXIOPB * sizeof(struct xy_iopb),
471 1.19 pk 64*1024, /* boundary */
472 1.19 pk BUS_DMA_NOWAIT,
473 1.19 pk &xyc->iopmap)) != 0) {
474 1.28 pk
475 1.93 chs aprint_error_dev(xyc->sc_dev, "DMA buffer map create error %d\n",
476 1.79 cegger error);
477 1.2 pk return;
478 1.2 pk }
479 1.2 pk
480 1.19 pk /* Get DMA buffer for iorq descriptors */
481 1.19 pk if ((error = xy_dmamem_alloc(xyc->dmatag, xyc->iopmap, &seg, &rseg,
482 1.19 pk XYC_MAXIOPB * sizeof(struct xy_iopb),
483 1.69 christos (void **)&xyc->iopbase,
484 1.52 mrg &busaddr)) != 0) {
485 1.93 chs aprint_error_dev(xyc->sc_dev, "DMA buffer alloc error %d\n",
486 1.79 cegger error);
487 1.2 pk return;
488 1.1 pk }
489 1.53 mrg xyc->dvmaiopb = (struct xy_iopb *)(u_long)BUS_ADDR_PADDR(busaddr);
490 1.19 pk
491 1.86 cegger memset(xyc->iopbase, 0, XYC_MAXIOPB * sizeof(struct xy_iopb));
492 1.2 pk
493 1.1 pk xyc->reqs = (struct xy_iorq *)
494 1.39 tsutsui malloc(XYC_MAXIOPB * sizeof(struct xy_iorq),
495 1.39 tsutsui M_DEVBUF, M_NOWAIT|M_ZERO);
496 1.1 pk if (xyc->reqs == NULL)
497 1.1 pk panic("xyc malloc");
498 1.1 pk
499 1.1 pk /*
500 1.1 pk * init iorq to iopb pointers, and non-zero fields in the
501 1.1 pk * iopb which never change.
502 1.1 pk */
503 1.1 pk
504 1.1 pk for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) {
505 1.1 pk xyc->xy_chain[lcv] = NULL;
506 1.1 pk xyc->reqs[lcv].iopb = &xyc->iopbase[lcv];
507 1.10 pk xyc->reqs[lcv].dmaiopb = &xyc->dvmaiopb[lcv];
508 1.1 pk xyc->iopbase[lcv].asr = 1; /* always the same */
509 1.1 pk xyc->iopbase[lcv].eef = 1; /* always the same */
510 1.1 pk xyc->iopbase[lcv].ecm = XY_ECM; /* always the same */
511 1.1 pk xyc->iopbase[lcv].aud = 1; /* always the same */
512 1.1 pk xyc->iopbase[lcv].relo = 1; /* always the same */
513 1.1 pk xyc->iopbase[lcv].thro = XY_THRO;/* always the same */
514 1.2 pk
515 1.28 pk if ((error = vme_dmamap_create(
516 1.28 pk ct, /* VME chip tag */
517 1.2 pk MAXPHYS, /* size */
518 1.28 pk VME_AM_A24, /* address modifier */
519 1.28 pk VME_D16, /* data size */
520 1.28 pk 0, /* swap */
521 1.2 pk 1, /* nsegments */
522 1.2 pk MAXPHYS, /* maxsegsz */
523 1.2 pk 0, /* boundary */
524 1.2 pk BUS_DMA_NOWAIT,
525 1.28 pk &xyc->reqs[lcv].dmamap)) != 0) {
526 1.28 pk
527 1.93 chs aprint_error_dev(xyc->sc_dev, "DMA buffer map create error %d\n",
528 1.79 cegger error);
529 1.2 pk return;
530 1.2 pk }
531 1.1 pk }
532 1.1 pk xyc->ciorq = &xyc->reqs[XYC_CTLIOPB]; /* short hand name */
533 1.1 pk xyc->ciopb = &xyc->iopbase[XYC_CTLIOPB]; /* short hand name */
534 1.1 pk xyc->xy_hand = 0;
535 1.1 pk
536 1.1 pk /* read controller parameters and insure we have a 450/451 */
537 1.1 pk
538 1.2 pk error = xyc_cmd(xyc, XYCMD_ST, 0, 0, 0, 0, 0, XY_SUB_POLL);
539 1.1 pk res = xyc->ciopb->ctyp;
540 1.2 pk XYC_DONE(xyc, error);
541 1.1 pk if (res != XYCT_450) {
542 1.2 pk if (error)
543 1.2 pk printf(": %s: ", xyc_e2str(error));
544 1.1 pk printf(": doesn't identify as a 450/451\n");
545 1.1 pk return;
546 1.1 pk }
547 1.1 pk printf(": Xylogics 450/451");
548 1.1 pk if (xyc->no_ols)
549 1.1 pk printf(" [OLS disabled]"); /* 450 doesn't overlap seek right */
550 1.1 pk printf("\n");
551 1.2 pk if (error) {
552 1.93 chs aprint_error_dev(xyc->sc_dev, "error: %s\n",
553 1.2 pk xyc_e2str(error));
554 1.1 pk return;
555 1.1 pk }
556 1.1 pk if ((xyc->xyc->xyc_csr & XYC_ADRM) == 0) {
557 1.1 pk printf("%s: 24 bit addressing turned off\n",
558 1.93 chs device_xname(xyc->sc_dev));
559 1.1 pk printf("please set hardware jumpers JM1-JM2=in, JM3-JM4=out\n");
560 1.1 pk printf("to enable 24 bit mode and this driver\n");
561 1.1 pk return;
562 1.1 pk }
563 1.1 pk
564 1.1 pk /* link in interrupt with higher level software */
565 1.30 scw vme_intr_map(ct, va->ilevel, va->ivector, &ih);
566 1.12 drochner vme_intr_establish(ct, ih, IPL_BIO, xycintr, xyc);
567 1.24 cgd evcnt_attach_dynamic(&xyc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
568 1.93 chs device_xname(xyc->sc_dev), "intr");
569 1.1 pk
570 1.71 ad callout_init(&xyc->sc_tick_ch, 0);
571 1.1 pk
572 1.1 pk /* now we must look for disks using autoconfig */
573 1.1 pk xa.fullmode = XY_SUB_POLL;
574 1.1 pk xa.booting = 1;
575 1.1 pk
576 1.1 pk for (xa.driveno = 0; xa.driveno < XYC_MAXDEV; xa.driveno++)
577 1.1 pk (void) config_found(self, (void *) &xa, NULL);
578 1.1 pk
579 1.1 pk /* start the watchdog clock */
580 1.17 thorpej callout_reset(&xyc->sc_tick_ch, XYC_TICKCNT, xyc_tick, xyc);
581 1.1 pk
582 1.1 pk }
583 1.1 pk
584 1.1 pk /*
585 1.1 pk * xymatch: probe for disk.
586 1.1 pk *
587 1.1 pk * note: we almost always say disk is present. this allows us to
588 1.1 pk * spin up and configure a disk after the system is booted (we can
589 1.1 pk * call xyattach!).
590 1.1 pk */
591 1.1 pk int
592 1.90 cegger xymatch(device_t parent, cfdata_t cf, void *aux)
593 1.1 pk {
594 1.1 pk struct xyc_attach_args *xa = aux;
595 1.1 pk
596 1.1 pk /* looking for autoconf wildcard or exact match */
597 1.1 pk
598 1.1 pk if (cf->cf_loc[XYCCF_DRIVE] != XYCCF_DRIVE_DEFAULT &&
599 1.1 pk cf->cf_loc[XYCCF_DRIVE] != xa->driveno)
600 1.1 pk return 0;
601 1.1 pk
602 1.1 pk return 1;
603 1.1 pk
604 1.1 pk }
605 1.1 pk
606 1.1 pk /*
607 1.1 pk * xyattach: attach a disk. this can be called from autoconf and also
608 1.1 pk * from xyopen/xystrategy.
609 1.1 pk */
610 1.1 pk void
611 1.90 cegger xyattach(device_t parent, device_t self, void *aux)
612 1.1 pk {
613 1.81 drochner struct xy_softc *xy = device_private(self), *oxy;
614 1.81 drochner struct xyc_softc *xyc = device_private(parent);
615 1.1 pk struct xyc_attach_args *xa = aux;
616 1.2 pk int spt, mb, blk, lcv, fmode, s = 0, newstate;
617 1.1 pk struct dkbad *dkb;
618 1.2 pk int rseg, error;
619 1.2 pk bus_dma_segment_t seg;
620 1.52 mrg bus_addr_t busaddr;
621 1.69 christos void * dmaddr;
622 1.70 mrg char * buf;
623 1.1 pk
624 1.93 chs xy->sc_dev = self;
625 1.93 chs
626 1.1 pk /*
627 1.1 pk * Always re-initialize the disk structure. We want statistics
628 1.1 pk * to start with a clean slate.
629 1.1 pk */
630 1.86 cegger memset(&xy->sc_dk, 0, sizeof(xy->sc_dk));
631 1.1 pk
632 1.1 pk /* if booting, init the xy_softc */
633 1.1 pk
634 1.1 pk if (xa->booting) {
635 1.1 pk xy->state = XY_DRIVE_UNKNOWN; /* to start */
636 1.1 pk xy->flags = 0;
637 1.1 pk xy->parent = xyc;
638 1.1 pk
639 1.1 pk /* init queue of waiting bufs */
640 1.1 pk
641 1.60 yamt bufq_alloc(&xy->xyq, "disksort", BUFQ_SORT_RAWBLOCK);
642 1.1 pk
643 1.1 pk xy->xyrq = &xyc->reqs[xa->driveno];
644 1.1 pk
645 1.1 pk }
646 1.1 pk xy->xy_drive = xa->driveno;
647 1.1 pk fmode = xa->fullmode;
648 1.1 pk xyc->sc_drives[xa->driveno] = xy;
649 1.1 pk
650 1.1 pk /* if not booting, make sure we are the only process in the attach for
651 1.1 pk * this drive. if locked out, sleep on it. */
652 1.1 pk
653 1.1 pk if (!xa->booting) {
654 1.1 pk s = splbio();
655 1.1 pk while (xy->state == XY_DRIVE_ATTACHING) {
656 1.1 pk if (tsleep(&xy->state, PRIBIO, "xyattach", 0)) {
657 1.1 pk splx(s);
658 1.1 pk return;
659 1.1 pk }
660 1.1 pk }
661 1.1 pk printf("%s at %s",
662 1.93 chs device_xname(xy->sc_dev), device_xname(xy->parent->sc_dev));
663 1.1 pk }
664 1.2 pk
665 1.1 pk /* we now have control */
666 1.1 pk xy->state = XY_DRIVE_ATTACHING;
667 1.1 pk newstate = XY_DRIVE_UNKNOWN;
668 1.1 pk
669 1.2 pk buf = NULL;
670 1.19 pk if ((error = xy_dmamem_alloc(xyc->dmatag, xyc->auxmap, &seg, &rseg,
671 1.19 pk XYFM_BPS,
672 1.69 christos (void **)&buf,
673 1.52 mrg &busaddr)) != 0) {
674 1.93 chs aprint_error_dev(xyc->sc_dev, "DMA buffer alloc error %d\n",
675 1.79 cegger error);
676 1.19 pk return;
677 1.2 pk }
678 1.69 christos dmaddr = (void *)(u_long)BUS_ADDR_PADDR(busaddr);
679 1.2 pk
680 1.1 pk /* first try and reset the drive */
681 1.2 pk error = xyc_cmd(xyc, XYCMD_RST, 0, xy->xy_drive, 0, 0, 0, fmode);
682 1.2 pk XYC_DONE(xyc, error);
683 1.2 pk if (error == XY_ERR_DNRY) {
684 1.1 pk printf(" drive %d: off-line\n", xa->driveno);
685 1.1 pk goto done;
686 1.1 pk }
687 1.2 pk if (error) {
688 1.2 pk printf(": ERROR 0x%02x (%s)\n", error, xyc_e2str(error));
689 1.1 pk goto done;
690 1.1 pk }
691 1.1 pk printf(" drive %d: ready", xa->driveno);
692 1.1 pk
693 1.1 pk /*
694 1.1 pk * now set drive parameters (to semi-bogus values) so we can read the
695 1.1 pk * disk label.
696 1.1 pk */
697 1.1 pk xy->pcyl = xy->ncyl = 1;
698 1.1 pk xy->acyl = 0;
699 1.1 pk xy->nhead = 1;
700 1.1 pk xy->nsect = 1;
701 1.1 pk xy->sectpercyl = 1;
702 1.1 pk for (lcv = 0; lcv < 126; lcv++) /* init empty bad144 table */
703 1.1 pk xy->dkb.bt_bad[lcv].bt_cyl =
704 1.1 pk xy->dkb.bt_bad[lcv].bt_trksec = 0xffff;
705 1.1 pk
706 1.1 pk /* read disk label */
707 1.1 pk for (xy->drive_type = 0 ; xy->drive_type <= XYC_MAXDT ;
708 1.1 pk xy->drive_type++) {
709 1.2 pk error = xyc_cmd(xyc, XYCMD_RD, 0, xy->xy_drive, 0, 1,
710 1.2 pk dmaddr, fmode);
711 1.2 pk XYC_DONE(xyc, error);
712 1.2 pk if (error == XY_ERR_AOK) break;
713 1.1 pk }
714 1.1 pk
715 1.2 pk if (error != XY_ERR_AOK) {
716 1.80 cegger aprint_normal("\n");
717 1.93 chs aprint_error_dev(xy->sc_dev, "reading disk label failed: %s\n",
718 1.79 cegger xyc_e2str(error));
719 1.1 pk goto done;
720 1.1 pk }
721 1.1 pk printf(" (drive type %d)\n", xy->drive_type);
722 1.1 pk
723 1.1 pk newstate = XY_DRIVE_NOLABEL;
724 1.1 pk
725 1.1 pk xy->hw_spt = spt = 0; /* XXX needed ? */
726 1.1 pk /* Attach the disk: must be before getdisklabel to malloc label */
727 1.93 chs disk_init(&xy->sc_dk, device_xname(xy->sc_dev), &xydkdriver);
728 1.1 pk disk_attach(&xy->sc_dk);
729 1.1 pk
730 1.2 pk if (xygetdisklabel(xy, buf) != XY_ERR_AOK)
731 1.1 pk goto done;
732 1.1 pk
733 1.1 pk /* inform the user of what is up */
734 1.93 chs printf("%s: <%s>, pcyl %d\n", device_xname(xy->sc_dev),
735 1.2 pk buf, xy->pcyl);
736 1.1 pk mb = xy->ncyl * (xy->nhead * xy->nsect) / (1048576 / XYFM_BPS);
737 1.1 pk printf("%s: %dMB, %d cyl, %d head, %d sec, %d bytes/sec\n",
738 1.93 chs device_xname(xy->sc_dev), mb, xy->ncyl, xy->nhead, xy->nsect,
739 1.1 pk XYFM_BPS);
740 1.1 pk
741 1.1 pk /*
742 1.1 pk * 450/451 stupidity: the drive type is encoded into the format
743 1.1 pk * of the disk. the drive type in the IOPB must match the drive
744 1.1 pk * type in the format, or you will not be able to do I/O to the
745 1.1 pk * disk (you get header not found errors). if you have two drives
746 1.1 pk * of different sizes that have the same drive type in their
747 1.1 pk * formatting then you are out of luck.
748 1.1 pk *
749 1.1 pk * this problem was corrected in the 753/7053.
750 1.1 pk */
751 1.1 pk
752 1.1 pk for (lcv = 0 ; lcv < XYC_MAXDEV ; lcv++) {
753 1.1 pk oxy = xyc->sc_drives[lcv];
754 1.1 pk if (oxy == NULL || oxy == xy) continue;
755 1.1 pk if (oxy->drive_type != xy->drive_type) continue;
756 1.1 pk if (xy->nsect != oxy->nsect || xy->pcyl != oxy->pcyl ||
757 1.1 pk xy->nhead != oxy->nhead) {
758 1.1 pk printf("%s: %s and %s must be the same size!\n",
759 1.93 chs device_xname(xyc->sc_dev), device_xname(xy->sc_dev),
760 1.93 chs device_xname(oxy->sc_dev));
761 1.1 pk panic("xy drive size mismatch");
762 1.1 pk }
763 1.1 pk }
764 1.1 pk
765 1.1 pk
766 1.1 pk /* now set the real drive parameters! */
767 1.1 pk
768 1.1 pk blk = (xy->nsect - 1) +
769 1.1 pk ((xy->nhead - 1) * xy->nsect) +
770 1.1 pk ((xy->pcyl - 1) * xy->nsect * xy->nhead);
771 1.2 pk error = xyc_cmd(xyc, XYCMD_SDS, 0, xy->xy_drive, blk, 0, 0, fmode);
772 1.2 pk XYC_DONE(xyc, error);
773 1.2 pk if (error) {
774 1.93 chs aprint_error_dev(xy->sc_dev, "write drive size failed: %s\n",
775 1.79 cegger xyc_e2str(error));
776 1.1 pk goto done;
777 1.1 pk }
778 1.1 pk newstate = XY_DRIVE_ONLINE;
779 1.1 pk
780 1.1 pk /*
781 1.1 pk * read bad144 table. this table resides on the first sector of the
782 1.1 pk * last track of the disk (i.e. second cyl of "acyl" area).
783 1.1 pk */
784 1.1 pk
785 1.1 pk blk = (xy->ncyl + xy->acyl - 1) * (xy->nhead * xy->nsect) +
786 1.1 pk /* last cyl */
787 1.1 pk (xy->nhead - 1) * xy->nsect; /* last head */
788 1.2 pk error = xyc_cmd(xyc, XYCMD_RD, 0, xy->xy_drive, blk, 1,
789 1.2 pk dmaddr, fmode);
790 1.2 pk XYC_DONE(xyc, error);
791 1.2 pk if (error) {
792 1.93 chs aprint_error_dev(xy->sc_dev, "reading bad144 failed: %s\n",
793 1.79 cegger xyc_e2str(error));
794 1.1 pk goto done;
795 1.1 pk }
796 1.1 pk
797 1.1 pk /* check dkbad for sanity */
798 1.2 pk dkb = (struct dkbad *) buf;
799 1.1 pk for (lcv = 0; lcv < 126; lcv++) {
800 1.1 pk if ((dkb->bt_bad[lcv].bt_cyl == 0xffff ||
801 1.1 pk dkb->bt_bad[lcv].bt_cyl == 0) &&
802 1.1 pk dkb->bt_bad[lcv].bt_trksec == 0xffff)
803 1.1 pk continue; /* blank */
804 1.1 pk if (dkb->bt_bad[lcv].bt_cyl >= xy->ncyl)
805 1.1 pk break;
806 1.1 pk if ((dkb->bt_bad[lcv].bt_trksec >> 8) >= xy->nhead)
807 1.1 pk break;
808 1.1 pk if ((dkb->bt_bad[lcv].bt_trksec & 0xff) >= xy->nsect)
809 1.1 pk break;
810 1.1 pk }
811 1.1 pk if (lcv != 126) {
812 1.93 chs aprint_error_dev(xy->sc_dev, "warning: invalid bad144 sector!\n");
813 1.1 pk } else {
814 1.88 tsutsui memcpy(&xy->dkb, buf, XYFM_BPS);
815 1.1 pk }
816 1.1 pk
817 1.1 pk done:
818 1.2 pk if (buf != NULL) {
819 1.19 pk xy_dmamem_free(xyc->dmatag, xyc->auxmap,
820 1.19 pk &seg, rseg, XYFM_BPS, buf);
821 1.2 pk }
822 1.2 pk
823 1.1 pk xy->state = newstate;
824 1.1 pk if (!xa->booting) {
825 1.1 pk wakeup(&xy->state);
826 1.1 pk splx(s);
827 1.1 pk }
828 1.1 pk }
829 1.1 pk
830 1.1 pk /*
831 1.1 pk * end of autoconfig functions
832 1.1 pk */
833 1.1 pk
834 1.1 pk /*
835 1.1 pk * { b , c } d e v s w f u n c t i o n s
836 1.1 pk */
837 1.1 pk
838 1.1 pk /*
839 1.1 pk * xyclose: close device
840 1.1 pk */
841 1.1 pk int
842 1.92 matt xyclose(dev_t dev, int flag, int fmt, struct lwp *l)
843 1.1 pk {
844 1.81 drochner struct xy_softc *xy = device_lookup_private(&xy_cd, DISKUNIT(dev));
845 1.1 pk int part = DISKPART(dev);
846 1.1 pk
847 1.1 pk /* clear mask bits */
848 1.1 pk
849 1.1 pk switch (fmt) {
850 1.1 pk case S_IFCHR:
851 1.1 pk xy->sc_dk.dk_copenmask &= ~(1 << part);
852 1.1 pk break;
853 1.1 pk case S_IFBLK:
854 1.1 pk xy->sc_dk.dk_bopenmask &= ~(1 << part);
855 1.1 pk break;
856 1.1 pk }
857 1.1 pk xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask;
858 1.1 pk
859 1.1 pk return 0;
860 1.1 pk }
861 1.1 pk
862 1.1 pk /*
863 1.1 pk * xydump: crash dump system
864 1.1 pk */
865 1.1 pk int
866 1.84 dsl xydump(dev_t dev, daddr_t blkno, void *va, size_t size)
867 1.1 pk {
868 1.1 pk int unit, part;
869 1.1 pk struct xy_softc *xy;
870 1.1 pk
871 1.1 pk unit = DISKUNIT(dev);
872 1.1 pk part = DISKPART(dev);
873 1.1 pk
874 1.81 drochner xy = device_lookup_private(&xy_cd, unit);
875 1.81 drochner if (!xy)
876 1.81 drochner return ENXIO;
877 1.1 pk
878 1.93 chs printf("%s%c: crash dump not supported (yet)\n", device_xname(xy->sc_dev),
879 1.1 pk 'a' + part);
880 1.1 pk
881 1.1 pk return ENXIO;
882 1.1 pk
883 1.1 pk /* outline: globals: "dumplo" == sector number of partition to start
884 1.1 pk * dump at (convert to physical sector with partition table)
885 1.1 pk * "dumpsize" == size of dump in clicks "physmem" == size of physical
886 1.1 pk * memory (clicks, ctob() to get bytes) (normal case: dumpsize ==
887 1.1 pk * physmem)
888 1.1 pk *
889 1.1 pk * dump a copy of physical memory to the dump device starting at sector
890 1.1 pk * "dumplo" in the swap partition (make sure > 0). map in pages as
891 1.1 pk * we go. use polled I/O.
892 1.1 pk *
893 1.1 pk * XXX how to handle NON_CONTIG? */
894 1.1 pk
895 1.1 pk }
896 1.1 pk
897 1.76 elad static enum kauth_device_req
898 1.76 elad xy_getkauthreq(u_char cmd)
899 1.76 elad {
900 1.76 elad enum kauth_device_req req;
901 1.76 elad
902 1.76 elad switch (cmd) {
903 1.76 elad case XYCMD_WR:
904 1.76 elad case XYCMD_WTH:
905 1.76 elad case XYCMD_WFM:
906 1.76 elad case XYCMD_WRH:
907 1.78 elad req = KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITE;
908 1.76 elad break;
909 1.76 elad
910 1.76 elad case XYCMD_RD:
911 1.76 elad case XYCMD_RTH:
912 1.76 elad case XYCMD_RDH:
913 1.78 elad req = KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READ;
914 1.76 elad break;
915 1.76 elad
916 1.76 elad case XYCMD_RDS:
917 1.76 elad case XYCMD_MBD:
918 1.78 elad req = KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READCONF;
919 1.76 elad break;
920 1.76 elad
921 1.76 elad case XYCMD_RST:
922 1.76 elad case XYCMD_SDS:
923 1.76 elad case XYCMD_MBL:
924 1.78 elad req = KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITECONF;
925 1.76 elad break;
926 1.76 elad
927 1.76 elad case XYCMD_NOP:
928 1.76 elad case XYCMD_SK:
929 1.76 elad case XYCMD_ST:
930 1.76 elad case XYCMD_R:
931 1.76 elad default:
932 1.76 elad req = 0;
933 1.76 elad break;
934 1.76 elad }
935 1.76 elad
936 1.76 elad return (req);
937 1.76 elad }
938 1.76 elad
939 1.1 pk /*
940 1.1 pk * xyioctl: ioctls on XY drives. based on ioctl's of other netbsd disks.
941 1.1 pk */
942 1.1 pk int
943 1.92 matt xyioctl(dev_t dev, u_long command, void *addr, int flag, struct lwp *l)
944 1.1 pk {
945 1.1 pk struct xy_softc *xy;
946 1.1 pk struct xd_iocmd *xio;
947 1.1 pk int error, s, unit;
948 1.31 fvdl #ifdef __HAVE_OLD_DISKLABEL
949 1.33 fvdl struct disklabel newlabel;
950 1.31 fvdl #endif
951 1.33 fvdl struct disklabel *lp;
952 1.33 fvdl
953 1.1 pk unit = DISKUNIT(dev);
954 1.1 pk
955 1.81 drochner if ((xy = device_lookup_private(&xy_cd, unit)) == NULL)
956 1.1 pk return (ENXIO);
957 1.1 pk
958 1.98 christos error = disk_ioctl(&xy->sc_dk, dev, command, addr, flag, l);
959 1.98 christos if (error != EPASSTHROUGH)
960 1.98 christos return error;
961 1.98 christos
962 1.1 pk /* switch on ioctl type */
963 1.1 pk
964 1.1 pk switch (command) {
965 1.1 pk case DIOCSBAD: /* set bad144 info */
966 1.1 pk if ((flag & FWRITE) == 0)
967 1.1 pk return EBADF;
968 1.1 pk s = splbio();
969 1.88 tsutsui memcpy(&xy->dkb, addr, sizeof(xy->dkb));
970 1.1 pk splx(s);
971 1.1 pk return 0;
972 1.1 pk
973 1.1 pk case DIOCSDINFO: /* set disk label */
974 1.31 fvdl #ifdef __HAVE_OLD_DISKLABEL
975 1.31 fvdl case ODIOCSDINFO:
976 1.31 fvdl if (command == ODIOCSDINFO) {
977 1.31 fvdl memset(&newlabel, 0, sizeof newlabel);
978 1.31 fvdl memcpy(&newlabel, addr, sizeof (struct olddisklabel));
979 1.31 fvdl lp = &newlabel;
980 1.31 fvdl } else
981 1.31 fvdl #endif
982 1.31 fvdl lp = (struct disklabel *)addr;
983 1.31 fvdl
984 1.1 pk if ((flag & FWRITE) == 0)
985 1.1 pk return EBADF;
986 1.1 pk error = setdisklabel(xy->sc_dk.dk_label,
987 1.31 fvdl lp, /* xy->sc_dk.dk_openmask : */ 0,
988 1.1 pk xy->sc_dk.dk_cpulabel);
989 1.1 pk if (error == 0) {
990 1.1 pk if (xy->state == XY_DRIVE_NOLABEL)
991 1.1 pk xy->state = XY_DRIVE_ONLINE;
992 1.1 pk }
993 1.1 pk return error;
994 1.1 pk
995 1.1 pk case DIOCWLABEL: /* change write status of disk label */
996 1.1 pk if ((flag & FWRITE) == 0)
997 1.1 pk return EBADF;
998 1.1 pk if (*(int *) addr)
999 1.1 pk xy->flags |= XY_WLABEL;
1000 1.1 pk else
1001 1.1 pk xy->flags &= ~XY_WLABEL;
1002 1.1 pk return 0;
1003 1.1 pk
1004 1.1 pk case DIOCWDINFO: /* write disk label */
1005 1.31 fvdl #ifdef __HAVE_OLD_DISKLABEL
1006 1.31 fvdl case ODIOCWDINFO:
1007 1.31 fvdl if (command == ODIOCWDINFO) {
1008 1.31 fvdl memset(&newlabel, 0, sizeof newlabel);
1009 1.31 fvdl memcpy(&newlabel, addr, sizeof (struct olddisklabel));
1010 1.31 fvdl lp = &newlabel;
1011 1.31 fvdl } else
1012 1.31 fvdl #endif
1013 1.31 fvdl lp = (struct disklabel *)addr;
1014 1.31 fvdl
1015 1.1 pk if ((flag & FWRITE) == 0)
1016 1.1 pk return EBADF;
1017 1.1 pk error = setdisklabel(xy->sc_dk.dk_label,
1018 1.31 fvdl lp, /* xy->sc_dk.dk_openmask : */ 0,
1019 1.1 pk xy->sc_dk.dk_cpulabel);
1020 1.1 pk if (error == 0) {
1021 1.1 pk if (xy->state == XY_DRIVE_NOLABEL)
1022 1.1 pk xy->state = XY_DRIVE_ONLINE;
1023 1.1 pk
1024 1.1 pk /* Simulate opening partition 0 so write succeeds. */
1025 1.1 pk xy->sc_dk.dk_openmask |= (1 << 0);
1026 1.1 pk error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART),
1027 1.1 pk xystrategy, xy->sc_dk.dk_label,
1028 1.1 pk xy->sc_dk.dk_cpulabel);
1029 1.1 pk xy->sc_dk.dk_openmask =
1030 1.1 pk xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask;
1031 1.1 pk }
1032 1.1 pk return error;
1033 1.1 pk
1034 1.76 elad case DIOSXDCMD: {
1035 1.76 elad enum kauth_device_req req;
1036 1.76 elad
1037 1.1 pk xio = (struct xd_iocmd *) addr;
1038 1.76 elad req = xy_getkauthreq(xio->cmd);
1039 1.76 elad if ((error = kauth_authorize_device_passthru(l->l_cred,
1040 1.76 elad dev, req, xio)) != 0)
1041 1.1 pk return (error);
1042 1.1 pk return (xyc_ioctlcmd(xy, dev, xio));
1043 1.77 elad }
1044 1.1 pk
1045 1.1 pk default:
1046 1.1 pk return ENOTTY;
1047 1.1 pk }
1048 1.1 pk }
1049 1.1 pk
1050 1.1 pk /*
1051 1.1 pk * xyopen: open drive
1052 1.1 pk */
1053 1.1 pk
1054 1.1 pk int
1055 1.85 dsl xyopen(dev_t dev, int flag, int fmt, struct lwp *l)
1056 1.1 pk {
1057 1.1 pk int unit, part;
1058 1.1 pk struct xy_softc *xy;
1059 1.1 pk struct xyc_attach_args xa;
1060 1.1 pk
1061 1.1 pk /* first, could it be a valid target? */
1062 1.1 pk
1063 1.1 pk unit = DISKUNIT(dev);
1064 1.81 drochner if ((xy = device_lookup_private(&xy_cd, unit)) == NULL)
1065 1.1 pk return (ENXIO);
1066 1.1 pk part = DISKPART(dev);
1067 1.1 pk
1068 1.1 pk /* do we need to attach the drive? */
1069 1.1 pk
1070 1.1 pk if (xy->state == XY_DRIVE_UNKNOWN) {
1071 1.1 pk xa.driveno = xy->xy_drive;
1072 1.1 pk xa.fullmode = XY_SUB_WAIT;
1073 1.1 pk xa.booting = 0;
1074 1.93 chs xyattach(xy->parent->sc_dev, xy->sc_dev, &xa);
1075 1.1 pk if (xy->state == XY_DRIVE_UNKNOWN) {
1076 1.1 pk return (EIO);
1077 1.1 pk }
1078 1.1 pk }
1079 1.1 pk /* check for partition */
1080 1.1 pk
1081 1.1 pk if (part != RAW_PART &&
1082 1.1 pk (part >= xy->sc_dk.dk_label->d_npartitions ||
1083 1.1 pk xy->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
1084 1.1 pk return (ENXIO);
1085 1.1 pk }
1086 1.1 pk /* set open masks */
1087 1.1 pk
1088 1.1 pk switch (fmt) {
1089 1.1 pk case S_IFCHR:
1090 1.1 pk xy->sc_dk.dk_copenmask |= (1 << part);
1091 1.1 pk break;
1092 1.1 pk case S_IFBLK:
1093 1.1 pk xy->sc_dk.dk_bopenmask |= (1 << part);
1094 1.1 pk break;
1095 1.1 pk }
1096 1.1 pk xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask;
1097 1.1 pk
1098 1.1 pk return 0;
1099 1.1 pk }
1100 1.1 pk
1101 1.1 pk int
1102 1.84 dsl xyread(dev_t dev, struct uio *uio, int flags)
1103 1.1 pk {
1104 1.1 pk
1105 1.1 pk return (physio(xystrategy, NULL, dev, B_READ, minphys, uio));
1106 1.1 pk }
1107 1.1 pk
1108 1.1 pk int
1109 1.84 dsl xywrite(dev_t dev, struct uio *uio, int flags)
1110 1.1 pk {
1111 1.1 pk
1112 1.1 pk return (physio(xystrategy, NULL, dev, B_WRITE, minphys, uio));
1113 1.1 pk }
1114 1.1 pk
1115 1.1 pk
1116 1.1 pk /*
1117 1.1 pk * xysize: return size of a partition for a dump
1118 1.1 pk */
1119 1.1 pk
1120 1.1 pk int
1121 1.92 matt xysize(dev_t dev)
1122 1.1 pk {
1123 1.1 pk struct xy_softc *xysc;
1124 1.1 pk int unit, part, size, omask;
1125 1.1 pk
1126 1.1 pk /* valid unit? */
1127 1.1 pk unit = DISKUNIT(dev);
1128 1.81 drochner if ((xysc = device_lookup_private(&xy_cd, unit)) == NULL)
1129 1.1 pk return (-1);
1130 1.1 pk
1131 1.1 pk part = DISKPART(dev);
1132 1.1 pk omask = xysc->sc_dk.dk_openmask & (1 << part);
1133 1.1 pk
1134 1.1 pk if (omask == 0 && xyopen(dev, 0, S_IFBLK, NULL) != 0)
1135 1.1 pk return (-1);
1136 1.1 pk
1137 1.1 pk /* do it */
1138 1.1 pk if (xysc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
1139 1.1 pk size = -1; /* only give valid size for swap partitions */
1140 1.1 pk else
1141 1.1 pk size = xysc->sc_dk.dk_label->d_partitions[part].p_size *
1142 1.1 pk (xysc->sc_dk.dk_label->d_secsize / DEV_BSIZE);
1143 1.1 pk if (omask == 0 && xyclose(dev, 0, S_IFBLK, NULL) != 0)
1144 1.1 pk return (-1);
1145 1.1 pk return (size);
1146 1.1 pk }
1147 1.1 pk
1148 1.1 pk /*
1149 1.1 pk * xystrategy: buffering system interface to xy.
1150 1.1 pk */
1151 1.1 pk
1152 1.1 pk void
1153 1.92 matt xystrategy(struct buf *bp)
1154 1.1 pk {
1155 1.1 pk struct xy_softc *xy;
1156 1.1 pk int s, unit;
1157 1.1 pk struct xyc_attach_args xa;
1158 1.16 thorpej struct disklabel *lp;
1159 1.16 thorpej daddr_t blkno;
1160 1.1 pk
1161 1.1 pk unit = DISKUNIT(bp->b_dev);
1162 1.1 pk
1163 1.1 pk /* check for live device */
1164 1.1 pk
1165 1.81 drochner if (!(xy = device_lookup_private(&xy_cd, unit)) ||
1166 1.1 pk bp->b_blkno < 0 ||
1167 1.1 pk (bp->b_bcount % xy->sc_dk.dk_label->d_secsize) != 0) {
1168 1.1 pk bp->b_error = EINVAL;
1169 1.72 ad goto done;
1170 1.1 pk }
1171 1.1 pk /* do we need to attach the drive? */
1172 1.1 pk
1173 1.1 pk if (xy->state == XY_DRIVE_UNKNOWN) {
1174 1.1 pk xa.driveno = xy->xy_drive;
1175 1.1 pk xa.fullmode = XY_SUB_WAIT;
1176 1.1 pk xa.booting = 0;
1177 1.93 chs xyattach(xy->parent->sc_dev, xy->sc_dev, &xa);
1178 1.1 pk if (xy->state == XY_DRIVE_UNKNOWN) {
1179 1.1 pk bp->b_error = EIO;
1180 1.72 ad goto done;
1181 1.1 pk }
1182 1.1 pk }
1183 1.1 pk if (xy->state != XY_DRIVE_ONLINE && DISKPART(bp->b_dev) != RAW_PART) {
1184 1.1 pk /* no I/O to unlabeled disks, unless raw partition */
1185 1.1 pk bp->b_error = EIO;
1186 1.72 ad goto done;
1187 1.1 pk }
1188 1.1 pk /* short circuit zero length request */
1189 1.1 pk
1190 1.1 pk if (bp->b_bcount == 0)
1191 1.1 pk goto done;
1192 1.1 pk
1193 1.1 pk /* check bounds with label (disksubr.c). Determine the size of the
1194 1.1 pk * transfer, and make sure it is within the boundaries of the
1195 1.1 pk * partition. Adjust transfer if needed, and signal errors or early
1196 1.1 pk * completion. */
1197 1.1 pk
1198 1.16 thorpej lp = xy->sc_dk.dk_label;
1199 1.16 thorpej
1200 1.49 thorpej if (bounds_check_with_label(&xy->sc_dk, bp,
1201 1.1 pk (xy->flags & XY_WLABEL) != 0) <= 0)
1202 1.1 pk goto done;
1203 1.1 pk
1204 1.1 pk /*
1205 1.16 thorpej * Now convert the block number to absolute and put it in
1206 1.16 thorpej * terms of the device's logical block size.
1207 1.16 thorpej */
1208 1.16 thorpej blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
1209 1.16 thorpej if (DISKPART(bp->b_dev) != RAW_PART)
1210 1.16 thorpej blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
1211 1.16 thorpej
1212 1.16 thorpej bp->b_rawblkno = blkno;
1213 1.16 thorpej
1214 1.16 thorpej /*
1215 1.1 pk * now we know we have a valid buf structure that we need to do I/O
1216 1.1 pk * on.
1217 1.1 pk */
1218 1.1 pk s = splbio(); /* protect the queues */
1219 1.1 pk
1220 1.83 yamt bufq_put(xy->xyq, bp);
1221 1.1 pk
1222 1.1 pk /* start 'em up */
1223 1.1 pk
1224 1.1 pk xyc_start(xy->parent, NULL);
1225 1.1 pk
1226 1.1 pk /* done! */
1227 1.1 pk
1228 1.1 pk splx(s);
1229 1.1 pk return;
1230 1.1 pk
1231 1.1 pk done: /* tells upper layers we are done with this
1232 1.1 pk * buf */
1233 1.1 pk bp->b_resid = bp->b_bcount;
1234 1.1 pk biodone(bp);
1235 1.1 pk }
1236 1.1 pk /*
1237 1.1 pk * end of {b,c}devsw functions
1238 1.1 pk */
1239 1.1 pk
1240 1.1 pk /*
1241 1.1 pk * i n t e r r u p t f u n c t i o n
1242 1.1 pk *
1243 1.1 pk * xycintr: hardware interrupt.
1244 1.1 pk */
1245 1.1 pk int
1246 1.92 matt xycintr(void *v)
1247 1.1 pk {
1248 1.1 pk struct xyc_softc *xycsc = v;
1249 1.1 pk
1250 1.1 pk /* kick the event counter */
1251 1.1 pk
1252 1.1 pk xycsc->sc_intrcnt.ev_count++;
1253 1.1 pk
1254 1.1 pk /* remove as many done IOPBs as possible */
1255 1.1 pk
1256 1.1 pk xyc_remove_iorq(xycsc);
1257 1.1 pk
1258 1.1 pk /* start any iorq's already waiting */
1259 1.1 pk
1260 1.1 pk xyc_start(xycsc, NULL);
1261 1.1 pk
1262 1.1 pk return (1);
1263 1.1 pk }
1264 1.1 pk /*
1265 1.1 pk * end of interrupt function
1266 1.1 pk */
1267 1.1 pk
1268 1.1 pk /*
1269 1.1 pk * i n t e r n a l f u n c t i o n s
1270 1.1 pk */
1271 1.1 pk
1272 1.1 pk /*
1273 1.1 pk * xyc_rqinit: fill out the fields of an I/O request
1274 1.1 pk */
1275 1.1 pk
1276 1.1 pk inline void
1277 1.84 dsl xyc_rqinit(struct xy_iorq *rq, struct xyc_softc *xyc, struct xy_softc *xy, int md, u_long blk, int cnt, void *db, struct buf *bp)
1278 1.1 pk {
1279 1.1 pk rq->xyc = xyc;
1280 1.1 pk rq->xy = xy;
1281 1.1 pk rq->ttl = XYC_MAXTTL + 10;
1282 1.1 pk rq->mode = md;
1283 1.67 christos rq->tries = rq->errnum = rq->lasterror = 0;
1284 1.1 pk rq->blockno = blk;
1285 1.1 pk rq->sectcnt = cnt;
1286 1.2 pk rq->dbuf = db;
1287 1.1 pk rq->buf = bp;
1288 1.1 pk }
1289 1.1 pk
1290 1.1 pk /*
1291 1.1 pk * xyc_rqtopb: load up an IOPB based on an iorq
1292 1.1 pk */
1293 1.1 pk
1294 1.1 pk void
1295 1.92 matt xyc_rqtopb(struct xy_iorq *iorq, struct xy_iopb *iopb, int cmd, int subfun)
1296 1.1 pk {
1297 1.1 pk u_long block, dp;
1298 1.1 pk
1299 1.1 pk /* normal IOPB case, standard stuff */
1300 1.1 pk
1301 1.1 pk /* chain bit handled later */
1302 1.1 pk iopb->ien = (XY_STATE(iorq->mode) == XY_SUB_POLL) ? 0 : 1;
1303 1.1 pk iopb->com = cmd;
1304 1.67 christos iopb->errnum = 0;
1305 1.1 pk iopb->errs = 0;
1306 1.1 pk iopb->done = 0;
1307 1.1 pk if (iorq->xy) {
1308 1.1 pk iopb->unit = iorq->xy->xy_drive;
1309 1.1 pk iopb->dt = iorq->xy->drive_type;
1310 1.1 pk } else {
1311 1.1 pk iopb->unit = 0;
1312 1.1 pk iopb->dt = 0;
1313 1.1 pk }
1314 1.1 pk block = iorq->blockno;
1315 1.1 pk if (iorq->xy == NULL || block == 0) {
1316 1.1 pk iopb->sect = iopb->head = iopb->cyl = 0;
1317 1.1 pk } else {
1318 1.1 pk iopb->sect = block % iorq->xy->nsect;
1319 1.1 pk block = block / iorq->xy->nsect;
1320 1.1 pk iopb->head = block % iorq->xy->nhead;
1321 1.1 pk block = block / iorq->xy->nhead;
1322 1.1 pk iopb->cyl = block;
1323 1.1 pk }
1324 1.1 pk iopb->scnt = iorq->sectcnt;
1325 1.2 pk dp = (u_long) iorq->dbuf;
1326 1.1 pk if (iorq->dbuf == NULL) {
1327 1.1 pk iopb->dataa = 0;
1328 1.1 pk iopb->datar = 0;
1329 1.1 pk } else {
1330 1.1 pk iopb->dataa = (dp & 0xffff);
1331 1.1 pk iopb->datar = ((dp & 0xff0000) >> 16);
1332 1.1 pk }
1333 1.1 pk iopb->subfn = subfun;
1334 1.1 pk }
1335 1.1 pk
1336 1.1 pk
1337 1.1 pk /*
1338 1.1 pk * xyc_unbusy: wait for the xyc to go unbusy, or timeout.
1339 1.1 pk */
1340 1.1 pk
1341 1.1 pk int
1342 1.92 matt xyc_unbusy(struct xyc *xyc, int del)
1343 1.1 pk {
1344 1.1 pk while (del-- > 0) {
1345 1.1 pk if ((xyc->xyc_csr & XYC_GBSY) == 0)
1346 1.1 pk break;
1347 1.1 pk DELAY(1);
1348 1.1 pk }
1349 1.1 pk return(del == 0 ? XY_ERR_FAIL : XY_ERR_AOK);
1350 1.1 pk }
1351 1.1 pk
1352 1.1 pk /*
1353 1.1 pk * xyc_cmd: front end for POLL'd and WAIT'd commands. Returns 0 or error.
1354 1.36 wiz * note that NORM requests are handled separately.
1355 1.1 pk */
1356 1.1 pk int
1357 1.92 matt xyc_cmd(struct xyc_softc *xycsc, int cmd, int subfn, int unit, int block,
1358 1.92 matt int scnt, char *dptr, int fullmode)
1359 1.1 pk {
1360 1.1 pk int submode = XY_STATE(fullmode);
1361 1.1 pk struct xy_iorq *iorq = xycsc->ciorq;
1362 1.1 pk struct xy_iopb *iopb = xycsc->ciopb;
1363 1.1 pk
1364 1.1 pk /*
1365 1.1 pk * is someone else using the control iopq wait for it if we can
1366 1.1 pk */
1367 1.1 pk start:
1368 1.1 pk if (submode == XY_SUB_WAIT && XY_STATE(iorq->mode) != XY_SUB_FREE) {
1369 1.1 pk if (tsleep(iorq, PRIBIO, "xyc_cmd", 0))
1370 1.1 pk return(XY_ERR_FAIL);
1371 1.1 pk goto start;
1372 1.1 pk }
1373 1.1 pk
1374 1.1 pk if (XY_STATE(iorq->mode) != XY_SUB_FREE) {
1375 1.1 pk DELAY(1000000); /* XY_SUB_POLL: steal the iorq */
1376 1.1 pk iorq->mode = XY_SUB_FREE;
1377 1.93 chs printf("%s: stole control iopb\n", device_xname(xycsc->sc_dev));
1378 1.1 pk }
1379 1.1 pk
1380 1.1 pk /* init iorq/iopb */
1381 1.1 pk
1382 1.1 pk xyc_rqinit(iorq, xycsc,
1383 1.1 pk (unit == XYC_NOUNIT) ? NULL : xycsc->sc_drives[unit],
1384 1.1 pk fullmode, block, scnt, dptr, NULL);
1385 1.1 pk
1386 1.1 pk /* load IOPB from iorq */
1387 1.1 pk
1388 1.1 pk xyc_rqtopb(iorq, iopb, cmd, subfn);
1389 1.1 pk
1390 1.1 pk /* submit it for processing */
1391 1.1 pk
1392 1.1 pk xyc_submit_iorq(xycsc, iorq, fullmode); /* error code will be in iorq */
1393 1.1 pk
1394 1.1 pk return(XY_ERR_AOK);
1395 1.1 pk }
1396 1.1 pk
1397 1.1 pk /*
1398 1.1 pk * xyc_startbuf
1399 1.1 pk * start a buffer for running
1400 1.1 pk */
1401 1.1 pk
1402 1.1 pk int
1403 1.92 matt xyc_startbuf(struct xyc_softc *xycsc, struct xy_softc *xysc, struct buf *bp)
1404 1.1 pk {
1405 1.94 mrg #ifdef XYC_DEBUG
1406 1.94 mrg int partno;
1407 1.94 mrg #endif
1408 1.94 mrg int error;
1409 1.1 pk struct xy_iorq *iorq;
1410 1.1 pk struct xy_iopb *iopb;
1411 1.1 pk u_long block;
1412 1.1 pk
1413 1.1 pk iorq = xysc->xyrq;
1414 1.1 pk iopb = iorq->iopb;
1415 1.1 pk
1416 1.1 pk /* get buf */
1417 1.1 pk
1418 1.1 pk if (bp == NULL)
1419 1.1 pk panic("xyc_startbuf null buf");
1420 1.1 pk
1421 1.94 mrg #ifdef XYC_DEBUG
1422 1.1 pk partno = DISKPART(bp->b_dev);
1423 1.93 chs printf("xyc_startbuf: %s%c: %s block %d\n", device_xname(xysc->sc_dev),
1424 1.1 pk 'a' + partno, (bp->b_flags & B_READ) ? "read" : "write", bp->b_blkno);
1425 1.1 pk printf("xyc_startbuf: b_bcount %d, b_data 0x%x\n",
1426 1.1 pk bp->b_bcount, bp->b_data);
1427 1.1 pk #endif
1428 1.1 pk
1429 1.1 pk /*
1430 1.16 thorpej * load request.
1431 1.1 pk *
1432 1.1 pk * note that iorq points to the buffer as mapped into DVMA space,
1433 1.1 pk * where as the bp->b_data points to its non-DVMA mapping.
1434 1.1 pk */
1435 1.1 pk
1436 1.16 thorpej block = bp->b_rawblkno;
1437 1.1 pk
1438 1.2 pk error = bus_dmamap_load(xycsc->dmatag, iorq->dmamap,
1439 1.2 pk bp->b_data, bp->b_bcount, 0, BUS_DMA_NOWAIT);
1440 1.10 pk if (error != 0) {
1441 1.93 chs aprint_error_dev(xycsc->sc_dev, "warning: cannot load DMA map\n");
1442 1.1 pk return (XY_ERR_FAIL); /* XXX: need some sort of
1443 1.1 pk * call-back scheme here? */
1444 1.1 pk }
1445 1.1 pk
1446 1.7 thorpej bus_dmamap_sync(xycsc->dmatag, iorq->dmamap, 0,
1447 1.7 thorpej iorq->dmamap->dm_mapsize, (bp->b_flags & B_READ)
1448 1.2 pk ? BUS_DMASYNC_PREREAD
1449 1.2 pk : BUS_DMASYNC_PREWRITE);
1450 1.2 pk
1451 1.1 pk /* init iorq and load iopb from it */
1452 1.1 pk xyc_rqinit(iorq, xycsc, xysc, XY_SUB_NORM | XY_MODE_VERBO, block,
1453 1.2 pk bp->b_bcount / XYFM_BPS,
1454 1.69 christos (void *)(u_long)iorq->dmamap->dm_segs[0].ds_addr,
1455 1.2 pk bp);
1456 1.1 pk
1457 1.1 pk xyc_rqtopb(iorq, iopb, (bp->b_flags & B_READ) ? XYCMD_RD : XYCMD_WR, 0);
1458 1.1 pk
1459 1.1 pk /* Instrumentation. */
1460 1.1 pk disk_busy(&xysc->sc_dk);
1461 1.1 pk
1462 1.1 pk return (XY_ERR_AOK);
1463 1.1 pk }
1464 1.1 pk
1465 1.1 pk
1466 1.1 pk /*
1467 1.1 pk * xyc_submit_iorq: submit an iorq for processing. returns XY_ERR_AOK
1468 1.1 pk * if ok. if it fail returns an error code. type is XY_SUB_*.
1469 1.1 pk *
1470 1.1 pk * note: caller frees iorq in all cases except NORM
1471 1.1 pk *
1472 1.1 pk * return value:
1473 1.1 pk * NORM: XY_AOK (req pending), XY_FAIL (couldn't submit request)
1474 1.1 pk * WAIT: XY_AOK (success), <error-code> (failed)
1475 1.1 pk * POLL: <same as WAIT>
1476 1.1 pk * NOQ : <same as NORM>
1477 1.1 pk *
1478 1.1 pk * there are three sources for i/o requests:
1479 1.1 pk * [1] xystrategy: normal block I/O, using "struct buf" system.
1480 1.1 pk * [2] autoconfig/crash dump: these are polled I/O requests, no interrupts.
1481 1.1 pk * [3] open/ioctl: these are I/O requests done in the context of a process,
1482 1.1 pk * and the process should block until they are done.
1483 1.1 pk *
1484 1.1 pk * software state is stored in the iorq structure. each iorq has an
1485 1.1 pk * iopb structure. the hardware understands the iopb structure.
1486 1.1 pk * every command must go through an iopb. a 450 handles one iopb at a
1487 1.1 pk * time, where as a 451 can take them in chains. [the 450 claims it
1488 1.1 pk * can handle chains, but is appears to be buggy...] iopb are allocated
1489 1.1 pk * in DVMA space at boot up time. each disk gets one iopb, and the
1490 1.1 pk * controller gets one (for POLL and WAIT commands). what happens if
1491 1.1 pk * the iopb is busy? for i/o type [1], the buffers are queued at the
1492 1.1 pk * "buff" layer and * picked up later by the interrupt routine. for case
1493 1.1 pk * [2] we can only be blocked if there is a WAIT type I/O request being
1494 1.1 pk * run. since this can only happen when we are crashing, we wait a sec
1495 1.1 pk * and then steal the IOPB. for case [3] the process can sleep
1496 1.54 wiz * on the iorq free list until some iopbs are available.
1497 1.1 pk */
1498 1.1 pk
1499 1.1 pk
1500 1.1 pk int
1501 1.92 matt xyc_submit_iorq(struct xyc_softc *xycsc, struct xy_iorq *iorq, int type)
1502 1.1 pk {
1503 1.10 pk struct xy_iopb *dmaiopb;
1504 1.1 pk
1505 1.1 pk #ifdef XYC_DEBUG
1506 1.1 pk printf("xyc_submit_iorq(%s, addr=0x%x, type=%d)\n",
1507 1.93 chs device_xname(xycsc->sc_dev), iorq, type);
1508 1.1 pk #endif
1509 1.1 pk
1510 1.1 pk /* first check and see if controller is busy */
1511 1.1 pk if ((xycsc->xyc->xyc_csr & XYC_GBSY) != 0) {
1512 1.1 pk #ifdef XYC_DEBUG
1513 1.1 pk printf("xyc_submit_iorq: XYC not ready (BUSY)\n");
1514 1.1 pk #endif
1515 1.1 pk if (type == XY_SUB_NOQ)
1516 1.1 pk return (XY_ERR_FAIL); /* failed */
1517 1.1 pk switch (type) {
1518 1.1 pk case XY_SUB_NORM:
1519 1.1 pk return XY_ERR_AOK; /* success */
1520 1.1 pk case XY_SUB_WAIT:
1521 1.1 pk while (iorq->iopb->done == 0) {
1522 1.23 thorpej (void) tsleep(iorq, PRIBIO, "xyciorq", 0);
1523 1.1 pk }
1524 1.67 christos return (iorq->errnum);
1525 1.1 pk case XY_SUB_POLL: /* steal controller */
1526 1.10 pk (void)xycsc->xyc->xyc_rsetup; /* RESET */
1527 1.1 pk if (xyc_unbusy(xycsc->xyc,XYC_RESETUSEC) == XY_ERR_FAIL)
1528 1.1 pk panic("xyc_submit_iorq: stuck xyc");
1529 1.1 pk printf("%s: stole controller\n",
1530 1.93 chs device_xname(xycsc->sc_dev));
1531 1.1 pk break;
1532 1.1 pk default:
1533 1.1 pk panic("xyc_submit_iorq adding");
1534 1.1 pk }
1535 1.1 pk }
1536 1.1 pk
1537 1.10 pk dmaiopb = xyc_chain(xycsc, iorq); /* build chain */
1538 1.10 pk if (dmaiopb == NULL) { /* nothing doing? */
1539 1.1 pk if (type == XY_SUB_NORM || type == XY_SUB_NOQ)
1540 1.1 pk return(XY_ERR_AOK);
1541 1.42 provos panic("xyc_submit_iorq: xyc_chain failed!");
1542 1.1 pk }
1543 1.1 pk
1544 1.63 skrll XYC_GO(xycsc->xyc, dmaiopb);
1545 1.1 pk
1546 1.1 pk /* command now running, wrap it up */
1547 1.1 pk switch (type) {
1548 1.1 pk case XY_SUB_NORM:
1549 1.1 pk case XY_SUB_NOQ:
1550 1.1 pk return (XY_ERR_AOK); /* success */
1551 1.1 pk case XY_SUB_WAIT:
1552 1.1 pk while (iorq->iopb->done == 0) {
1553 1.23 thorpej (void) tsleep(iorq, PRIBIO, "xyciorq", 0);
1554 1.1 pk }
1555 1.67 christos return (iorq->errnum);
1556 1.1 pk case XY_SUB_POLL:
1557 1.1 pk return (xyc_piodriver(xycsc, iorq));
1558 1.1 pk default:
1559 1.1 pk panic("xyc_submit_iorq wrap up");
1560 1.1 pk }
1561 1.1 pk panic("xyc_submit_iorq");
1562 1.1 pk return 0; /* not reached */
1563 1.1 pk }
1564 1.1 pk
1565 1.1 pk
1566 1.1 pk /*
1567 1.1 pk * xyc_chain: build a chain. return dvma address of first element in
1568 1.1 pk * the chain. iorq != NULL: means we only want that item on the chain.
1569 1.1 pk */
1570 1.1 pk
1571 1.1 pk struct xy_iopb *
1572 1.92 matt xyc_chain(struct xyc_softc *xycsc, struct xy_iorq *iorq)
1573 1.10 pk {
1574 1.10 pk int togo, chain, hand;
1575 1.10 pk
1576 1.86 cegger memset(xycsc->xy_chain, 0, sizeof(xycsc->xy_chain));
1577 1.10 pk
1578 1.10 pk /*
1579 1.10 pk * promote control IOPB to the top
1580 1.10 pk */
1581 1.10 pk if (iorq == NULL) {
1582 1.10 pk if ((XY_STATE(xycsc->reqs[XYC_CTLIOPB].mode) == XY_SUB_POLL ||
1583 1.10 pk XY_STATE(xycsc->reqs[XYC_CTLIOPB].mode) == XY_SUB_WAIT) &&
1584 1.10 pk xycsc->iopbase[XYC_CTLIOPB].done == 0)
1585 1.10 pk iorq = &xycsc->reqs[XYC_CTLIOPB];
1586 1.10 pk }
1587 1.10 pk
1588 1.10 pk /*
1589 1.10 pk * special case: if iorq != NULL then we have a POLL or WAIT request.
1590 1.10 pk * we let these take priority and do them first.
1591 1.10 pk */
1592 1.10 pk if (iorq) {
1593 1.10 pk xycsc->xy_chain[0] = iorq;
1594 1.10 pk iorq->iopb->chen = 0;
1595 1.10 pk return(iorq->dmaiopb);
1596 1.10 pk }
1597 1.1 pk
1598 1.10 pk /*
1599 1.10 pk * NORM case: do round robin and maybe chain (if allowed and possible)
1600 1.10 pk */
1601 1.10 pk chain = 0;
1602 1.10 pk hand = xycsc->xy_hand;
1603 1.10 pk xycsc->xy_hand = (xycsc->xy_hand + 1) % XYC_MAXIOPB;
1604 1.10 pk
1605 1.10 pk for (togo = XYC_MAXIOPB; togo > 0;
1606 1.10 pk togo--, hand = (hand + 1) % XYC_MAXIOPB) {
1607 1.10 pk struct xy_iopb *iopb, *prev_iopb, *dmaiopb;
1608 1.10 pk
1609 1.10 pk if (XY_STATE(xycsc->reqs[hand].mode) != XY_SUB_NORM ||
1610 1.10 pk xycsc->iopbase[hand].done)
1611 1.10 pk continue; /* not ready-for-i/o */
1612 1.10 pk
1613 1.10 pk xycsc->xy_chain[chain] = &xycsc->reqs[hand];
1614 1.10 pk iopb = xycsc->xy_chain[chain]->iopb;
1615 1.10 pk iopb->chen = 0;
1616 1.10 pk if (chain != 0) {
1617 1.10 pk /* adding a link to a chain */
1618 1.10 pk prev_iopb = xycsc->xy_chain[chain-1]->iopb;
1619 1.10 pk prev_iopb->chen = 1;
1620 1.10 pk dmaiopb = xycsc->xy_chain[chain]->dmaiopb;
1621 1.10 pk prev_iopb->nxtiopb = ((u_long)dmaiopb) & 0xffff;
1622 1.10 pk } else {
1623 1.10 pk /* head of chain */
1624 1.10 pk iorq = xycsc->xy_chain[chain];
1625 1.10 pk }
1626 1.10 pk chain++;
1627 1.10 pk
1628 1.10 pk /* quit if chaining dis-allowed */
1629 1.10 pk if (xycsc->no_ols)
1630 1.10 pk break;
1631 1.10 pk }
1632 1.1 pk
1633 1.10 pk return(iorq ? iorq->dmaiopb : NULL);
1634 1.1 pk }
1635 1.1 pk
1636 1.1 pk /*
1637 1.1 pk * xyc_piodriver
1638 1.1 pk *
1639 1.1 pk * programmed i/o driver. this function takes over the computer
1640 1.1 pk * and drains off the polled i/o request. it returns the status of the iorq
1641 1.1 pk * the caller is interesting in.
1642 1.1 pk */
1643 1.1 pk int
1644 1.92 matt xyc_piodriver(struct xyc_softc *xycsc, struct xy_iorq *iorq)
1645 1.1 pk {
1646 1.1 pk int nreset = 0;
1647 1.1 pk int retval = 0;
1648 1.1 pk u_long res;
1649 1.1 pk #ifdef XYC_DEBUG
1650 1.93 chs printf("xyc_piodriver(%s, 0x%x)\n", device_xname(xycsc->sc_dev), iorq);
1651 1.1 pk #endif
1652 1.1 pk
1653 1.1 pk while (iorq->iopb->done == 0) {
1654 1.1 pk
1655 1.1 pk res = xyc_unbusy(xycsc->xyc, XYC_MAXTIME);
1656 1.1 pk
1657 1.1 pk /* we expect some progress soon */
1658 1.1 pk if (res == XY_ERR_FAIL && nreset >= 2) {
1659 1.1 pk xyc_reset(xycsc, 0, XY_RSET_ALL, XY_ERR_FAIL, 0);
1660 1.1 pk #ifdef XYC_DEBUG
1661 1.1 pk printf("xyc_piodriver: timeout\n");
1662 1.1 pk #endif
1663 1.1 pk return (XY_ERR_FAIL);
1664 1.1 pk }
1665 1.1 pk if (res == XY_ERR_FAIL) {
1666 1.1 pk if (xyc_reset(xycsc, 0,
1667 1.1 pk (nreset++ == 0) ? XY_RSET_NONE : iorq,
1668 1.1 pk XY_ERR_FAIL,
1669 1.1 pk 0) == XY_ERR_FAIL)
1670 1.1 pk return (XY_ERR_FAIL); /* flushes all but POLL
1671 1.1 pk * requests, resets */
1672 1.1 pk continue;
1673 1.1 pk }
1674 1.1 pk
1675 1.1 pk xyc_remove_iorq(xycsc); /* may resubmit request */
1676 1.1 pk
1677 1.1 pk if (iorq->iopb->done == 0)
1678 1.1 pk xyc_start(xycsc, iorq);
1679 1.1 pk }
1680 1.1 pk
1681 1.1 pk /* get return value */
1682 1.1 pk
1683 1.67 christos retval = iorq->errnum;
1684 1.1 pk
1685 1.1 pk #ifdef XYC_DEBUG
1686 1.1 pk printf("xyc_piodriver: done, retval = 0x%x (%s)\n",
1687 1.67 christos iorq->errnum, xyc_e2str(iorq->errnum));
1688 1.1 pk #endif
1689 1.1 pk
1690 1.1 pk /* start up any bufs that have queued */
1691 1.1 pk
1692 1.1 pk xyc_start(xycsc, NULL);
1693 1.1 pk
1694 1.1 pk return (retval);
1695 1.1 pk }
1696 1.1 pk
1697 1.1 pk /*
1698 1.1 pk * xyc_xyreset: reset one drive. NOTE: assumes xyc was just reset.
1699 1.1 pk * we steal iopb[XYC_CTLIOPB] for this, but we put it back when we are done.
1700 1.1 pk */
1701 1.1 pk void
1702 1.92 matt xyc_xyreset(struct xyc_softc *xycsc, struct xy_softc *xysc)
1703 1.1 pk {
1704 1.1 pk struct xy_iopb tmpiopb;
1705 1.10 pk struct xy_iopb *iopb;
1706 1.1 pk int del;
1707 1.1 pk
1708 1.10 pk iopb = xycsc->ciopb;
1709 1.10 pk
1710 1.10 pk /* Save contents */
1711 1.88 tsutsui memcpy(&tmpiopb, iopb, sizeof(struct xy_iopb));
1712 1.10 pk
1713 1.10 pk iopb->chen = iopb->done = iopb->errs = 0;
1714 1.10 pk iopb->ien = 0;
1715 1.10 pk iopb->com = XYCMD_RST;
1716 1.10 pk iopb->unit = xysc->xy_drive;
1717 1.10 pk
1718 1.63 skrll XYC_GO(xycsc->xyc, xycsc->ciorq->dmaiopb);
1719 1.1 pk
1720 1.1 pk del = XYC_RESETUSEC;
1721 1.1 pk while (del > 0) {
1722 1.10 pk if ((xycsc->xyc->xyc_csr & XYC_GBSY) == 0)
1723 1.10 pk break;
1724 1.1 pk DELAY(1);
1725 1.1 pk del--;
1726 1.1 pk }
1727 1.1 pk
1728 1.10 pk if (del <= 0 || iopb->errs) {
1729 1.93 chs printf("%s: off-line: %s\n", device_xname(xycsc->sc_dev),
1730 1.67 christos xyc_e2str(iopb->errnum));
1731 1.1 pk del = xycsc->xyc->xyc_rsetup;
1732 1.1 pk if (xyc_unbusy(xycsc->xyc, XYC_RESETUSEC) == XY_ERR_FAIL)
1733 1.1 pk panic("xyc_reset");
1734 1.1 pk } else {
1735 1.1 pk xycsc->xyc->xyc_csr = XYC_IPND; /* clear IPND */
1736 1.1 pk }
1737 1.10 pk
1738 1.10 pk /* Restore contents */
1739 1.88 tsutsui memcpy(iopb, &tmpiopb, sizeof(struct xy_iopb));
1740 1.1 pk }
1741 1.1 pk
1742 1.1 pk
1743 1.1 pk /*
1744 1.1 pk * xyc_reset: reset everything: requests are marked as errors except
1745 1.1 pk * a polled request (which is resubmitted)
1746 1.1 pk */
1747 1.1 pk int
1748 1.92 matt xyc_reset(struct xyc_softc *xycsc, int quiet, struct xy_iorq *blastmode,
1749 1.92 matt int error, struct xy_softc *xysc)
1750 1.1 pk {
1751 1.1 pk int del = 0, lcv, retval = XY_ERR_AOK;
1752 1.1 pk
1753 1.1 pk /* soft reset hardware */
1754 1.1 pk
1755 1.1 pk if (!quiet)
1756 1.93 chs printf("%s: soft reset\n", device_xname(xycsc->sc_dev));
1757 1.1 pk del = xycsc->xyc->xyc_rsetup;
1758 1.1 pk del = xyc_unbusy(xycsc->xyc, XYC_RESETUSEC);
1759 1.1 pk if (del == XY_ERR_FAIL) {
1760 1.1 pk blastmode = XY_RSET_ALL; /* dead, flush all requests */
1761 1.1 pk retval = XY_ERR_FAIL;
1762 1.1 pk }
1763 1.1 pk if (xysc)
1764 1.1 pk xyc_xyreset(xycsc, xysc);
1765 1.1 pk
1766 1.1 pk /* fix queues based on "blast-mode" */
1767 1.1 pk
1768 1.1 pk for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) {
1769 1.1 pk register struct xy_iorq *iorq = &xycsc->reqs[lcv];
1770 1.1 pk
1771 1.1 pk if (XY_STATE(iorq->mode) != XY_SUB_POLL &&
1772 1.1 pk XY_STATE(iorq->mode) != XY_SUB_WAIT &&
1773 1.1 pk XY_STATE(iorq->mode) != XY_SUB_NORM)
1774 1.1 pk /* is it active? */
1775 1.1 pk continue;
1776 1.1 pk
1777 1.1 pk if (blastmode == XY_RSET_ALL ||
1778 1.1 pk blastmode != iorq) {
1779 1.1 pk /* failed */
1780 1.67 christos iorq->errnum = error;
1781 1.1 pk xycsc->iopbase[lcv].done = xycsc->iopbase[lcv].errs = 1;
1782 1.1 pk switch (XY_STATE(iorq->mode)) {
1783 1.1 pk case XY_SUB_NORM:
1784 1.1 pk iorq->buf->b_error = EIO;
1785 1.1 pk iorq->buf->b_resid = iorq->sectcnt * XYFM_BPS;
1786 1.2 pk
1787 1.7 thorpej bus_dmamap_sync(xycsc->dmatag, iorq->dmamap, 0,
1788 1.7 thorpej iorq->dmamap->dm_mapsize,
1789 1.2 pk (iorq->buf->b_flags & B_READ)
1790 1.2 pk ? BUS_DMASYNC_POSTREAD
1791 1.2 pk : BUS_DMASYNC_POSTWRITE);
1792 1.58 perry
1793 1.2 pk bus_dmamap_unload(xycsc->dmatag, iorq->dmamap);
1794 1.2 pk
1795 1.83 yamt (void)bufq_get(iorq->xy->xyq);
1796 1.1 pk disk_unbusy(&xycsc->reqs[lcv].xy->sc_dk,
1797 1.1 pk (xycsc->reqs[lcv].buf->b_bcount -
1798 1.47 mrg xycsc->reqs[lcv].buf->b_resid),
1799 1.47 mrg (xycsc->reqs[lcv].buf->b_flags & B_READ));
1800 1.1 pk biodone(iorq->buf);
1801 1.1 pk iorq->mode = XY_SUB_FREE;
1802 1.1 pk break;
1803 1.1 pk case XY_SUB_WAIT:
1804 1.1 pk wakeup(iorq);
1805 1.1 pk case XY_SUB_POLL:
1806 1.1 pk iorq->mode =
1807 1.1 pk XY_NEWSTATE(iorq->mode, XY_SUB_DONE);
1808 1.1 pk break;
1809 1.1 pk }
1810 1.1 pk
1811 1.1 pk } else {
1812 1.1 pk
1813 1.1 pk /* resubmit, no need to do anything here */
1814 1.1 pk }
1815 1.1 pk }
1816 1.1 pk
1817 1.1 pk /*
1818 1.1 pk * now, if stuff is waiting, start it.
1819 1.1 pk * since we just reset it should go
1820 1.1 pk */
1821 1.1 pk xyc_start(xycsc, NULL);
1822 1.1 pk
1823 1.1 pk return (retval);
1824 1.1 pk }
1825 1.1 pk
1826 1.1 pk /*
1827 1.1 pk * xyc_start: start waiting buffers
1828 1.1 pk */
1829 1.1 pk
1830 1.1 pk void
1831 1.92 matt xyc_start(struct xyc_softc *xycsc, struct xy_iorq *iorq)
1832 1.1 pk {
1833 1.1 pk int lcv;
1834 1.1 pk struct xy_softc *xy;
1835 1.1 pk
1836 1.1 pk if (iorq == NULL) {
1837 1.1 pk for (lcv = 0; lcv < XYC_MAXDEV ; lcv++) {
1838 1.1 pk if ((xy = xycsc->sc_drives[lcv]) == NULL) continue;
1839 1.83 yamt if (bufq_peek(xy->xyq) == NULL) continue;
1840 1.1 pk if (xy->xyrq->mode != XY_SUB_FREE) continue;
1841 1.83 yamt xyc_startbuf(xycsc, xy, bufq_peek(xy->xyq));
1842 1.1 pk }
1843 1.1 pk }
1844 1.1 pk xyc_submit_iorq(xycsc, iorq, XY_SUB_NOQ);
1845 1.1 pk }
1846 1.1 pk
1847 1.1 pk /*
1848 1.1 pk * xyc_remove_iorq: remove "done" IOPB's.
1849 1.1 pk */
1850 1.1 pk
1851 1.1 pk int
1852 1.92 matt xyc_remove_iorq(struct xyc_softc *xycsc)
1853 1.1 pk {
1854 1.67 christos int errnum, rq, comm, errs;
1855 1.1 pk struct xyc *xyc = xycsc->xyc;
1856 1.1 pk u_long addr;
1857 1.1 pk struct xy_iopb *iopb;
1858 1.1 pk struct xy_iorq *iorq;
1859 1.1 pk struct buf *bp;
1860 1.1 pk
1861 1.1 pk if (xyc->xyc_csr & XYC_DERR) {
1862 1.1 pk /*
1863 1.1 pk * DOUBLE ERROR: should never happen under normal use. This
1864 1.1 pk * error is so bad, you can't even tell which IOPB is bad, so
1865 1.1 pk * we dump them all.
1866 1.1 pk */
1867 1.67 christos errnum = XY_ERR_DERR;
1868 1.93 chs aprint_error_dev(xycsc->sc_dev, "DOUBLE ERROR!\n");
1869 1.67 christos if (xyc_reset(xycsc, 0, XY_RSET_ALL, errnum, 0) != XY_ERR_AOK) {
1870 1.93 chs aprint_error_dev(xycsc->sc_dev, "soft reset failed!\n");
1871 1.1 pk panic("xyc_remove_iorq: controller DEAD");
1872 1.1 pk }
1873 1.1 pk return (XY_ERR_AOK);
1874 1.1 pk }
1875 1.1 pk
1876 1.1 pk /*
1877 1.1 pk * get iopb that is done, loop down the chain
1878 1.1 pk */
1879 1.1 pk
1880 1.1 pk if (xyc->xyc_csr & XYC_ERR) {
1881 1.1 pk xyc->xyc_csr = XYC_ERR; /* clear error condition */
1882 1.1 pk }
1883 1.1 pk if (xyc->xyc_csr & XYC_IPND) {
1884 1.1 pk xyc->xyc_csr = XYC_IPND; /* clear interrupt */
1885 1.1 pk }
1886 1.1 pk
1887 1.1 pk for (rq = 0; rq < XYC_MAXIOPB; rq++) {
1888 1.1 pk iorq = xycsc->xy_chain[rq];
1889 1.1 pk if (iorq == NULL) break; /* done ! */
1890 1.1 pk if (iorq->mode == 0 || XY_STATE(iorq->mode) == XY_SUB_DONE)
1891 1.1 pk continue; /* free, or done */
1892 1.1 pk iopb = iorq->iopb;
1893 1.1 pk if (iopb->done == 0)
1894 1.1 pk continue; /* not done yet */
1895 1.1 pk
1896 1.1 pk comm = iopb->com;
1897 1.1 pk errs = iopb->errs;
1898 1.1 pk
1899 1.1 pk if (errs)
1900 1.67 christos iorq->errnum = iopb->errnum;
1901 1.1 pk else
1902 1.67 christos iorq->errnum = 0;
1903 1.1 pk
1904 1.1 pk /* handle non-fatal errors */
1905 1.1 pk
1906 1.1 pk if (errs &&
1907 1.1 pk xyc_error(xycsc, iorq, iopb, comm) == XY_ERR_AOK)
1908 1.1 pk continue; /* AOK: we resubmitted it */
1909 1.1 pk
1910 1.1 pk
1911 1.1 pk /* this iorq is now done (hasn't been restarted or anything) */
1912 1.1 pk
1913 1.1 pk if ((iorq->mode & XY_MODE_VERBO) && iorq->lasterror)
1914 1.1 pk xyc_perror(iorq, iopb, 0);
1915 1.1 pk
1916 1.1 pk /* now, if read/write check to make sure we got all the data
1917 1.1 pk * we needed. (this may not be the case if we got an error in
1918 1.1 pk * the middle of a multisector request). */
1919 1.1 pk
1920 1.1 pk if ((iorq->mode & XY_MODE_B144) != 0 && errs == 0 &&
1921 1.1 pk (comm == XYCMD_RD || comm == XYCMD_WR)) {
1922 1.1 pk /* we just successfully processed a bad144 sector
1923 1.1 pk * note: if we are in bad 144 mode, the pointers have
1924 1.1 pk * been advanced already (see above) and are pointing
1925 1.1 pk * at the bad144 sector. to exit bad144 mode, we
1926 1.1 pk * must advance the pointers 1 sector and issue a new
1927 1.1 pk * request if there are still sectors left to process
1928 1.1 pk *
1929 1.1 pk */
1930 1.1 pk XYC_ADVANCE(iorq, 1); /* advance 1 sector */
1931 1.1 pk
1932 1.1 pk /* exit b144 mode */
1933 1.1 pk iorq->mode = iorq->mode & (~XY_MODE_B144);
1934 1.1 pk
1935 1.1 pk if (iorq->sectcnt) { /* more to go! */
1936 1.67 christos iorq->lasterror = iorq->errnum = iopb->errnum = 0;
1937 1.1 pk iopb->errs = iopb->done = 0;
1938 1.1 pk iorq->tries = 0;
1939 1.1 pk iopb->scnt = iorq->sectcnt;
1940 1.1 pk iopb->cyl = iorq->blockno /
1941 1.1 pk iorq->xy->sectpercyl;
1942 1.1 pk iopb->head =
1943 1.1 pk (iorq->blockno / iorq->xy->nhead) %
1944 1.1 pk iorq->xy->nhead;
1945 1.1 pk iopb->sect = iorq->blockno % XYFM_BPS;
1946 1.2 pk addr = (u_long) iorq->dbuf;
1947 1.1 pk iopb->dataa = (addr & 0xffff);
1948 1.1 pk iopb->datar = ((addr & 0xff0000) >> 16);
1949 1.1 pk /* will resubit at end */
1950 1.1 pk continue;
1951 1.1 pk }
1952 1.1 pk }
1953 1.1 pk /* final cleanup, totally done with this request */
1954 1.1 pk
1955 1.1 pk switch (XY_STATE(iorq->mode)) {
1956 1.1 pk case XY_SUB_NORM:
1957 1.1 pk bp = iorq->buf;
1958 1.1 pk if (errs) {
1959 1.1 pk bp->b_error = EIO;
1960 1.1 pk bp->b_resid = iorq->sectcnt * XYFM_BPS;
1961 1.1 pk } else {
1962 1.1 pk bp->b_resid = 0; /* done */
1963 1.1 pk }
1964 1.7 thorpej bus_dmamap_sync(xycsc->dmatag, iorq->dmamap, 0,
1965 1.7 thorpej iorq->dmamap->dm_mapsize,
1966 1.2 pk (iorq->buf->b_flags & B_READ)
1967 1.2 pk ? BUS_DMASYNC_POSTREAD
1968 1.2 pk : BUS_DMASYNC_POSTWRITE);
1969 1.58 perry
1970 1.2 pk bus_dmamap_unload(xycsc->dmatag, iorq->dmamap);
1971 1.2 pk
1972 1.83 yamt (void)bufq_get(iorq->xy->xyq);
1973 1.1 pk disk_unbusy(&iorq->xy->sc_dk,
1974 1.47 mrg (bp->b_bcount - bp->b_resid),
1975 1.47 mrg (bp->b_flags & B_READ));
1976 1.1 pk iorq->mode = XY_SUB_FREE;
1977 1.1 pk biodone(bp);
1978 1.1 pk break;
1979 1.1 pk case XY_SUB_WAIT:
1980 1.1 pk iorq->mode = XY_NEWSTATE(iorq->mode, XY_SUB_DONE);
1981 1.1 pk wakeup(iorq);
1982 1.1 pk break;
1983 1.1 pk case XY_SUB_POLL:
1984 1.1 pk iorq->mode = XY_NEWSTATE(iorq->mode, XY_SUB_DONE);
1985 1.1 pk break;
1986 1.1 pk }
1987 1.1 pk }
1988 1.1 pk
1989 1.1 pk return (XY_ERR_AOK);
1990 1.1 pk }
1991 1.1 pk
1992 1.1 pk /*
1993 1.1 pk * xyc_perror: print error.
1994 1.1 pk * - if still_trying is true: we got an error, retried and got a
1995 1.1 pk * different error. in that case lasterror is the old error,
1996 1.67 christos * and errnum is the new one.
1997 1.1 pk * - if still_trying is not true, then if we ever had an error it
1998 1.67 christos * is in lasterror. also, if iorq->errnum == 0, then we recovered
1999 1.67 christos * from that error (otherwise iorq->errnum == iorq->lasterror).
2000 1.1 pk */
2001 1.1 pk void
2002 1.92 matt xyc_perror(struct xy_iorq *iorq, struct xy_iopb *iopb, int still_trying)
2003 1.1 pk {
2004 1.1 pk
2005 1.1 pk int error = iorq->lasterror;
2006 1.1 pk
2007 1.93 chs printf("%s", (iorq->xy) ? device_xname(iorq->xy->sc_dev)
2008 1.93 chs : device_xname(iorq->xyc->sc_dev));
2009 1.1 pk if (iorq->buf)
2010 1.82 cegger printf("%c: ", 'a' + (char)DISKPART(iorq->buf->b_dev));
2011 1.1 pk if (iopb->com == XYCMD_RD || iopb->com == XYCMD_WR)
2012 1.1 pk printf("%s %d/%d/%d: ",
2013 1.1 pk (iopb->com == XYCMD_RD) ? "read" : "write",
2014 1.1 pk iopb->cyl, iopb->head, iopb->sect);
2015 1.1 pk printf("%s", xyc_e2str(error));
2016 1.1 pk
2017 1.1 pk if (still_trying)
2018 1.67 christos printf(" [still trying, new error=%s]", xyc_e2str(iorq->errnum));
2019 1.1 pk else
2020 1.67 christos if (iorq->errnum == 0)
2021 1.1 pk printf(" [recovered in %d tries]", iorq->tries);
2022 1.1 pk
2023 1.1 pk printf("\n");
2024 1.1 pk }
2025 1.1 pk
2026 1.1 pk /*
2027 1.1 pk * xyc_error: non-fatal error encountered... recover.
2028 1.1 pk * return AOK if resubmitted, return FAIL if this iopb is done
2029 1.1 pk */
2030 1.1 pk int
2031 1.92 matt xyc_error(struct xyc_softc *xycsc, struct xy_iorq *iorq, struct xy_iopb *iopb,
2032 1.92 matt int comm)
2033 1.1 pk {
2034 1.67 christos int errnum = iorq->errnum;
2035 1.67 christos int erract = xyc_entoact(errnum);
2036 1.12 drochner int oldmode, advance;
2037 1.18 chs #ifdef __sparc__
2038 1.12 drochner int i;
2039 1.12 drochner #endif
2040 1.1 pk
2041 1.1 pk if (erract == XY_ERA_RSET) { /* some errors require a reset */
2042 1.1 pk oldmode = iorq->mode;
2043 1.1 pk iorq->mode = XY_SUB_DONE | (~XY_SUB_MASK & oldmode);
2044 1.1 pk /* make xyc_start ignore us */
2045 1.67 christos xyc_reset(xycsc, 1, XY_RSET_NONE, errnum, iorq->xy);
2046 1.1 pk iorq->mode = oldmode;
2047 1.1 pk }
2048 1.1 pk /* check for read/write to a sector in bad144 table if bad: redirect
2049 1.1 pk * request to bad144 area */
2050 1.1 pk
2051 1.1 pk if ((comm == XYCMD_RD || comm == XYCMD_WR) &&
2052 1.1 pk (iorq->mode & XY_MODE_B144) == 0) {
2053 1.1 pk advance = iorq->sectcnt - iopb->scnt;
2054 1.1 pk XYC_ADVANCE(iorq, advance);
2055 1.18 chs #ifdef __sparc__
2056 1.1 pk if ((i = isbad(&iorq->xy->dkb, iorq->blockno / iorq->xy->sectpercyl,
2057 1.1 pk (iorq->blockno / iorq->xy->nsect) % iorq->xy->nhead,
2058 1.1 pk iorq->blockno % iorq->xy->nsect)) != -1) {
2059 1.1 pk iorq->mode |= XY_MODE_B144; /* enter bad144 mode &
2060 1.1 pk * redirect */
2061 1.67 christos iopb->errnum = iopb->done = iopb->errs = 0;
2062 1.1 pk iopb->scnt = 1;
2063 1.1 pk iopb->cyl = (iorq->xy->ncyl + iorq->xy->acyl) - 2;
2064 1.1 pk /* second to last acyl */
2065 1.1 pk i = iorq->xy->sectpercyl - 1 - i; /* follow bad144
2066 1.1 pk * standard */
2067 1.1 pk iopb->head = i / iorq->xy->nhead;
2068 1.1 pk iopb->sect = i % iorq->xy->nhead;
2069 1.1 pk /* will resubmit when we come out of remove_iorq */
2070 1.1 pk return (XY_ERR_AOK); /* recovered! */
2071 1.1 pk }
2072 1.12 drochner #endif
2073 1.1 pk }
2074 1.1 pk
2075 1.1 pk /*
2076 1.1 pk * it isn't a bad144 sector, must be real error! see if we can retry
2077 1.1 pk * it?
2078 1.1 pk */
2079 1.1 pk if ((iorq->mode & XY_MODE_VERBO) && iorq->lasterror)
2080 1.1 pk xyc_perror(iorq, iopb, 1); /* inform of error state
2081 1.1 pk * change */
2082 1.67 christos iorq->lasterror = errnum;
2083 1.1 pk
2084 1.1 pk if ((erract == XY_ERA_RSET || erract == XY_ERA_HARD)
2085 1.1 pk && iorq->tries < XYC_MAXTRIES) { /* retry? */
2086 1.1 pk iorq->tries++;
2087 1.67 christos iorq->errnum = iopb->errnum = iopb->done = iopb->errs = 0;
2088 1.1 pk /* will resubmit at end of remove_iorq */
2089 1.1 pk return (XY_ERR_AOK); /* recovered! */
2090 1.1 pk }
2091 1.1 pk
2092 1.1 pk /* failed to recover from this error */
2093 1.1 pk return (XY_ERR_FAIL);
2094 1.1 pk }
2095 1.1 pk
2096 1.1 pk /*
2097 1.1 pk * xyc_tick: make sure xy is still alive and ticking (err, kicking).
2098 1.1 pk */
2099 1.1 pk void
2100 1.92 matt xyc_tick(void *arg)
2101 1.1 pk {
2102 1.1 pk struct xyc_softc *xycsc = arg;
2103 1.1 pk int lcv, s, reset = 0;
2104 1.1 pk
2105 1.1 pk /* reduce ttl for each request if one goes to zero, reset xyc */
2106 1.1 pk s = splbio();
2107 1.1 pk for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) {
2108 1.1 pk if (xycsc->reqs[lcv].mode == 0 ||
2109 1.1 pk XY_STATE(xycsc->reqs[lcv].mode) == XY_SUB_DONE)
2110 1.1 pk continue;
2111 1.1 pk xycsc->reqs[lcv].ttl--;
2112 1.1 pk if (xycsc->reqs[lcv].ttl == 0)
2113 1.1 pk reset = 1;
2114 1.1 pk }
2115 1.1 pk if (reset) {
2116 1.93 chs printf("%s: watchdog timeout\n", device_xname(xycsc->sc_dev));
2117 1.1 pk xyc_reset(xycsc, 0, XY_RSET_NONE, XY_ERR_FAIL, NULL);
2118 1.1 pk }
2119 1.1 pk splx(s);
2120 1.1 pk
2121 1.1 pk /* until next time */
2122 1.1 pk
2123 1.17 thorpej callout_reset(&xycsc->sc_tick_ch, XYC_TICKCNT, xyc_tick, xycsc);
2124 1.1 pk }
2125 1.1 pk
2126 1.1 pk /*
2127 1.1 pk * xyc_ioctlcmd: this function provides a user level interface to the
2128 1.1 pk * controller via ioctl. this allows "format" programs to be written
2129 1.1 pk * in user code, and is also useful for some debugging. we return
2130 1.1 pk * an error code. called at user priority.
2131 1.1 pk *
2132 1.1 pk * XXX missing a few commands (see the 7053 driver for ideas)
2133 1.1 pk */
2134 1.1 pk int
2135 1.92 matt xyc_ioctlcmd(struct xy_softc *xy, dev_t dev, struct xd_iocmd *xio)
2136 1.1 pk {
2137 1.2 pk int s, rqno, dummy = 0;
2138 1.70 mrg char *dvmabuf = NULL, *buf = NULL;
2139 1.1 pk struct xyc_softc *xycsc;
2140 1.2 pk int rseg, error;
2141 1.2 pk bus_dma_segment_t seg;
2142 1.1 pk
2143 1.1 pk /* check sanity of requested command */
2144 1.1 pk
2145 1.1 pk switch (xio->cmd) {
2146 1.1 pk
2147 1.1 pk case XYCMD_NOP: /* no op: everything should be zero */
2148 1.1 pk if (xio->subfn || xio->dptr || xio->dlen ||
2149 1.1 pk xio->block || xio->sectcnt)
2150 1.1 pk return (EINVAL);
2151 1.1 pk break;
2152 1.1 pk
2153 1.1 pk case XYCMD_RD: /* read / write sectors (up to XD_IOCMD_MAXS) */
2154 1.1 pk case XYCMD_WR:
2155 1.1 pk if (xio->subfn || xio->sectcnt > XD_IOCMD_MAXS ||
2156 1.1 pk xio->sectcnt * XYFM_BPS != xio->dlen || xio->dptr == NULL)
2157 1.1 pk return (EINVAL);
2158 1.1 pk break;
2159 1.1 pk
2160 1.1 pk case XYCMD_SK: /* seek: doesn't seem useful to export this */
2161 1.1 pk return (EINVAL);
2162 1.1 pk
2163 1.1 pk break;
2164 1.1 pk
2165 1.1 pk default:
2166 1.1 pk return (EINVAL);/* ??? */
2167 1.1 pk }
2168 1.1 pk
2169 1.2 pk xycsc = xy->parent;
2170 1.2 pk
2171 1.1 pk /* create DVMA buffer for request if needed */
2172 1.2 pk if (xio->dlen) {
2173 1.52 mrg bus_addr_t busbuf;
2174 1.52 mrg
2175 1.19 pk if ((error = xy_dmamem_alloc(xycsc->dmatag, xycsc->auxmap,
2176 1.19 pk &seg, &rseg,
2177 1.70 mrg xio->dlen, (void **)&buf,
2178 1.52 mrg &busbuf)) != 0) {
2179 1.2 pk return (error);
2180 1.2 pk }
2181 1.69 christos dvmabuf = (void *)(u_long)BUS_ADDR_PADDR(busbuf);
2182 1.1 pk
2183 1.1 pk if (xio->cmd == XYCMD_WR) {
2184 1.2 pk if ((error = copyin(xio->dptr, buf, xio->dlen)) != 0) {
2185 1.2 pk bus_dmamem_unmap(xycsc->dmatag, buf, xio->dlen);
2186 1.2 pk bus_dmamem_free(xycsc->dmatag, &seg, rseg);
2187 1.2 pk return (error);
2188 1.1 pk }
2189 1.1 pk }
2190 1.1 pk }
2191 1.1 pk /* do it! */
2192 1.1 pk
2193 1.2 pk error = 0;
2194 1.1 pk s = splbio();
2195 1.1 pk rqno = xyc_cmd(xycsc, xio->cmd, xio->subfn, xy->xy_drive, xio->block,
2196 1.1 pk xio->sectcnt, dvmabuf, XY_SUB_WAIT);
2197 1.1 pk if (rqno == XY_ERR_FAIL) {
2198 1.2 pk error = EIO;
2199 1.1 pk goto done;
2200 1.1 pk }
2201 1.67 christos xio->errnum = xycsc->ciorq->errnum;
2202 1.1 pk xio->tries = xycsc->ciorq->tries;
2203 1.1 pk XYC_DONE(xycsc, dummy);
2204 1.1 pk
2205 1.1 pk if (xio->cmd == XYCMD_RD)
2206 1.2 pk error = copyout(buf, xio->dptr, xio->dlen);
2207 1.1 pk
2208 1.1 pk done:
2209 1.1 pk splx(s);
2210 1.2 pk if (dvmabuf) {
2211 1.19 pk xy_dmamem_free(xycsc->dmatag, xycsc->auxmap, &seg, rseg,
2212 1.19 pk xio->dlen, buf);
2213 1.2 pk }
2214 1.2 pk return (error);
2215 1.1 pk }
2216 1.1 pk
2217 1.1 pk /*
2218 1.1 pk * xyc_e2str: convert error code number into an error string
2219 1.1 pk */
2220 1.59 tsutsui const char *
2221 1.84 dsl xyc_e2str(int no)
2222 1.1 pk {
2223 1.1 pk switch (no) {
2224 1.1 pk case XY_ERR_FAIL:
2225 1.1 pk return ("Software fatal error");
2226 1.1 pk case XY_ERR_DERR:
2227 1.1 pk return ("DOUBLE ERROR");
2228 1.1 pk case XY_ERR_AOK:
2229 1.1 pk return ("Successful completion");
2230 1.1 pk case XY_ERR_IPEN:
2231 1.1 pk return("Interrupt pending");
2232 1.1 pk case XY_ERR_BCFL:
2233 1.1 pk return("Busy conflict");
2234 1.1 pk case XY_ERR_TIMO:
2235 1.1 pk return("Operation timeout");
2236 1.1 pk case XY_ERR_NHDR:
2237 1.1 pk return("Header not found");
2238 1.1 pk case XY_ERR_HARD:
2239 1.1 pk return("Hard ECC error");
2240 1.1 pk case XY_ERR_ICYL:
2241 1.1 pk return("Illegal cylinder address");
2242 1.1 pk case XY_ERR_ISEC:
2243 1.1 pk return("Illegal sector address");
2244 1.1 pk case XY_ERR_SMAL:
2245 1.1 pk return("Last sector too small");
2246 1.1 pk case XY_ERR_SACK:
2247 1.1 pk return("Slave ACK error (non-existent memory)");
2248 1.1 pk case XY_ERR_CHER:
2249 1.1 pk return("Cylinder and head/header error");
2250 1.1 pk case XY_ERR_SRTR:
2251 1.1 pk return("Auto-seek retry successful");
2252 1.1 pk case XY_ERR_WPRO:
2253 1.1 pk return("Write-protect error");
2254 1.1 pk case XY_ERR_UIMP:
2255 1.1 pk return("Unimplemented command");
2256 1.1 pk case XY_ERR_DNRY:
2257 1.1 pk return("Drive not ready");
2258 1.1 pk case XY_ERR_SZER:
2259 1.1 pk return("Sector count zero");
2260 1.1 pk case XY_ERR_DFLT:
2261 1.1 pk return("Drive faulted");
2262 1.1 pk case XY_ERR_ISSZ:
2263 1.1 pk return("Illegal sector size");
2264 1.1 pk case XY_ERR_SLTA:
2265 1.1 pk return("Self test A");
2266 1.1 pk case XY_ERR_SLTB:
2267 1.1 pk return("Self test B");
2268 1.1 pk case XY_ERR_SLTC:
2269 1.1 pk return("Self test C");
2270 1.1 pk case XY_ERR_SOFT:
2271 1.1 pk return("Soft ECC error");
2272 1.1 pk case XY_ERR_SFOK:
2273 1.1 pk return("Soft ECC error recovered");
2274 1.1 pk case XY_ERR_IHED:
2275 1.1 pk return("Illegal head");
2276 1.1 pk case XY_ERR_DSEQ:
2277 1.1 pk return("Disk sequencer error");
2278 1.1 pk case XY_ERR_SEEK:
2279 1.1 pk return("Seek error");
2280 1.1 pk default:
2281 1.1 pk return ("Unknown error");
2282 1.1 pk }
2283 1.1 pk }
2284 1.1 pk
2285 1.1 pk int
2286 1.92 matt xyc_entoact(int errnum)
2287 1.1 pk {
2288 1.67 christos switch (errnum) {
2289 1.1 pk case XY_ERR_FAIL: case XY_ERR_DERR: case XY_ERR_IPEN:
2290 1.1 pk case XY_ERR_BCFL: case XY_ERR_ICYL: case XY_ERR_ISEC:
2291 1.1 pk case XY_ERR_UIMP: case XY_ERR_SZER: case XY_ERR_ISSZ:
2292 1.1 pk case XY_ERR_SLTA: case XY_ERR_SLTB: case XY_ERR_SLTC:
2293 1.1 pk case XY_ERR_IHED: case XY_ERR_SACK: case XY_ERR_SMAL:
2294 1.1 pk
2295 1.1 pk return(XY_ERA_PROG); /* program error ! */
2296 1.1 pk
2297 1.1 pk case XY_ERR_TIMO: case XY_ERR_NHDR: case XY_ERR_HARD:
2298 1.1 pk case XY_ERR_DNRY: case XY_ERR_CHER: case XY_ERR_SEEK:
2299 1.1 pk case XY_ERR_SOFT:
2300 1.1 pk
2301 1.1 pk return(XY_ERA_HARD); /* hard error, retry */
2302 1.1 pk
2303 1.1 pk case XY_ERR_DFLT: case XY_ERR_DSEQ:
2304 1.1 pk
2305 1.1 pk return(XY_ERA_RSET); /* hard error reset */
2306 1.1 pk
2307 1.1 pk case XY_ERR_SRTR: case XY_ERR_SFOK: case XY_ERR_AOK:
2308 1.1 pk
2309 1.1 pk return(XY_ERA_SOFT); /* an FYI error */
2310 1.1 pk
2311 1.1 pk case XY_ERR_WPRO:
2312 1.1 pk
2313 1.1 pk return(XY_ERA_WPRO); /* write protect */
2314 1.1 pk }
2315 1.1 pk
2316 1.1 pk return(XY_ERA_PROG); /* ??? */
2317 1.1 pk }
2318