xd.c revision 1.40.8.1 1 /* $NetBSD: xd.c,v 1.40.8.1 2002/05/16 11:27:59 gehenna Exp $ */
2
3 /*
4 *
5 * Copyright (c) 1995 Charles D. Cranor
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Charles D. Cranor.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 *
36 * x d . c x y l o g i c s 7 5 3 / 7 0 5 3 v m e / s m d d r i v e r
37 *
38 * author: Chuck Cranor <chuck (at) ccrc.wustl.edu>
39 * started: 27-Feb-95
40 * references: [1] Xylogics Model 753 User's Manual
41 * part number: 166-753-001, Revision B, May 21, 1988.
42 * "Your Partner For Performance"
43 * [2] other NetBSD disk device drivers
44 *
45 * Special thanks go to Scott E. Campbell of Xylogics, Inc. for taking
46 * the time to answer some of my questions about the 753/7053.
47 *
48 * note: the 753 and the 7053 are programmed the same way, but are
49 * different sizes. the 753 is a 6U VME card, while the 7053 is a 9U
50 * VME card (found in many VME based suns).
51 */
52
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: xd.c,v 1.40.8.1 2002/05/16 11:27:59 gehenna Exp $");
55
56 #undef XDC_DEBUG /* full debug */
57 #define XDC_DIAG /* extra sanity checks */
58 #if defined(DIAGNOSTIC) && !defined(XDC_DIAG)
59 #define XDC_DIAG /* link in with master DIAG option */
60 #endif
61
62 #include <sys/param.h>
63 #include <sys/proc.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/file.h>
67 #include <sys/stat.h>
68 #include <sys/ioctl.h>
69 #include <sys/buf.h>
70 #include <sys/uio.h>
71 #include <sys/malloc.h>
72 #include <sys/device.h>
73 #include <sys/disklabel.h>
74 #include <sys/disk.h>
75 #include <sys/syslog.h>
76 #include <sys/dkbad.h>
77 #include <sys/conf.h>
78
79 #include <machine/bus.h>
80 #include <machine/intr.h>
81
82 #if defined(__sparc__) || defined(sun3)
83 #include <dev/sun/disklabel.h>
84 #endif
85
86 #include <dev/vme/vmereg.h>
87 #include <dev/vme/vmevar.h>
88
89 #include <dev/vme/xdreg.h>
90 #include <dev/vme/xdvar.h>
91 #include <dev/vme/xio.h>
92
93 #include "locators.h"
94
95 /*
96 * macros
97 */
98
99 /*
100 * XDC_TWAIT: add iorq "N" to tail of SC's wait queue
101 */
102 #define XDC_TWAIT(SC, N) { \
103 (SC)->waitq[(SC)->waitend] = (N); \
104 (SC)->waitend = ((SC)->waitend + 1) % XDC_MAXIOPB; \
105 (SC)->nwait++; \
106 }
107
108 /*
109 * XDC_HWAIT: add iorq "N" to head of SC's wait queue
110 */
111 #define XDC_HWAIT(SC, N) { \
112 (SC)->waithead = ((SC)->waithead == 0) ? \
113 (XDC_MAXIOPB - 1) : ((SC)->waithead - 1); \
114 (SC)->waitq[(SC)->waithead] = (N); \
115 (SC)->nwait++; \
116 }
117
118 /*
119 * XDC_GET_WAITER: gets the first request waiting on the waitq
120 * and removes it (so it can be submitted)
121 */
122 #define XDC_GET_WAITER(XDCSC, RQ) { \
123 (RQ) = (XDCSC)->waitq[(XDCSC)->waithead]; \
124 (XDCSC)->waithead = ((XDCSC)->waithead + 1) % XDC_MAXIOPB; \
125 xdcsc->nwait--; \
126 }
127
128 /*
129 * XDC_FREE: add iorq "N" to SC's free list
130 */
131 #define XDC_FREE(SC, N) { \
132 (SC)->freereq[(SC)->nfree++] = (N); \
133 (SC)->reqs[N].mode = 0; \
134 if ((SC)->nfree == 1) wakeup(&(SC)->nfree); \
135 }
136
137
138 /*
139 * XDC_RQALLOC: allocate an iorq off the free list (assume nfree > 0).
140 */
141 #define XDC_RQALLOC(XDCSC) (XDCSC)->freereq[--((XDCSC)->nfree)]
142
143 /*
144 * XDC_GO: start iopb ADDR (DVMA addr in a u_long) on XDC
145 */
146 #define XDC_GO(XDC, ADDR) { \
147 (XDC)->xdc_iopbaddr0 = ((ADDR) & 0xff); \
148 (ADDR) = ((ADDR) >> 8); \
149 (XDC)->xdc_iopbaddr1 = ((ADDR) & 0xff); \
150 (ADDR) = ((ADDR) >> 8); \
151 (XDC)->xdc_iopbaddr2 = ((ADDR) & 0xff); \
152 (ADDR) = ((ADDR) >> 8); \
153 (XDC)->xdc_iopbaddr3 = (ADDR); \
154 (XDC)->xdc_iopbamod = XDC_ADDRMOD; \
155 (XDC)->xdc_csr = XDC_ADDIOPB; /* go! */ \
156 }
157
158 /*
159 * XDC_WAIT: wait for XDC's csr "BITS" to come on in "TIME".
160 * LCV is a counter. If it goes to zero then we timed out.
161 */
162 #define XDC_WAIT(XDC, LCV, TIME, BITS) { \
163 (LCV) = (TIME); \
164 while ((LCV) > 0) { \
165 if ((XDC)->xdc_csr & (BITS)) break; \
166 (LCV) = (LCV) - 1; \
167 DELAY(1); \
168 } \
169 }
170
171 /*
172 * XDC_DONE: don't need IORQ, get error code and free (done after xdc_cmd)
173 */
174 #define XDC_DONE(SC,RQ,ER) { \
175 if ((RQ) == XD_ERR_FAIL) { \
176 (ER) = (RQ); \
177 } else { \
178 if ((SC)->ndone-- == XDC_SUBWAITLIM) \
179 wakeup(&(SC)->ndone); \
180 (ER) = (SC)->reqs[RQ].errno; \
181 XDC_FREE((SC), (RQ)); \
182 } \
183 }
184
185 /*
186 * XDC_ADVANCE: advance iorq's pointers by a number of sectors
187 */
188 #define XDC_ADVANCE(IORQ, N) { \
189 if (N) { \
190 (IORQ)->sectcnt -= (N); \
191 (IORQ)->blockno += (N); \
192 (IORQ)->dbuf += ((N)*XDFM_BPS); \
193 } \
194 }
195
196 /*
197 * note - addresses you can sleep on:
198 * [1] & of xd_softc's "state" (waiting for a chance to attach a drive)
199 * [2] & of xdc_softc's "nfree" (waiting for a free iorq/iopb)
200 * [3] & of xdc_softc's "ndone" (waiting for number of done iorq/iopb's
201 * to drop below XDC_SUBWAITLIM)
202 * [4] & an iorq (waiting for an XD_SUB_WAIT iorq to finish)
203 */
204
205
206 /*
207 * function prototypes
208 * "xdc_*" functions are internal, all others are external interfaces
209 */
210
211 extern int pil_to_vme[]; /* from obio.c */
212
213 /* internals */
214 int xdc_cmd __P((struct xdc_softc *, int, int, int, int, int, char *, int));
215 char *xdc_e2str __P((int));
216 int xdc_error __P((struct xdc_softc *, struct xd_iorq *,
217 struct xd_iopb *, int, int));
218 int xdc_ioctlcmd __P((struct xd_softc *, dev_t dev, struct xd_iocmd *));
219 void xdc_perror __P((struct xd_iorq *, struct xd_iopb *, int));
220 int xdc_piodriver __P((struct xdc_softc *, int, int));
221 int xdc_remove_iorq __P((struct xdc_softc *));
222 int xdc_reset __P((struct xdc_softc *, int, int, int, struct xd_softc *));
223 inline void xdc_rqinit __P((struct xd_iorq *, struct xdc_softc *,
224 struct xd_softc *, int, u_long, int,
225 caddr_t, struct buf *));
226 void xdc_rqtopb __P((struct xd_iorq *, struct xd_iopb *, int, int));
227 void xdc_start __P((struct xdc_softc *, int));
228 int xdc_startbuf __P((struct xdc_softc *, struct xd_softc *, struct buf *));
229 int xdc_submit_iorq __P((struct xdc_softc *, int, int));
230 void xdc_tick __P((void *));
231 void xdc_xdreset __P((struct xdc_softc *, struct xd_softc *));
232 int xd_dmamem_alloc(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
233 int *, bus_size_t, caddr_t *, bus_addr_t *);
234 void xd_dmamem_free(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
235 int, bus_size_t, caddr_t);
236
237
238 /* machine interrupt hook */
239 int xdcintr __P((void *));
240
241 /* autoconf */
242 int xdcmatch __P((struct device *, struct cfdata *, void *));
243 void xdcattach __P((struct device *, struct device *, void *));
244 int xdmatch __P((struct device *, struct cfdata *, void *));
245 void xdattach __P((struct device *, struct device *, void *));
246 static int xdc_probe __P((void *, bus_space_tag_t, bus_space_handle_t));
247
248 static void xddummystrat __P((struct buf *));
249 int xdgetdisklabel __P((struct xd_softc *, void *));
250
251 /* XXX - think about this more.. xd_machdep? */
252 void xdc_md_setup __P((void));
253 int XDC_DELAY;
254
255 #if defined(__sparc__)
256 #include <sparc/sparc/vaddrs.h>
257 #include <sparc/sparc/cpuvar.h>
258 void xdc_md_setup()
259 {
260 if (CPU_ISSUN4 && cpuinfo.cpu_type == CPUTYP_4_300)
261 XDC_DELAY = XDC_DELAY_4_300;
262 else
263 XDC_DELAY = XDC_DELAY_SPARC;
264 }
265 #elif defined(sun3)
266 void xdc_md_setup()
267 {
268 XDC_DELAY = XDC_DELAY_SUN3;
269 }
270 #else
271 void xdc_md_setup()
272 {
273 XDC_DELAY = 0;
274 }
275 #endif
276
277 /*
278 * cfattach's: device driver interface to autoconfig
279 */
280
281 struct cfattach xdc_ca = {
282 sizeof(struct xdc_softc), xdcmatch, xdcattach
283 };
284
285
286 struct cfattach xd_ca = {
287 sizeof(struct xd_softc), xdmatch, xdattach
288 };
289
290 extern struct cfdriver xd_cd;
291
292 dev_type_open(xdopen);
293 dev_type_close(xdclose);
294 dev_type_read(xdread);
295 dev_type_write(xdwrite);
296 dev_type_ioctl(xdioctl);
297 dev_type_strategy(xdstrategy);
298 dev_type_dump(xddump);
299 dev_type_size(xdsize);
300
301 const struct bdevsw xd_bdevsw = {
302 xdopen, xdclose, xdstrategy, xdioctl, xddump, xdsize, D_DISK
303 };
304
305 const struct cdevsw xd_cdevsw = {
306 xdopen, xdclose, xdread, xdwrite, xdioctl,
307 nostop, notty, nopoll, nommap, D_DISK
308 };
309
310 struct xdc_attach_args { /* this is the "aux" args to xdattach */
311 int driveno; /* unit number */
312 int fullmode; /* submit mode */
313 int booting; /* are we booting or not? */
314 };
315
316 /*
317 * dkdriver
318 */
319
320 struct dkdriver xddkdriver = {xdstrategy};
321
322 /*
323 * start: disk label fix code (XXX)
324 */
325
326 static void *xd_labeldata;
327
328 static void
329 xddummystrat(bp)
330 struct buf *bp;
331 {
332 if (bp->b_bcount != XDFM_BPS)
333 panic("xddummystrat");
334 bcopy(xd_labeldata, bp->b_data, XDFM_BPS);
335 bp->b_flags |= B_DONE;
336 bp->b_flags &= ~B_BUSY;
337 }
338
339 int
340 xdgetdisklabel(xd, b)
341 struct xd_softc *xd;
342 void *b;
343 {
344 char *err;
345 #if defined(__sparc__) || defined(sun3)
346 struct sun_disklabel *sdl;
347 #endif
348
349 /* We already have the label data in `b'; setup for dummy strategy */
350 xd_labeldata = b;
351
352 /* Required parameter for readdisklabel() */
353 xd->sc_dk.dk_label->d_secsize = XDFM_BPS;
354
355 err = readdisklabel(MAKEDISKDEV(0, xd->sc_dev.dv_unit, RAW_PART),
356 xddummystrat,
357 xd->sc_dk.dk_label, xd->sc_dk.dk_cpulabel);
358 if (err) {
359 printf("%s: %s\n", xd->sc_dev.dv_xname, err);
360 return(XD_ERR_FAIL);
361 }
362
363 #if defined(__sparc__) || defined(sun3)
364 /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */
365 sdl = (struct sun_disklabel *)xd->sc_dk.dk_cpulabel->cd_block;
366 if (sdl->sl_magic == SUN_DKMAGIC) {
367 xd->pcyl = sdl->sl_pcylinders;
368 } else
369 #endif
370 {
371 printf("%s: WARNING: no `pcyl' in disk label.\n",
372 xd->sc_dev.dv_xname);
373 xd->pcyl = xd->sc_dk.dk_label->d_ncylinders +
374 xd->sc_dk.dk_label->d_acylinders;
375 printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n",
376 xd->sc_dev.dv_xname, xd->pcyl);
377 }
378
379 xd->ncyl = xd->sc_dk.dk_label->d_ncylinders;
380 xd->acyl = xd->sc_dk.dk_label->d_acylinders;
381 xd->nhead = xd->sc_dk.dk_label->d_ntracks;
382 xd->nsect = xd->sc_dk.dk_label->d_nsectors;
383 xd->sectpercyl = xd->nhead * xd->nsect;
384 xd->sc_dk.dk_label->d_secsize = XDFM_BPS; /* not handled by
385 * sun->bsd */
386 return(XD_ERR_AOK);
387 }
388
389 /*
390 * end: disk label fix code (XXX)
391 */
392
393 /*
394 * Shorthand for allocating, mapping and loading a DMA buffer
395 */
396 int
397 xd_dmamem_alloc(tag, map, seg, nsegp, len, kvap, dmap)
398 bus_dma_tag_t tag;
399 bus_dmamap_t map;
400 bus_dma_segment_t *seg;
401 int *nsegp;
402 bus_size_t len;
403 caddr_t *kvap;
404 bus_addr_t *dmap;
405 {
406 int nseg;
407 int error;
408
409 if ((error = bus_dmamem_alloc(tag, len, 0, 0,
410 seg, 1, &nseg, BUS_DMA_NOWAIT)) != 0) {
411 return (error);
412 }
413
414 if ((error = bus_dmamem_map(tag, seg, nseg,
415 len, kvap,
416 BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
417 bus_dmamem_free(tag, seg, nseg);
418 return (error);
419 }
420
421 if ((error = bus_dmamap_load(tag, map,
422 *kvap, len, NULL,
423 BUS_DMA_NOWAIT)) != 0) {
424 bus_dmamem_unmap(tag, *kvap, len);
425 bus_dmamem_free(tag, seg, nseg);
426 return (error);
427 }
428
429 *dmap = map->dm_segs[0].ds_addr;
430 *nsegp = nseg;
431 return (0);
432 }
433
434 void
435 xd_dmamem_free(tag, map, seg, nseg, len, kva)
436 bus_dma_tag_t tag;
437 bus_dmamap_t map;
438 bus_dma_segment_t *seg;
439 int nseg;
440 bus_size_t len;
441 caddr_t kva;
442 {
443
444 bus_dmamap_unload(tag, map);
445 bus_dmamem_unmap(tag, kva, len);
446 bus_dmamem_free(tag, seg, nseg);
447 }
448
449
450 /*
451 * a u t o c o n f i g f u n c t i o n s
452 */
453
454 /*
455 * xdcmatch: determine if xdc is present or not. we do a
456 * soft reset to detect the xdc.
457 */
458
459 int
460 xdc_probe(arg, tag, handle)
461 void *arg;
462 bus_space_tag_t tag;
463 bus_space_handle_t handle;
464 {
465 struct xdc *xdc = (void *)handle; /* XXX */
466 int del = 0;
467
468 xdc->xdc_csr = XDC_RESET;
469 XDC_WAIT(xdc, del, XDC_RESETUSEC, XDC_RESET);
470 return (del > 0 ? 0 : EIO);
471 }
472
473 int xdcmatch(parent, cf, aux)
474 struct device *parent;
475 struct cfdata *cf;
476 void *aux;
477 {
478 struct vme_attach_args *va = aux;
479 vme_chipset_tag_t ct = va->va_vct;
480 vme_am_t mod;
481 int error;
482
483 mod = VME_AM_A16 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
484 if (vme_space_alloc(ct, va->r[0].offset, sizeof(struct xdc), mod))
485 return (0);
486
487 error = vme_probe(ct, va->r[0].offset, sizeof(struct xdc),
488 mod, VME_D32, xdc_probe, 0);
489 vme_space_free(va->va_vct, va->r[0].offset, sizeof(struct xdc), mod);
490
491 return (error == 0);
492 }
493
494 /*
495 * xdcattach: attach controller
496 */
497 void
498 xdcattach(parent, self, aux)
499 struct device *parent, *self;
500 void *aux;
501
502 {
503 struct vme_attach_args *va = aux;
504 vme_chipset_tag_t ct = va->va_vct;
505 bus_space_tag_t bt;
506 bus_space_handle_t bh;
507 vme_intr_handle_t ih;
508 vme_am_t mod;
509 struct xdc_softc *xdc = (void *) self;
510 struct xdc_attach_args xa;
511 int lcv, rqno, error;
512 struct xd_iopb_ctrl *ctl;
513 bus_dma_segment_t seg;
514 int rseg;
515 vme_mapresc_t resc;
516
517 xdc_md_setup();
518
519 /* get addressing and intr level stuff from autoconfig and load it
520 * into our xdc_softc. */
521
522 xdc->dmatag = va->va_bdt;
523 mod = VME_AM_A16 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
524
525 if (vme_space_alloc(ct, va->r[0].offset, sizeof(struct xdc), mod))
526 panic("xdc: vme alloc");
527
528 if (vme_space_map(ct, va->r[0].offset, sizeof(struct xdc),
529 mod, VME_D32, 0, &bt, &bh, &resc) != 0)
530 panic("xdc: vme_map");
531
532 xdc->xdc = (struct xdc *) bh; /* XXX */
533 xdc->ipl = va->ilevel;
534 xdc->vector = va->ivector;
535
536 for (lcv = 0; lcv < XDC_MAXDEV; lcv++)
537 xdc->sc_drives[lcv] = (struct xd_softc *) 0;
538
539 /*
540 * allocate and zero buffers
541 *
542 * note: we simplify the code by allocating the max number of iopbs and
543 * iorq's up front. thus, we avoid linked lists and the costs
544 * associated with them in exchange for wasting a little memory.
545 */
546
547 /* Get DMA handle for misc. transfers */
548 if ((error = vme_dmamap_create(
549 ct, /* VME chip tag */
550 MAXPHYS, /* size */
551 VME_AM_A24, /* address modifier */
552 VME_D32, /* data size */
553 0, /* swap */
554 1, /* nsegments */
555 MAXPHYS, /* maxsegsz */
556 0, /* boundary */
557 BUS_DMA_NOWAIT,
558 &xdc->auxmap)) != 0) {
559
560 printf("%s: DMA buffer map create error %d\n",
561 xdc->sc_dev.dv_xname, error);
562 return;
563 }
564
565
566 /* Get DMA handle for mapping iorq descriptors */
567 if ((error = vme_dmamap_create(
568 ct, /* VME chip tag */
569 XDC_MAXIOPB * sizeof(struct xd_iopb),
570 VME_AM_A24, /* address modifier */
571 VME_D32, /* data size */
572 0, /* swap */
573 1, /* nsegments */
574 XDC_MAXIOPB * sizeof(struct xd_iopb),
575 0, /* boundary */
576 BUS_DMA_NOWAIT,
577 &xdc->iopmap)) != 0) {
578
579 printf("%s: DMA buffer map create error %d\n",
580 xdc->sc_dev.dv_xname, error);
581 return;
582 }
583
584 /* Get DMA buffer for iorq descriptors */
585 if ((error = xd_dmamem_alloc(xdc->dmatag, xdc->iopmap, &seg, &rseg,
586 XDC_MAXIOPB * sizeof(struct xd_iopb),
587 (caddr_t *)&xdc->iopbase,
588 (bus_addr_t *)&xdc->dvmaiopb)) != 0) {
589 printf("%s: DMA buffer alloc error %d\n",
590 xdc->sc_dev.dv_xname, error);
591 return;
592 }
593
594 bzero(xdc->iopbase, XDC_MAXIOPB * sizeof(struct xd_iopb));
595
596 xdc->reqs = (struct xd_iorq *)
597 malloc(XDC_MAXIOPB * sizeof(struct xd_iorq),
598 M_DEVBUF, M_NOWAIT|M_ZERO);
599 if (xdc->reqs == NULL)
600 panic("xdc malloc");
601
602 /* init free list, iorq to iopb pointers, and non-zero fields in the
603 * iopb which never change. */
604
605 for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) {
606 xdc->reqs[lcv].iopb = &xdc->iopbase[lcv];
607 xdc->reqs[lcv].dmaiopb = &xdc->dvmaiopb[lcv];
608 xdc->freereq[lcv] = lcv;
609 xdc->iopbase[lcv].fixd = 1; /* always the same */
610 xdc->iopbase[lcv].naddrmod = XDC_ADDRMOD; /* always the same */
611 xdc->iopbase[lcv].intr_vec = xdc->vector; /* always the same */
612
613 if ((error = vme_dmamap_create(
614 ct, /* VME chip tag */
615 MAXPHYS, /* size */
616 VME_AM_A24, /* address modifier */
617 VME_D32, /* data size */
618 0, /* swap */
619 1, /* nsegments */
620 MAXPHYS, /* maxsegsz */
621 0, /* boundary */
622 BUS_DMA_NOWAIT,
623 &xdc->reqs[lcv].dmamap)) != 0) {
624
625 printf("%s: DMA buffer map create error %d\n",
626 xdc->sc_dev.dv_xname, error);
627 return;
628 }
629 }
630 xdc->nfree = XDC_MAXIOPB;
631 xdc->nrun = 0;
632 xdc->waithead = xdc->waitend = xdc->nwait = 0;
633 xdc->ndone = 0;
634
635 /* init queue of waiting bufs */
636
637 BUFQ_INIT(&xdc->sc_wq);
638 callout_init(&xdc->sc_tick_ch);
639
640 /*
641 * section 7 of the manual tells us how to init the controller:
642 * - read controller parameters (6/0)
643 * - write controller parameters (5/0)
644 */
645
646 /* read controller parameters and insure we have a 753/7053 */
647
648 rqno = xdc_cmd(xdc, XDCMD_RDP, XDFUN_CTL, 0, 0, 0, 0, XD_SUB_POLL);
649 if (rqno == XD_ERR_FAIL) {
650 printf(": couldn't read controller params\n");
651 return; /* shouldn't ever happen */
652 }
653 ctl = (struct xd_iopb_ctrl *) &xdc->iopbase[rqno];
654 if (ctl->ctype != XDCT_753) {
655 if (xdc->reqs[rqno].errno)
656 printf(": %s: ", xdc_e2str(xdc->reqs[rqno].errno));
657 printf(": doesn't identify as a 753/7053\n");
658 XDC_DONE(xdc, rqno, error);
659 return;
660 }
661 printf(": Xylogics 753/7053, PROM=0x%x.%02x.%02x\n",
662 ctl->eprom_partno, ctl->eprom_lvl, ctl->eprom_rev);
663 XDC_DONE(xdc, rqno, error);
664
665 /* now write controller parameters (xdc_cmd sets all params for us) */
666
667 rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_CTL, 0, 0, 0, 0, XD_SUB_POLL);
668 XDC_DONE(xdc, rqno, error);
669 if (error) {
670 printf("%s: controller config error: %s\n",
671 xdc->sc_dev.dv_xname, xdc_e2str(error));
672 return;
673 }
674
675 /* link in interrupt with higher level software */
676 vme_intr_map(ct, va->ilevel, va->ivector, &ih);
677 vme_intr_establish(ct, ih, IPL_BIO, xdcintr, xdc);
678 evcnt_attach_dynamic(&xdc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
679 xdc->sc_dev.dv_xname, "intr");
680
681
682 /* now we must look for disks using autoconfig */
683 xa.fullmode = XD_SUB_POLL;
684 xa.booting = 1;
685
686 for (xa.driveno = 0; xa.driveno < XDC_MAXDEV; xa.driveno++)
687 (void) config_found(self, (void *) &xa, NULL);
688
689 /* start the watchdog clock */
690 callout_reset(&xdc->sc_tick_ch, XDC_TICKCNT, xdc_tick, xdc);
691
692 }
693
694 /*
695 * xdmatch: probe for disk.
696 *
697 * note: we almost always say disk is present. this allows us to
698 * spin up and configure a disk after the system is booted (we can
699 * call xdattach!).
700 */
701 int
702 xdmatch(parent, cf, aux)
703 struct device *parent;
704 struct cfdata *cf;
705 void *aux;
706 {
707 struct xdc_attach_args *xa = aux;
708
709 /* looking for autoconf wildcard or exact match */
710
711 if (cf->cf_loc[XDCCF_DRIVE] != XDCCF_DRIVE_DEFAULT &&
712 cf->cf_loc[XDCCF_DRIVE] != xa->driveno)
713 return 0;
714
715 return 1;
716
717 }
718
719 /*
720 * xdattach: attach a disk. this can be called from autoconf and also
721 * from xdopen/xdstrategy.
722 */
723 void
724 xdattach(parent, self, aux)
725 struct device *parent, *self;
726 void *aux;
727
728 {
729 struct xd_softc *xd = (void *) self;
730 struct xdc_softc *xdc = (void *) parent;
731 struct xdc_attach_args *xa = aux;
732 int rqno, spt = 0, mb, blk, lcv, fmode, s = 0, newstate;
733 struct xd_iopb_drive *driopb;
734 struct dkbad *dkb;
735 int rseg, error;
736 bus_dma_segment_t seg;
737 caddr_t dmaddr;
738 caddr_t buf;
739
740 /*
741 * Always re-initialize the disk structure. We want statistics
742 * to start with a clean slate.
743 */
744 bzero(&xd->sc_dk, sizeof(xd->sc_dk));
745 xd->sc_dk.dk_driver = &xddkdriver;
746 xd->sc_dk.dk_name = xd->sc_dev.dv_xname;
747
748 /* if booting, init the xd_softc */
749
750 if (xa->booting) {
751 xd->state = XD_DRIVE_UNKNOWN; /* to start */
752 xd->flags = 0;
753 xd->parent = xdc;
754 }
755 xd->xd_drive = xa->driveno;
756 fmode = xa->fullmode;
757 xdc->sc_drives[xa->driveno] = xd;
758
759 /* if not booting, make sure we are the only process in the attach for
760 * this drive. if locked out, sleep on it. */
761
762 if (!xa->booting) {
763 s = splbio();
764 while (xd->state == XD_DRIVE_ATTACHING) {
765 if (tsleep(&xd->state, PRIBIO, "xdattach", 0)) {
766 splx(s);
767 return;
768 }
769 }
770 printf("%s at %s",
771 xd->sc_dev.dv_xname, xd->parent->sc_dev.dv_xname);
772 }
773
774 /* we now have control */
775 xd->state = XD_DRIVE_ATTACHING;
776 newstate = XD_DRIVE_UNKNOWN;
777
778 buf = NULL;
779 if ((error = xd_dmamem_alloc(xdc->dmatag, xdc->auxmap, &seg, &rseg,
780 XDFM_BPS,
781 (caddr_t *)&buf,
782 (bus_addr_t *)&dmaddr)) != 0) {
783 printf("%s: DMA buffer alloc error %d\n",
784 xdc->sc_dev.dv_xname, error);
785 return;
786 }
787
788 /* first try and reset the drive */
789
790 rqno = xdc_cmd(xdc, XDCMD_RST, 0, xd->xd_drive, 0, 0, 0, fmode);
791 XDC_DONE(xdc, rqno, error);
792 if (error == XD_ERR_NRDY) {
793 printf(" drive %d: off-line\n", xa->driveno);
794 goto done;
795 }
796 if (error) {
797 printf(": ERROR 0x%02x (%s)\n", error, xdc_e2str(error));
798 goto done;
799 }
800 printf(" drive %d: ready\n", xa->driveno);
801
802 /* now set format parameters */
803
804 rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_FMT, xd->xd_drive, 0, 0, 0, fmode);
805 XDC_DONE(xdc, rqno, error);
806 if (error) {
807 printf("%s: write format parameters failed: %s\n",
808 xd->sc_dev.dv_xname, xdc_e2str(error));
809 goto done;
810 }
811
812 /* get drive parameters */
813 rqno = xdc_cmd(xdc, XDCMD_RDP, XDFUN_DRV, xd->xd_drive, 0, 0, 0, fmode);
814 if (rqno != XD_ERR_FAIL) {
815 driopb = (struct xd_iopb_drive *) &xdc->iopbase[rqno];
816 spt = driopb->sectpertrk;
817 }
818 XDC_DONE(xdc, rqno, error);
819 if (error) {
820 printf("%s: read drive parameters failed: %s\n",
821 xd->sc_dev.dv_xname, xdc_e2str(error));
822 goto done;
823 }
824
825 /*
826 * now set drive parameters (to semi-bogus values) so we can read the
827 * disk label.
828 */
829 xd->pcyl = xd->ncyl = 1;
830 xd->acyl = 0;
831 xd->nhead = 1;
832 xd->nsect = 1;
833 xd->sectpercyl = 1;
834 for (lcv = 0; lcv < 126; lcv++) /* init empty bad144 table */
835 xd->dkb.bt_bad[lcv].bt_cyl = xd->dkb.bt_bad[lcv].bt_trksec = 0xffff;
836 rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_DRV, xd->xd_drive, 0, 0, 0, fmode);
837 XDC_DONE(xdc, rqno, error);
838 if (error) {
839 printf("%s: write drive parameters failed: %s\n",
840 xd->sc_dev.dv_xname, xdc_e2str(error));
841 goto done;
842 }
843
844 /* read disk label */
845 rqno = xdc_cmd(xdc, XDCMD_RD, 0, xd->xd_drive, 0, 1, dmaddr, fmode);
846 XDC_DONE(xdc, rqno, error);
847 if (error) {
848 printf("%s: reading disk label failed: %s\n",
849 xd->sc_dev.dv_xname, xdc_e2str(error));
850 goto done;
851 }
852 newstate = XD_DRIVE_NOLABEL;
853
854 xd->hw_spt = spt;
855 /* Attach the disk: must be before getdisklabel to malloc label */
856 disk_attach(&xd->sc_dk);
857
858 if (xdgetdisklabel(xd, buf) != XD_ERR_AOK)
859 goto done;
860
861 /* inform the user of what is up */
862 printf("%s: <%s>, pcyl %d, hw_spt %d\n", xd->sc_dev.dv_xname,
863 buf, xd->pcyl, spt);
864 mb = xd->ncyl * (xd->nhead * xd->nsect) / (1048576 / XDFM_BPS);
865 printf("%s: %dMB, %d cyl, %d head, %d sec, %d bytes/sec\n",
866 xd->sc_dev.dv_xname, mb, xd->ncyl, xd->nhead, xd->nsect,
867 XDFM_BPS);
868
869 /* now set the real drive parameters! */
870
871 rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_DRV, xd->xd_drive, 0, 0, 0, fmode);
872 XDC_DONE(xdc, rqno, error);
873 if (error) {
874 printf("%s: write real drive parameters failed: %s\n",
875 xd->sc_dev.dv_xname, xdc_e2str(error));
876 goto done;
877 }
878 newstate = XD_DRIVE_ONLINE;
879
880 /*
881 * read bad144 table. this table resides on the first sector of the
882 * last track of the disk (i.e. second cyl of "acyl" area).
883 */
884
885 blk = (xd->ncyl + xd->acyl - 1) * (xd->nhead * xd->nsect) + /* last cyl */
886 (xd->nhead - 1) * xd->nsect; /* last head */
887 rqno = xdc_cmd(xdc, XDCMD_RD, 0, xd->xd_drive, blk, 1, dmaddr, fmode);
888 XDC_DONE(xdc, rqno, error);
889 if (error) {
890 printf("%s: reading bad144 failed: %s\n",
891 xd->sc_dev.dv_xname, xdc_e2str(error));
892 goto done;
893 }
894
895 /* check dkbad for sanity */
896 dkb = (struct dkbad *) buf;
897 for (lcv = 0; lcv < 126; lcv++) {
898 if ((dkb->bt_bad[lcv].bt_cyl == 0xffff ||
899 dkb->bt_bad[lcv].bt_cyl == 0) &&
900 dkb->bt_bad[lcv].bt_trksec == 0xffff)
901 continue; /* blank */
902 if (dkb->bt_bad[lcv].bt_cyl >= xd->ncyl)
903 break;
904 if ((dkb->bt_bad[lcv].bt_trksec >> 8) >= xd->nhead)
905 break;
906 if ((dkb->bt_bad[lcv].bt_trksec & 0xff) >= xd->nsect)
907 break;
908 }
909 if (lcv != 126) {
910 printf("%s: warning: invalid bad144 sector!\n",
911 xd->sc_dev.dv_xname);
912 } else {
913 bcopy(buf, &xd->dkb, XDFM_BPS);
914 }
915
916 done:
917 if (buf != NULL) {
918 xd_dmamem_free(xdc->dmatag, xdc->auxmap,
919 &seg, rseg, XDFM_BPS, buf);
920 }
921
922 xd->state = newstate;
923 if (!xa->booting) {
924 wakeup(&xd->state);
925 splx(s);
926 }
927 }
928
929 /*
930 * end of autoconfig functions
931 */
932
933 /*
934 * { b , c } d e v s w f u n c t i o n s
935 */
936
937 /*
938 * xdclose: close device
939 */
940 int
941 xdclose(dev, flag, fmt, p)
942 dev_t dev;
943 int flag, fmt;
944 struct proc *p;
945 {
946 struct xd_softc *xd = xd_cd.cd_devs[DISKUNIT(dev)];
947 int part = DISKPART(dev);
948
949 /* clear mask bits */
950
951 switch (fmt) {
952 case S_IFCHR:
953 xd->sc_dk.dk_copenmask &= ~(1 << part);
954 break;
955 case S_IFBLK:
956 xd->sc_dk.dk_bopenmask &= ~(1 << part);
957 break;
958 }
959 xd->sc_dk.dk_openmask = xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask;
960
961 return 0;
962 }
963
964 /*
965 * xddump: crash dump system
966 */
967 int
968 xddump(dev, blkno, va, size)
969 dev_t dev;
970 daddr_t blkno;
971 caddr_t va;
972 size_t size;
973 {
974 int unit, part;
975 struct xd_softc *xd;
976
977 unit = DISKUNIT(dev);
978 if (unit >= xd_cd.cd_ndevs)
979 return ENXIO;
980 part = DISKPART(dev);
981
982 xd = xd_cd.cd_devs[unit];
983
984 printf("%s%c: crash dump not supported (yet)\n", xd->sc_dev.dv_xname,
985 'a' + part);
986
987 return ENXIO;
988
989 /* outline: globals: "dumplo" == sector number of partition to start
990 * dump at (convert to physical sector with partition table)
991 * "dumpsize" == size of dump in clicks "physmem" == size of physical
992 * memory (clicks, ctob() to get bytes) (normal case: dumpsize ==
993 * physmem)
994 *
995 * dump a copy of physical memory to the dump device starting at sector
996 * "dumplo" in the swap partition (make sure > 0). map in pages as
997 * we go. use polled I/O.
998 *
999 * XXX how to handle NON_CONTIG? */
1000
1001 }
1002
1003 /*
1004 * xdioctl: ioctls on XD drives. based on ioctl's of other netbsd disks.
1005 */
1006 int
1007 xdioctl(dev, command, addr, flag, p)
1008 dev_t dev;
1009 u_long command;
1010 caddr_t addr;
1011 int flag;
1012 struct proc *p;
1013
1014 {
1015 struct xd_softc *xd;
1016 struct xd_iocmd *xio;
1017 int error, s, unit;
1018 #ifdef __HAVE_OLD_DISKLABEL
1019 struct disklabel newlabel;
1020 #endif
1021 struct disklabel *lp;
1022
1023 unit = DISKUNIT(dev);
1024
1025 if (unit >= xd_cd.cd_ndevs || (xd = xd_cd.cd_devs[unit]) == NULL)
1026 return (ENXIO);
1027
1028 /* switch on ioctl type */
1029
1030 switch (command) {
1031 case DIOCSBAD: /* set bad144 info */
1032 if ((flag & FWRITE) == 0)
1033 return EBADF;
1034 s = splbio();
1035 bcopy(addr, &xd->dkb, sizeof(xd->dkb));
1036 splx(s);
1037 return 0;
1038
1039 case DIOCGDINFO: /* get disk label */
1040 bcopy(xd->sc_dk.dk_label, addr, sizeof(struct disklabel));
1041 return 0;
1042 #ifdef __HAVE_OLD_DISKLABEL
1043 case ODIOCGDINFO:
1044 newlabel = *(xd->sc_dk.dk_label);
1045 if (newlabel.d_npartitions > OLDMAXPARTITIONS)
1046 return ENOTTY;
1047 memcpy(addr, &newlabel, sizeof (struct olddisklabel));
1048 return 0;
1049 #endif
1050
1051 case DIOCGPART: /* get partition info */
1052 ((struct partinfo *) addr)->disklab = xd->sc_dk.dk_label;
1053 ((struct partinfo *) addr)->part =
1054 &xd->sc_dk.dk_label->d_partitions[DISKPART(dev)];
1055 return 0;
1056
1057 case DIOCSDINFO: /* set disk label */
1058 #ifdef __HAVE_OLD_DISKLABEL
1059 case ODIOCSDINFO:
1060 if (command == ODIOCSDINFO) {
1061 memset(&newlabel, 0, sizeof newlabel);
1062 memcpy(&newlabel, addr, sizeof (struct olddisklabel));
1063 lp = &newlabel;
1064 } else
1065 #endif
1066 lp = (struct disklabel *)addr;
1067
1068 if ((flag & FWRITE) == 0)
1069 return EBADF;
1070 error = setdisklabel(xd->sc_dk.dk_label,
1071 lp, /* xd->sc_dk.dk_openmask : */ 0,
1072 xd->sc_dk.dk_cpulabel);
1073 if (error == 0) {
1074 if (xd->state == XD_DRIVE_NOLABEL)
1075 xd->state = XD_DRIVE_ONLINE;
1076 }
1077 return error;
1078
1079 case DIOCWLABEL: /* change write status of disk label */
1080 if ((flag & FWRITE) == 0)
1081 return EBADF;
1082 if (*(int *) addr)
1083 xd->flags |= XD_WLABEL;
1084 else
1085 xd->flags &= ~XD_WLABEL;
1086 return 0;
1087
1088 case DIOCWDINFO: /* write disk label */
1089 #ifdef __HAVE_OLD_DISKLABEL
1090 case ODIOCWDINFO:
1091 if (command == ODIOCWDINFO) {
1092 memset(&newlabel, 0, sizeof newlabel);
1093 memcpy(&newlabel, addr, sizeof (struct olddisklabel));
1094 lp = &newlabel;
1095 } else
1096 #endif
1097 lp = (struct disklabel *)addr;
1098
1099 if ((flag & FWRITE) == 0)
1100 return EBADF;
1101 error = setdisklabel(xd->sc_dk.dk_label,
1102 lp, /* xd->sc_dk.dk_openmask : */ 0,
1103 xd->sc_dk.dk_cpulabel);
1104 if (error == 0) {
1105 if (xd->state == XD_DRIVE_NOLABEL)
1106 xd->state = XD_DRIVE_ONLINE;
1107
1108 /* Simulate opening partition 0 so write succeeds. */
1109 xd->sc_dk.dk_openmask |= (1 << 0);
1110 error = writedisklabel(MAKEDISKDEV(major(dev),
1111 DISKUNIT(dev), RAW_PART),
1112 xdstrategy, xd->sc_dk.dk_label,
1113 xd->sc_dk.dk_cpulabel);
1114 xd->sc_dk.dk_openmask =
1115 xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask;
1116 }
1117 return error;
1118
1119 case DIOSXDCMD:
1120 xio = (struct xd_iocmd *) addr;
1121 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
1122 return (error);
1123 return (xdc_ioctlcmd(xd, dev, xio));
1124
1125 default:
1126 return ENOTTY;
1127 }
1128 }
1129 /*
1130 * xdopen: open drive
1131 */
1132
1133 int
1134 xdopen(dev, flag, fmt, p)
1135 dev_t dev;
1136 int flag, fmt;
1137 struct proc *p;
1138 {
1139 int unit, part;
1140 struct xd_softc *xd;
1141 struct xdc_attach_args xa;
1142
1143 /* first, could it be a valid target? */
1144
1145 unit = DISKUNIT(dev);
1146 if (unit >= xd_cd.cd_ndevs || (xd = xd_cd.cd_devs[unit]) == NULL)
1147 return (ENXIO);
1148 part = DISKPART(dev);
1149
1150 /* do we need to attach the drive? */
1151
1152 if (xd->state == XD_DRIVE_UNKNOWN) {
1153 xa.driveno = xd->xd_drive;
1154 xa.fullmode = XD_SUB_WAIT;
1155 xa.booting = 0;
1156 xdattach((struct device *) xd->parent, (struct device *) xd, &xa);
1157 if (xd->state == XD_DRIVE_UNKNOWN) {
1158 return (EIO);
1159 }
1160 }
1161 /* check for partition */
1162
1163 if (part != RAW_PART &&
1164 (part >= xd->sc_dk.dk_label->d_npartitions ||
1165 xd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
1166 return (ENXIO);
1167 }
1168 /* set open masks */
1169
1170 switch (fmt) {
1171 case S_IFCHR:
1172 xd->sc_dk.dk_copenmask |= (1 << part);
1173 break;
1174 case S_IFBLK:
1175 xd->sc_dk.dk_bopenmask |= (1 << part);
1176 break;
1177 }
1178 xd->sc_dk.dk_openmask = xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask;
1179
1180 return 0;
1181 }
1182
1183 int
1184 xdread(dev, uio, flags)
1185 dev_t dev;
1186 struct uio *uio;
1187 int flags;
1188 {
1189
1190 return (physio(xdstrategy, NULL, dev, B_READ, minphys, uio));
1191 }
1192
1193 int
1194 xdwrite(dev, uio, flags)
1195 dev_t dev;
1196 struct uio *uio;
1197 int flags;
1198 {
1199
1200 return (physio(xdstrategy, NULL, dev, B_WRITE, minphys, uio));
1201 }
1202
1203
1204 /*
1205 * xdsize: return size of a partition for a dump
1206 */
1207
1208 int
1209 xdsize(dev)
1210 dev_t dev;
1211
1212 {
1213 struct xd_softc *xdsc;
1214 int unit, part, size, omask;
1215
1216 /* valid unit? */
1217 unit = DISKUNIT(dev);
1218 if (unit >= xd_cd.cd_ndevs || (xdsc = xd_cd.cd_devs[unit]) == NULL)
1219 return (-1);
1220
1221 part = DISKPART(dev);
1222 omask = xdsc->sc_dk.dk_openmask & (1 << part);
1223
1224 if (omask == 0 && xdopen(dev, 0, S_IFBLK, NULL) != 0)
1225 return (-1);
1226
1227 /* do it */
1228 if (xdsc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
1229 size = -1; /* only give valid size for swap partitions */
1230 else
1231 size = xdsc->sc_dk.dk_label->d_partitions[part].p_size *
1232 (xdsc->sc_dk.dk_label->d_secsize / DEV_BSIZE);
1233 if (omask == 0 && xdclose(dev, 0, S_IFBLK, NULL) != 0)
1234 return (-1);
1235 return (size);
1236 }
1237 /*
1238 * xdstrategy: buffering system interface to xd.
1239 */
1240
1241 void
1242 xdstrategy(bp)
1243 struct buf *bp;
1244
1245 {
1246 struct xd_softc *xd;
1247 struct xdc_softc *parent;
1248 int s, unit;
1249 struct xdc_attach_args xa;
1250
1251 unit = DISKUNIT(bp->b_dev);
1252
1253 /* check for live device */
1254
1255 if (unit >= xd_cd.cd_ndevs || (xd = xd_cd.cd_devs[unit]) == 0 ||
1256 bp->b_blkno < 0 ||
1257 (bp->b_bcount % xd->sc_dk.dk_label->d_secsize) != 0) {
1258 bp->b_error = EINVAL;
1259 goto bad;
1260 }
1261 /* do we need to attach the drive? */
1262
1263 if (xd->state == XD_DRIVE_UNKNOWN) {
1264 xa.driveno = xd->xd_drive;
1265 xa.fullmode = XD_SUB_WAIT;
1266 xa.booting = 0;
1267 xdattach((struct device *)xd->parent, (struct device *)xd, &xa);
1268 if (xd->state == XD_DRIVE_UNKNOWN) {
1269 bp->b_error = EIO;
1270 goto bad;
1271 }
1272 }
1273 if (xd->state != XD_DRIVE_ONLINE && DISKPART(bp->b_dev) != RAW_PART) {
1274 /* no I/O to unlabeled disks, unless raw partition */
1275 bp->b_error = EIO;
1276 goto bad;
1277 }
1278 /* short circuit zero length request */
1279
1280 if (bp->b_bcount == 0)
1281 goto done;
1282
1283 /* check bounds with label (disksubr.c). Determine the size of the
1284 * transfer, and make sure it is within the boundaries of the
1285 * partition. Adjust transfer if needed, and signal errors or early
1286 * completion. */
1287
1288 if (bounds_check_with_label(bp, xd->sc_dk.dk_label,
1289 (xd->flags & XD_WLABEL) != 0) <= 0)
1290 goto done;
1291
1292 /*
1293 * now we know we have a valid buf structure that we need to do I/O
1294 * on.
1295 *
1296 * note that we don't disksort because the controller has a sorting
1297 * algorithm built into the hardware.
1298 */
1299
1300 s = splbio(); /* protect the queues */
1301
1302 /* first, give jobs in front of us a chance */
1303 parent = xd->parent;
1304 while (parent->nfree > 0 && BUFQ_FIRST(&parent->sc_wq) != NULL)
1305 if (xdc_startbuf(parent, NULL, NULL) != XD_ERR_AOK)
1306 break;
1307
1308 /* if there are no free iorq's, then we just queue and return. the
1309 * buffs will get picked up later by xdcintr().
1310 */
1311
1312 if (parent->nfree == 0) {
1313 BUFQ_INSERT_TAIL(&parent->sc_wq, bp);
1314 splx(s);
1315 return;
1316 }
1317
1318 /* now we have free iopb's and we are at splbio... start 'em up */
1319 if (xdc_startbuf(parent, xd, bp) != XD_ERR_AOK) {
1320 return;
1321 }
1322
1323 /* done! */
1324
1325 splx(s);
1326 return;
1327
1328 bad: /* tells upper layers we have an error */
1329 bp->b_flags |= B_ERROR;
1330 done: /* tells upper layers we are done with this
1331 * buf */
1332 bp->b_resid = bp->b_bcount;
1333 biodone(bp);
1334 }
1335 /*
1336 * end of {b,c}devsw functions
1337 */
1338
1339 /*
1340 * i n t e r r u p t f u n c t i o n
1341 *
1342 * xdcintr: hardware interrupt.
1343 */
1344 int
1345 xdcintr(v)
1346 void *v;
1347
1348 {
1349 struct xdc_softc *xdcsc = v;
1350
1351 /* kick the event counter */
1352
1353 xdcsc->sc_intrcnt.ev_count++;
1354
1355 /* remove as many done IOPBs as possible */
1356
1357 xdc_remove_iorq(xdcsc);
1358
1359 /* start any iorq's already waiting */
1360
1361 xdc_start(xdcsc, XDC_MAXIOPB);
1362
1363 /* fill up any remaining iorq's with queue'd buffers */
1364
1365 while (xdcsc->nfree > 0 && BUFQ_FIRST(&xdcsc->sc_wq) != NULL)
1366 if (xdc_startbuf(xdcsc, NULL, NULL) != XD_ERR_AOK)
1367 break;
1368
1369 return (1);
1370 }
1371 /*
1372 * end of interrupt function
1373 */
1374
1375 /*
1376 * i n t e r n a l f u n c t i o n s
1377 */
1378
1379 /*
1380 * xdc_rqinit: fill out the fields of an I/O request
1381 */
1382
1383 inline void
1384 xdc_rqinit(rq, xdc, xd, md, blk, cnt, db, bp)
1385 struct xd_iorq *rq;
1386 struct xdc_softc *xdc;
1387 struct xd_softc *xd;
1388 int md;
1389 u_long blk;
1390 int cnt;
1391 caddr_t db;
1392 struct buf *bp;
1393 {
1394 rq->xdc = xdc;
1395 rq->xd = xd;
1396 rq->ttl = XDC_MAXTTL + 10;
1397 rq->mode = md;
1398 rq->tries = rq->errno = rq->lasterror = 0;
1399 rq->blockno = blk;
1400 rq->sectcnt = cnt;
1401 rq->dbuf = db;
1402 rq->buf = bp;
1403 }
1404 /*
1405 * xdc_rqtopb: load up an IOPB based on an iorq
1406 */
1407
1408 void
1409 xdc_rqtopb(iorq, iopb, cmd, subfun)
1410 struct xd_iorq *iorq;
1411 struct xd_iopb *iopb;
1412 int cmd, subfun;
1413
1414 {
1415 u_long block, dp;
1416
1417 /* standard stuff */
1418
1419 iopb->errs = iopb->done = 0;
1420 iopb->comm = cmd;
1421 iopb->errno = iopb->status = 0;
1422 iopb->subfun = subfun;
1423 if (iorq->xd)
1424 iopb->unit = iorq->xd->xd_drive;
1425 else
1426 iopb->unit = 0;
1427
1428 /* check for alternate IOPB format */
1429
1430 if (cmd == XDCMD_WRP) {
1431 switch (subfun) {
1432 case XDFUN_CTL:{
1433 struct xd_iopb_ctrl *ctrl =
1434 (struct xd_iopb_ctrl *) iopb;
1435 iopb->lll = 0;
1436 iopb->intl = (XD_STATE(iorq->mode) == XD_SUB_POLL)
1437 ? 0
1438 : iorq->xdc->ipl;
1439 ctrl->param_a = XDPA_TMOD | XDPA_DACF;
1440 ctrl->param_b = XDPB_ROR | XDPB_TDT_3_2USEC;
1441 ctrl->param_c = XDPC_OVS | XDPC_COP | XDPC_ASR |
1442 XDPC_RBC | XDPC_ECC2;
1443 ctrl->throttle = XDC_THROTTLE;
1444 ctrl->delay = XDC_DELAY;
1445 break;
1446 }
1447 case XDFUN_DRV:{
1448 struct xd_iopb_drive *drv =
1449 (struct xd_iopb_drive *)iopb;
1450 /* we assume that the disk label has the right
1451 * info */
1452 if (XD_STATE(iorq->mode) == XD_SUB_POLL)
1453 drv->dparam_ipl = (XDC_DPARAM << 3);
1454 else
1455 drv->dparam_ipl = (XDC_DPARAM << 3) |
1456 iorq->xdc->ipl;
1457 drv->maxsect = iorq->xd->nsect - 1;
1458 drv->maxsector = drv->maxsect;
1459 /* note: maxsector != maxsect only if you are
1460 * doing cyl sparing */
1461 drv->headoff = 0;
1462 drv->maxcyl = iorq->xd->pcyl - 1;
1463 drv->maxhead = iorq->xd->nhead - 1;
1464 break;
1465 }
1466 case XDFUN_FMT:{
1467 struct xd_iopb_format *form =
1468 (struct xd_iopb_format *) iopb;
1469 if (XD_STATE(iorq->mode) == XD_SUB_POLL)
1470 form->interleave_ipl = (XDC_INTERLEAVE << 3);
1471 else
1472 form->interleave_ipl = (XDC_INTERLEAVE << 3) |
1473 iorq->xdc->ipl;
1474 form->field1 = XDFM_FIELD1;
1475 form->field2 = XDFM_FIELD2;
1476 form->field3 = XDFM_FIELD3;
1477 form->field4 = XDFM_FIELD4;
1478 form->bytespersec = XDFM_BPS;
1479 form->field6 = XDFM_FIELD6;
1480 form->field7 = XDFM_FIELD7;
1481 break;
1482 }
1483 }
1484 } else {
1485
1486 /* normal IOPB case (harmless to RDP command) */
1487
1488 iopb->lll = 0;
1489 iopb->intl = (XD_STATE(iorq->mode) == XD_SUB_POLL)
1490 ? 0
1491 : iorq->xdc->ipl;
1492 iopb->sectcnt = iorq->sectcnt;
1493 block = iorq->blockno;
1494 if (iorq->xd == NULL || block == 0) {
1495 iopb->sectno = iopb->headno = iopb->cylno = 0;
1496 } else {
1497 iopb->sectno = block % iorq->xd->nsect;
1498 block = block / iorq->xd->nsect;
1499 iopb->headno = block % iorq->xd->nhead;
1500 block = block / iorq->xd->nhead;
1501 iopb->cylno = block;
1502 }
1503 dp = (u_long) iorq->dbuf;
1504 dp = iopb->daddr = (iorq->dbuf == NULL) ? 0 : dp;
1505 iopb->addrmod = ((dp + (XDFM_BPS * iorq->sectcnt)) > 0x1000000)
1506 ? XDC_ADDRMOD32
1507 : XDC_ADDRMOD;
1508 }
1509 }
1510
1511 /*
1512 * xdc_cmd: front end for POLL'd and WAIT'd commands. Returns rqno.
1513 * If you've already got an IORQ, you can call submit directly (currently
1514 * there is no need to do this). NORM requests are handled separately.
1515 */
1516 int
1517 xdc_cmd(xdcsc, cmd, subfn, unit, block, scnt, dptr, fullmode)
1518 struct xdc_softc *xdcsc;
1519 int cmd, subfn, unit, block, scnt;
1520 char *dptr;
1521 int fullmode;
1522
1523 {
1524 int rqno, submode = XD_STATE(fullmode), retry;
1525 struct xd_iorq *iorq;
1526 struct xd_iopb *iopb;
1527
1528 /* get iorq/iopb */
1529 switch (submode) {
1530 case XD_SUB_POLL:
1531 while (xdcsc->nfree == 0) {
1532 if (xdc_piodriver(xdcsc, 0, 1) != XD_ERR_AOK)
1533 return (XD_ERR_FAIL);
1534 }
1535 break;
1536 case XD_SUB_WAIT:
1537 retry = 1;
1538 while (retry) {
1539 while (xdcsc->nfree == 0) {
1540 if (tsleep(&xdcsc->nfree, PRIBIO, "xdnfree", 0))
1541 return (XD_ERR_FAIL);
1542 }
1543 while (xdcsc->ndone > XDC_SUBWAITLIM) {
1544 if (tsleep(&xdcsc->ndone, PRIBIO, "xdsubwait", 0))
1545 return (XD_ERR_FAIL);
1546 }
1547 if (xdcsc->nfree)
1548 retry = 0; /* got it */
1549 }
1550 break;
1551 default:
1552 return (XD_ERR_FAIL); /* illegal */
1553 }
1554 if (xdcsc->nfree == 0)
1555 panic("xdcmd nfree");
1556 rqno = XDC_RQALLOC(xdcsc);
1557 iorq = &xdcsc->reqs[rqno];
1558 iopb = iorq->iopb;
1559
1560
1561 /* init iorq/iopb */
1562
1563 xdc_rqinit(iorq, xdcsc,
1564 (unit == XDC_NOUNIT) ? NULL : xdcsc->sc_drives[unit],
1565 fullmode, block, scnt, dptr, NULL);
1566
1567 /* load IOPB from iorq */
1568
1569 xdc_rqtopb(iorq, iopb, cmd, subfn);
1570
1571 /* submit it for processing */
1572
1573 xdc_submit_iorq(xdcsc, rqno, fullmode); /* error code will be in iorq */
1574
1575 return (rqno);
1576 }
1577 /*
1578 * xdc_startbuf
1579 * start a buffer running, assumes nfree > 0
1580 */
1581
1582 int
1583 xdc_startbuf(xdcsc, xdsc, bp)
1584 struct xdc_softc *xdcsc;
1585 struct xd_softc *xdsc;
1586 struct buf *bp;
1587
1588 {
1589 int rqno, partno;
1590 struct xd_iorq *iorq;
1591 struct xd_iopb *iopb;
1592 u_long block;
1593 /* caddr_t dbuf;*/
1594 int error;
1595
1596 if (!xdcsc->nfree)
1597 panic("xdc_startbuf free");
1598 rqno = XDC_RQALLOC(xdcsc);
1599 iorq = &xdcsc->reqs[rqno];
1600 iopb = iorq->iopb;
1601
1602 /* get buf */
1603
1604 if (bp == NULL) {
1605 bp = BUFQ_FIRST(&xdcsc->sc_wq);
1606 if (bp == NULL)
1607 panic("xdc_startbuf bp");
1608 BUFQ_REMOVE(&xdcsc->sc_wq, bp);
1609 xdsc = xdcsc->sc_drives[DISKUNIT(bp->b_dev)];
1610 }
1611 partno = DISKPART(bp->b_dev);
1612 #ifdef XDC_DEBUG
1613 printf("xdc_startbuf: %s%c: %s block %d\n", xdsc->sc_dev.dv_xname,
1614 'a' + partno, (bp->b_flags & B_READ) ? "read" : "write", bp->b_blkno);
1615 printf("xdc_startbuf: b_bcount %d, b_data 0x%x\n",
1616 bp->b_bcount, bp->b_data);
1617 #endif
1618
1619 /*
1620 * load request. we have to calculate the correct block number based
1621 * on partition info.
1622 *
1623 * note that iorq points to the buffer as mapped into DVMA space,
1624 * where as the bp->b_data points to its non-DVMA mapping.
1625 */
1626
1627 block = bp->b_blkno + ((partno == RAW_PART) ? 0 :
1628 xdsc->sc_dk.dk_label->d_partitions[partno].p_offset);
1629
1630 error = bus_dmamap_load(xdcsc->dmatag, iorq->dmamap,
1631 bp->b_data, bp->b_bcount, 0, BUS_DMA_NOWAIT);
1632 if (error != 0) {
1633 printf("%s: warning: cannot load DMA map\n",
1634 xdcsc->sc_dev.dv_xname);
1635 XDC_FREE(xdcsc, rqno);
1636 BUFQ_INSERT_TAIL(&xdcsc->sc_wq, bp);
1637 return (XD_ERR_FAIL); /* XXX: need some sort of
1638 * call-back scheme here? */
1639 }
1640 bus_dmamap_sync(xdcsc->dmatag, iorq->dmamap, 0,
1641 iorq->dmamap->dm_mapsize, (bp->b_flags & B_READ)
1642 ? BUS_DMASYNC_PREREAD
1643 : BUS_DMASYNC_PREWRITE);
1644
1645 /* init iorq and load iopb from it */
1646 xdc_rqinit(iorq, xdcsc, xdsc, XD_SUB_NORM | XD_MODE_VERBO, block,
1647 bp->b_bcount / XDFM_BPS,
1648 (caddr_t)(u_long)iorq->dmamap->dm_segs[0].ds_addr,
1649 bp);
1650
1651 xdc_rqtopb(iorq, iopb, (bp->b_flags & B_READ) ? XDCMD_RD : XDCMD_WR, 0);
1652
1653 /* Instrumentation. */
1654 disk_busy(&xdsc->sc_dk);
1655
1656 /* now submit [note that xdc_submit_iorq can never fail on NORM reqs] */
1657
1658 xdc_submit_iorq(xdcsc, rqno, XD_SUB_NORM);
1659 return (XD_ERR_AOK);
1660 }
1661
1662
1663 /*
1664 * xdc_submit_iorq: submit an iorq for processing. returns XD_ERR_AOK
1665 * if ok. if it fail returns an error code. type is XD_SUB_*.
1666 *
1667 * note: caller frees iorq in all cases except NORM
1668 *
1669 * return value:
1670 * NORM: XD_AOK (req pending), XD_FAIL (couldn't submit request)
1671 * WAIT: XD_AOK (success), <error-code> (failed)
1672 * POLL: <same as WAIT>
1673 * NOQ : <same as NORM>
1674 *
1675 * there are three sources for i/o requests:
1676 * [1] xdstrategy: normal block I/O, using "struct buf" system.
1677 * [2] autoconfig/crash dump: these are polled I/O requests, no interrupts.
1678 * [3] open/ioctl: these are I/O requests done in the context of a process,
1679 * and the process should block until they are done.
1680 *
1681 * software state is stored in the iorq structure. each iorq has an
1682 * iopb structure. the hardware understands the iopb structure.
1683 * every command must go through an iopb. a 7053 can only handle
1684 * XDC_MAXIOPB (31) active iopbs at one time. iopbs are allocated in
1685 * DVMA space at boot up time. what happens if we run out of iopb's?
1686 * for i/o type [1], the buffers are queued at the "buff" layer and
1687 * picked up later by the interrupt routine. for case [2] the
1688 * programmed i/o driver is called with a special flag that says
1689 * return when one iopb is free. for case [3] the process can sleep
1690 * on the iorq free list until some iopbs are avaliable.
1691 */
1692
1693
1694 int
1695 xdc_submit_iorq(xdcsc, iorqno, type)
1696 struct xdc_softc *xdcsc;
1697 int iorqno;
1698 int type;
1699
1700 {
1701 u_long iopbaddr;
1702 struct xd_iorq *iorq = &xdcsc->reqs[iorqno];
1703
1704 #ifdef XDC_DEBUG
1705 printf("xdc_submit_iorq(%s, no=%d, type=%d)\n", xdcsc->sc_dev.dv_xname,
1706 iorqno, type);
1707 #endif
1708
1709 /* first check and see if controller is busy */
1710 if (xdcsc->xdc->xdc_csr & XDC_ADDING) {
1711 #ifdef XDC_DEBUG
1712 printf("xdc_submit_iorq: XDC not ready (ADDING)\n");
1713 #endif
1714 if (type == XD_SUB_NOQ)
1715 return (XD_ERR_FAIL); /* failed */
1716 XDC_TWAIT(xdcsc, iorqno); /* put at end of waitq */
1717 switch (type) {
1718 case XD_SUB_NORM:
1719 return XD_ERR_AOK; /* success */
1720 case XD_SUB_WAIT:
1721 while (iorq->iopb->done == 0) {
1722 (void) tsleep(iorq, PRIBIO, "xdciorq", 0);
1723 }
1724 return (iorq->errno);
1725 case XD_SUB_POLL:
1726 return (xdc_piodriver(xdcsc, iorqno, 0));
1727 default:
1728 panic("xdc_submit_iorq adding");
1729 }
1730 }
1731 #ifdef XDC_DEBUG
1732 {
1733 u_char *rio = (u_char *) iorq->iopb;
1734 int sz = sizeof(struct xd_iopb), lcv;
1735 printf("%s: aio #%d [",
1736 xdcsc->sc_dev.dv_xname, iorq - xdcsc->reqs);
1737 for (lcv = 0; lcv < sz; lcv++)
1738 printf(" %02x", rio[lcv]);
1739 printf("]\n");
1740 }
1741 #endif /* XDC_DEBUG */
1742
1743 /* controller not busy, start command */
1744 iopbaddr = (u_long) iorq->dmaiopb;
1745 XDC_GO(xdcsc->xdc, iopbaddr); /* go! */
1746 xdcsc->nrun++;
1747 /* command now running, wrap it up */
1748 switch (type) {
1749 case XD_SUB_NORM:
1750 case XD_SUB_NOQ:
1751 return (XD_ERR_AOK); /* success */
1752 case XD_SUB_WAIT:
1753 while (iorq->iopb->done == 0) {
1754 (void) tsleep(iorq, PRIBIO, "xdciorq", 0);
1755 }
1756 return (iorq->errno);
1757 case XD_SUB_POLL:
1758 return (xdc_piodriver(xdcsc, iorqno, 0));
1759 default:
1760 panic("xdc_submit_iorq wrap up");
1761 }
1762 panic("xdc_submit_iorq");
1763 return 0; /* not reached */
1764 }
1765
1766
1767 /*
1768 * xdc_piodriver
1769 *
1770 * programmed i/o driver. this function takes over the computer
1771 * and drains off all i/o requests. it returns the status of the iorq
1772 * the caller is interesting in. if freeone is true, then it returns
1773 * when there is a free iorq.
1774 */
1775 int
1776 xdc_piodriver(xdcsc, iorqno, freeone)
1777 struct xdc_softc *xdcsc;
1778 int iorqno;
1779 int freeone;
1780
1781 {
1782 int nreset = 0;
1783 int retval = 0;
1784 u_long count;
1785 struct xdc *xdc = xdcsc->xdc;
1786 #ifdef XDC_DEBUG
1787 printf("xdc_piodriver(%s, %d, freeone=%d)\n", xdcsc->sc_dev.dv_xname,
1788 iorqno, freeone);
1789 #endif
1790
1791 while (xdcsc->nwait || xdcsc->nrun) {
1792 #ifdef XDC_DEBUG
1793 printf("xdc_piodriver: wait=%d, run=%d\n",
1794 xdcsc->nwait, xdcsc->nrun);
1795 #endif
1796 XDC_WAIT(xdc, count, XDC_MAXTIME, (XDC_REMIOPB | XDC_F_ERROR));
1797 #ifdef XDC_DEBUG
1798 printf("xdc_piodriver: done wait with count = %d\n", count);
1799 #endif
1800 /* we expect some progress soon */
1801 if (count == 0 && nreset >= 2) {
1802 xdc_reset(xdcsc, 0, XD_RSET_ALL, XD_ERR_FAIL, 0);
1803 #ifdef XDC_DEBUG
1804 printf("xdc_piodriver: timeout\n");
1805 #endif
1806 return (XD_ERR_FAIL);
1807 }
1808 if (count == 0) {
1809 if (xdc_reset(xdcsc, 0,
1810 (nreset++ == 0) ? XD_RSET_NONE : iorqno,
1811 XD_ERR_FAIL,
1812 0) == XD_ERR_FAIL)
1813 return (XD_ERR_FAIL); /* flushes all but POLL
1814 * requests, resets */
1815 continue;
1816 }
1817 xdc_remove_iorq(xdcsc); /* could resubmit request */
1818 if (freeone) {
1819 if (xdcsc->nrun < XDC_MAXIOPB) {
1820 #ifdef XDC_DEBUG
1821 printf("xdc_piodriver: done: one free\n");
1822 #endif
1823 return (XD_ERR_AOK);
1824 }
1825 continue; /* don't xdc_start */
1826 }
1827 xdc_start(xdcsc, XDC_MAXIOPB);
1828 }
1829
1830 /* get return value */
1831
1832 retval = xdcsc->reqs[iorqno].errno;
1833
1834 #ifdef XDC_DEBUG
1835 printf("xdc_piodriver: done, retval = 0x%x (%s)\n",
1836 xdcsc->reqs[iorqno].errno, xdc_e2str(xdcsc->reqs[iorqno].errno));
1837 #endif
1838
1839 /* now that we've drained everything, start up any bufs that have
1840 * queued */
1841
1842 while (xdcsc->nfree > 0 && BUFQ_FIRST(&xdcsc->sc_wq) != NULL)
1843 if (xdc_startbuf(xdcsc, NULL, NULL) != XD_ERR_AOK)
1844 break;
1845
1846 return (retval);
1847 }
1848
1849 /*
1850 * xdc_reset: reset one drive. NOTE: assumes xdc was just reset.
1851 * we steal iopb[0] for this, but we put it back when we are done.
1852 */
1853 void
1854 xdc_xdreset(xdcsc, xdsc)
1855 struct xdc_softc *xdcsc;
1856 struct xd_softc *xdsc;
1857
1858 {
1859 struct xd_iopb tmpiopb;
1860 u_long addr;
1861 int del;
1862 bcopy(xdcsc->iopbase, &tmpiopb, sizeof(tmpiopb));
1863 bzero(xdcsc->iopbase, sizeof(tmpiopb));
1864 xdcsc->iopbase->comm = XDCMD_RST;
1865 xdcsc->iopbase->unit = xdsc->xd_drive;
1866 addr = (u_long) xdcsc->dvmaiopb;
1867 XDC_GO(xdcsc->xdc, addr); /* go! */
1868 XDC_WAIT(xdcsc->xdc, del, XDC_RESETUSEC, XDC_REMIOPB);
1869 if (del <= 0 || xdcsc->iopbase->errs) {
1870 printf("%s: off-line: %s\n", xdcsc->sc_dev.dv_xname,
1871 xdc_e2str(xdcsc->iopbase->errno));
1872 xdcsc->xdc->xdc_csr = XDC_RESET;
1873 XDC_WAIT(xdcsc->xdc, del, XDC_RESETUSEC, XDC_RESET);
1874 if (del <= 0)
1875 panic("xdc_reset");
1876 } else {
1877 xdcsc->xdc->xdc_csr = XDC_CLRRIO; /* clear RIO */
1878 }
1879 bcopy(&tmpiopb, xdcsc->iopbase, sizeof(tmpiopb));
1880 }
1881
1882
1883 /*
1884 * xdc_reset: reset everything: requests are marked as errors except
1885 * a polled request (which is resubmitted)
1886 */
1887 int
1888 xdc_reset(xdcsc, quiet, blastmode, error, xdsc)
1889 struct xdc_softc *xdcsc;
1890 int quiet, blastmode, error;
1891 struct xd_softc *xdsc;
1892
1893 {
1894 int del = 0, lcv, retval = XD_ERR_AOK;
1895 int oldfree = xdcsc->nfree;
1896
1897 /* soft reset hardware */
1898
1899 if (!quiet)
1900 printf("%s: soft reset\n", xdcsc->sc_dev.dv_xname);
1901 xdcsc->xdc->xdc_csr = XDC_RESET;
1902 XDC_WAIT(xdcsc->xdc, del, XDC_RESETUSEC, XDC_RESET);
1903 if (del <= 0) {
1904 blastmode = XD_RSET_ALL; /* dead, flush all requests */
1905 retval = XD_ERR_FAIL;
1906 }
1907 if (xdsc)
1908 xdc_xdreset(xdcsc, xdsc);
1909
1910 /* fix queues based on "blast-mode" */
1911
1912 for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) {
1913 register struct xd_iorq *iorq = &xdcsc->reqs[lcv];
1914
1915 if (XD_STATE(iorq->mode) != XD_SUB_POLL &&
1916 XD_STATE(iorq->mode) != XD_SUB_WAIT &&
1917 XD_STATE(iorq->mode) != XD_SUB_NORM)
1918 /* is it active? */
1919 continue;
1920
1921 xdcsc->nrun--; /* it isn't running any more */
1922 if (blastmode == XD_RSET_ALL || blastmode != lcv) {
1923 /* failed */
1924 iorq->errno = error;
1925 xdcsc->iopbase[lcv].done = xdcsc->iopbase[lcv].errs = 1;
1926 switch (XD_STATE(xdcsc->reqs[lcv].mode)) {
1927 case XD_SUB_NORM:
1928 iorq->buf->b_error = EIO;
1929 iorq->buf->b_flags |= B_ERROR;
1930 iorq->buf->b_resid =
1931 iorq->sectcnt * XDFM_BPS;
1932
1933 bus_dmamap_sync(xdcsc->dmatag, iorq->dmamap, 0,
1934 iorq->dmamap->dm_mapsize,
1935 (iorq->buf->b_flags & B_READ)
1936 ? BUS_DMASYNC_POSTREAD
1937 : BUS_DMASYNC_POSTWRITE);
1938
1939 bus_dmamap_unload(xdcsc->dmatag, iorq->dmamap);
1940
1941 disk_unbusy(&xdcsc->reqs[lcv].xd->sc_dk,
1942 (xdcsc->reqs[lcv].buf->b_bcount -
1943 xdcsc->reqs[lcv].buf->b_resid));
1944 biodone(iorq->buf);
1945 XDC_FREE(xdcsc, lcv); /* add to free list */
1946 break;
1947 case XD_SUB_WAIT:
1948 wakeup(iorq);
1949 case XD_SUB_POLL:
1950 xdcsc->ndone++;
1951 iorq->mode =
1952 XD_NEWSTATE(iorq->mode, XD_SUB_DONE);
1953 break;
1954 }
1955
1956 } else {
1957
1958 /* resubmit, put at front of wait queue */
1959 XDC_HWAIT(xdcsc, lcv);
1960 }
1961 }
1962
1963 /*
1964 * now, if stuff is waiting, start it.
1965 * since we just reset it should go
1966 */
1967 xdc_start(xdcsc, XDC_MAXIOPB);
1968
1969 /* ok, we did it */
1970 if (oldfree == 0 && xdcsc->nfree)
1971 wakeup(&xdcsc->nfree);
1972
1973 #ifdef XDC_DIAG
1974 del = xdcsc->nwait + xdcsc->nrun + xdcsc->nfree + xdcsc->ndone;
1975 if (del != XDC_MAXIOPB)
1976 printf("%s: diag: xdc_reset miscount (%d should be %d)!\n",
1977 xdcsc->sc_dev.dv_xname, del, XDC_MAXIOPB);
1978 else
1979 if (xdcsc->ndone > XDC_MAXIOPB - XDC_SUBWAITLIM)
1980 printf("%s: diag: lots of done jobs (%d)\n",
1981 xdcsc->sc_dev.dv_xname, xdcsc->ndone);
1982 #endif
1983 printf("RESET DONE\n");
1984 return (retval);
1985 }
1986 /*
1987 * xdc_start: start all waiting buffers
1988 */
1989
1990 void
1991 xdc_start(xdcsc, maxio)
1992 struct xdc_softc *xdcsc;
1993 int maxio;
1994
1995 {
1996 int rqno;
1997 while (maxio && xdcsc->nwait &&
1998 (xdcsc->xdc->xdc_csr & XDC_ADDING) == 0) {
1999 XDC_GET_WAITER(xdcsc, rqno); /* note: rqno is an "out"
2000 * param */
2001 if (xdc_submit_iorq(xdcsc, rqno, XD_SUB_NOQ) != XD_ERR_AOK)
2002 panic("xdc_start"); /* should never happen */
2003 maxio--;
2004 }
2005 }
2006 /*
2007 * xdc_remove_iorq: remove "done" IOPB's.
2008 */
2009
2010 int
2011 xdc_remove_iorq(xdcsc)
2012 struct xdc_softc *xdcsc;
2013
2014 {
2015 int errno, rqno, comm, errs;
2016 struct xdc *xdc = xdcsc->xdc;
2017 struct xd_iopb *iopb;
2018 struct xd_iorq *iorq;
2019 struct buf *bp;
2020
2021 if (xdc->xdc_csr & XDC_F_ERROR) {
2022 /*
2023 * FATAL ERROR: should never happen under normal use. This
2024 * error is so bad, you can't even tell which IOPB is bad, so
2025 * we dump them all.
2026 */
2027 errno = xdc->xdc_f_err;
2028 printf("%s: fatal error 0x%02x: %s\n", xdcsc->sc_dev.dv_xname,
2029 errno, xdc_e2str(errno));
2030 if (xdc_reset(xdcsc, 0, XD_RSET_ALL, errno, 0) != XD_ERR_AOK) {
2031 printf("%s: soft reset failed!\n",
2032 xdcsc->sc_dev.dv_xname);
2033 panic("xdc_remove_iorq: controller DEAD");
2034 }
2035 return (XD_ERR_AOK);
2036 }
2037
2038 /*
2039 * get iopb that is done
2040 *
2041 * hmm... I used to read the address of the done IOPB off the VME
2042 * registers and calculate the rqno directly from that. that worked
2043 * until I started putting a load on the controller. when loaded, i
2044 * would get interrupts but neither the REMIOPB or F_ERROR bits would
2045 * be set, even after DELAY'ing a while! later on the timeout
2046 * routine would detect IOPBs that were marked "running" but their
2047 * "done" bit was set. rather than dealing directly with this
2048 * problem, it is just easier to look at all running IOPB's for the
2049 * done bit.
2050 */
2051 if (xdc->xdc_csr & XDC_REMIOPB) {
2052 xdc->xdc_csr = XDC_CLRRIO;
2053 }
2054
2055 for (rqno = 0; rqno < XDC_MAXIOPB; rqno++) {
2056 iorq = &xdcsc->reqs[rqno];
2057 if (iorq->mode == 0 || XD_STATE(iorq->mode) == XD_SUB_DONE)
2058 continue; /* free, or done */
2059 iopb = &xdcsc->iopbase[rqno];
2060 if (iopb->done == 0)
2061 continue; /* not done yet */
2062
2063 #ifdef XDC_DEBUG
2064 {
2065 u_char *rio = (u_char *) iopb;
2066 int sz = sizeof(struct xd_iopb), lcv;
2067 printf("%s: rio #%d [", xdcsc->sc_dev.dv_xname, rqno);
2068 for (lcv = 0; lcv < sz; lcv++)
2069 printf(" %02x", rio[lcv]);
2070 printf("]\n");
2071 }
2072 #endif /* XDC_DEBUG */
2073
2074 xdcsc->nrun--;
2075
2076 comm = iopb->comm;
2077 errs = iopb->errs;
2078
2079 if (errs)
2080 iorq->errno = iopb->errno;
2081 else
2082 iorq->errno = 0;
2083
2084 /* handle non-fatal errors */
2085
2086 if (errs &&
2087 xdc_error(xdcsc, iorq, iopb, rqno, comm) == XD_ERR_AOK)
2088 continue; /* AOK: we resubmitted it */
2089
2090
2091 /* this iorq is now done (hasn't been restarted or anything) */
2092
2093 if ((iorq->mode & XD_MODE_VERBO) && iorq->lasterror)
2094 xdc_perror(iorq, iopb, 0);
2095
2096 /* now, if read/write check to make sure we got all the data
2097 * we needed. (this may not be the case if we got an error in
2098 * the middle of a multisector request). */
2099
2100 if ((iorq->mode & XD_MODE_B144) != 0 && errs == 0 &&
2101 (comm == XDCMD_RD || comm == XDCMD_WR)) {
2102 /* we just successfully processed a bad144 sector
2103 * note: if we are in bad 144 mode, the pointers have
2104 * been advanced already (see above) and are pointing
2105 * at the bad144 sector. to exit bad144 mode, we
2106 * must advance the pointers 1 sector and issue a new
2107 * request if there are still sectors left to process
2108 *
2109 */
2110 XDC_ADVANCE(iorq, 1); /* advance 1 sector */
2111
2112 /* exit b144 mode */
2113 iorq->mode = iorq->mode & (~XD_MODE_B144);
2114
2115 if (iorq->sectcnt) { /* more to go! */
2116 iorq->lasterror = iorq->errno = iopb->errno = 0;
2117 iopb->errs = iopb->done = 0;
2118 iorq->tries = 0;
2119 iopb->sectcnt = iorq->sectcnt;
2120 iopb->cylno = iorq->blockno /
2121 iorq->xd->sectpercyl;
2122 iopb->headno =
2123 (iorq->blockno / iorq->xd->nhead) %
2124 iorq->xd->nhead;
2125 iopb->sectno = iorq->blockno % XDFM_BPS;
2126 iopb->daddr = (u_long) iorq->dbuf;
2127 XDC_HWAIT(xdcsc, rqno);
2128 xdc_start(xdcsc, 1); /* resubmit */
2129 continue;
2130 }
2131 }
2132 /* final cleanup, totally done with this request */
2133
2134 switch (XD_STATE(iorq->mode)) {
2135 case XD_SUB_NORM:
2136 bp = iorq->buf;
2137 if (errs) {
2138 bp->b_error = EIO;
2139 bp->b_flags |= B_ERROR;
2140 bp->b_resid = iorq->sectcnt * XDFM_BPS;
2141 } else {
2142 bp->b_resid = 0; /* done */
2143 }
2144 bus_dmamap_sync(xdcsc->dmatag, iorq->dmamap, 0,
2145 iorq->dmamap->dm_mapsize,
2146 (bp->b_flags & B_READ)
2147 ? BUS_DMASYNC_POSTREAD
2148 : BUS_DMASYNC_POSTWRITE);
2149 bus_dmamap_unload(xdcsc->dmatag, iorq->dmamap);
2150
2151 disk_unbusy(&iorq->xd->sc_dk,
2152 (bp->b_bcount - bp->b_resid));
2153 XDC_FREE(xdcsc, rqno);
2154 biodone(bp);
2155 break;
2156 case XD_SUB_WAIT:
2157 iorq->mode = XD_NEWSTATE(iorq->mode, XD_SUB_DONE);
2158 xdcsc->ndone++;
2159 wakeup(iorq);
2160 break;
2161 case XD_SUB_POLL:
2162 iorq->mode = XD_NEWSTATE(iorq->mode, XD_SUB_DONE);
2163 xdcsc->ndone++;
2164 break;
2165 }
2166 }
2167
2168 return (XD_ERR_AOK);
2169 }
2170
2171 /*
2172 * xdc_perror: print error.
2173 * - if still_trying is true: we got an error, retried and got a
2174 * different error. in that case lasterror is the old error,
2175 * and errno is the new one.
2176 * - if still_trying is not true, then if we ever had an error it
2177 * is in lasterror. also, if iorq->errno == 0, then we recovered
2178 * from that error (otherwise iorq->errno == iorq->lasterror).
2179 */
2180 void
2181 xdc_perror(iorq, iopb, still_trying)
2182 struct xd_iorq *iorq;
2183 struct xd_iopb *iopb;
2184 int still_trying;
2185
2186 {
2187
2188 int error = iorq->lasterror;
2189
2190 printf("%s", (iorq->xd) ? iorq->xd->sc_dev.dv_xname
2191 : iorq->xdc->sc_dev.dv_xname);
2192 if (iorq->buf)
2193 printf("%c: ", 'a' + DISKPART(iorq->buf->b_dev));
2194 if (iopb->comm == XDCMD_RD || iopb->comm == XDCMD_WR)
2195 printf("%s %d/%d/%d: ",
2196 (iopb->comm == XDCMD_RD) ? "read" : "write",
2197 iopb->cylno, iopb->headno, iopb->sectno);
2198 printf("%s", xdc_e2str(error));
2199
2200 if (still_trying)
2201 printf(" [still trying, new error=%s]", xdc_e2str(iorq->errno));
2202 else
2203 if (iorq->errno == 0)
2204 printf(" [recovered in %d tries]", iorq->tries);
2205
2206 printf("\n");
2207 }
2208
2209 /*
2210 * xdc_error: non-fatal error encountered... recover.
2211 * return AOK if resubmitted, return FAIL if this iopb is done
2212 */
2213 int
2214 xdc_error(xdcsc, iorq, iopb, rqno, comm)
2215 struct xdc_softc *xdcsc;
2216 struct xd_iorq *iorq;
2217 struct xd_iopb *iopb;
2218 int rqno, comm;
2219
2220 {
2221 int errno = iorq->errno;
2222 int erract = errno & XD_ERA_MASK;
2223 int oldmode, advance;
2224 #ifdef __sparc__
2225 int i;
2226 #endif
2227
2228 if (erract == XD_ERA_RSET) { /* some errors require a reset */
2229 oldmode = iorq->mode;
2230 iorq->mode = XD_SUB_DONE | (~XD_SUB_MASK & oldmode);
2231 xdcsc->ndone++;
2232 /* make xdc_start ignore us */
2233 xdc_reset(xdcsc, 1, XD_RSET_NONE, errno, iorq->xd);
2234 iorq->mode = oldmode;
2235 xdcsc->ndone--;
2236 }
2237 /* check for read/write to a sector in bad144 table if bad: redirect
2238 * request to bad144 area */
2239
2240 if ((comm == XDCMD_RD || comm == XDCMD_WR) &&
2241 (iorq->mode & XD_MODE_B144) == 0) {
2242 advance = iorq->sectcnt - iopb->sectcnt;
2243 XDC_ADVANCE(iorq, advance);
2244 #ifdef __sparc__
2245 if ((i = isbad(&iorq->xd->dkb, iorq->blockno / iorq->xd->sectpercyl,
2246 (iorq->blockno / iorq->xd->nsect) % iorq->xd->nhead,
2247 iorq->blockno % iorq->xd->nsect)) != -1) {
2248 iorq->mode |= XD_MODE_B144; /* enter bad144 mode &
2249 * redirect */
2250 iopb->errno = iopb->done = iopb->errs = 0;
2251 iopb->sectcnt = 1;
2252 iopb->cylno = (iorq->xd->ncyl + iorq->xd->acyl) - 2;
2253 /* second to last acyl */
2254 i = iorq->xd->sectpercyl - 1 - i; /* follow bad144
2255 * standard */
2256 iopb->headno = i / iorq->xd->nhead;
2257 iopb->sectno = i % iorq->xd->nhead;
2258 XDC_HWAIT(xdcsc, rqno);
2259 xdc_start(xdcsc, 1); /* resubmit */
2260 return (XD_ERR_AOK); /* recovered! */
2261 }
2262 #endif
2263 }
2264
2265 /*
2266 * it isn't a bad144 sector, must be real error! see if we can retry
2267 * it?
2268 */
2269 if ((iorq->mode & XD_MODE_VERBO) && iorq->lasterror)
2270 xdc_perror(iorq, iopb, 1); /* inform of error state
2271 * change */
2272 iorq->lasterror = errno;
2273
2274 if ((erract == XD_ERA_RSET || erract == XD_ERA_HARD)
2275 && iorq->tries < XDC_MAXTRIES) { /* retry? */
2276 iorq->tries++;
2277 iorq->errno = iopb->errno = iopb->done = iopb->errs = 0;
2278 XDC_HWAIT(xdcsc, rqno);
2279 xdc_start(xdcsc, 1); /* restart */
2280 return (XD_ERR_AOK); /* recovered! */
2281 }
2282
2283 /* failed to recover from this error */
2284 return (XD_ERR_FAIL);
2285 }
2286
2287 /*
2288 * xdc_tick: make sure xd is still alive and ticking (err, kicking).
2289 */
2290 void
2291 xdc_tick(arg)
2292 void *arg;
2293
2294 {
2295 struct xdc_softc *xdcsc = arg;
2296 int lcv, s, reset = 0;
2297 #ifdef XDC_DIAG
2298 int wait, run, free, done, whd = 0;
2299 u_char fqc[XDC_MAXIOPB], wqc[XDC_MAXIOPB], mark[XDC_MAXIOPB];
2300 s = splbio();
2301 wait = xdcsc->nwait;
2302 run = xdcsc->nrun;
2303 free = xdcsc->nfree;
2304 done = xdcsc->ndone;
2305 bcopy(xdcsc->waitq, wqc, sizeof(wqc));
2306 bcopy(xdcsc->freereq, fqc, sizeof(fqc));
2307 splx(s);
2308 if (wait + run + free + done != XDC_MAXIOPB) {
2309 printf("%s: diag: IOPB miscount (got w/f/r/d %d/%d/%d/%d, wanted %d)\n",
2310 xdcsc->sc_dev.dv_xname, wait, free, run, done, XDC_MAXIOPB);
2311 bzero(mark, sizeof(mark));
2312 printf("FREE: ");
2313 for (lcv = free; lcv > 0; lcv--) {
2314 printf("%d ", fqc[lcv - 1]);
2315 mark[fqc[lcv - 1]] = 1;
2316 }
2317 printf("\nWAIT: ");
2318 lcv = wait;
2319 while (lcv > 0) {
2320 printf("%d ", wqc[whd]);
2321 mark[wqc[whd]] = 1;
2322 whd = (whd + 1) % XDC_MAXIOPB;
2323 lcv--;
2324 }
2325 printf("\n");
2326 for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) {
2327 if (mark[lcv] == 0)
2328 printf("MARK: running %d: mode %d done %d errs %d errno 0x%x ttl %d buf %p\n",
2329 lcv, xdcsc->reqs[lcv].mode,
2330 xdcsc->iopbase[lcv].done,
2331 xdcsc->iopbase[lcv].errs,
2332 xdcsc->iopbase[lcv].errno,
2333 xdcsc->reqs[lcv].ttl, xdcsc->reqs[lcv].buf);
2334 }
2335 } else
2336 if (done > XDC_MAXIOPB - XDC_SUBWAITLIM)
2337 printf("%s: diag: lots of done jobs (%d)\n",
2338 xdcsc->sc_dev.dv_xname, done);
2339
2340 #endif
2341 #ifdef XDC_DEBUG
2342 printf("%s: tick: csr 0x%x, w/f/r/d %d/%d/%d/%d\n",
2343 xdcsc->sc_dev.dv_xname,
2344 xdcsc->xdc->xdc_csr, xdcsc->nwait, xdcsc->nfree, xdcsc->nrun,
2345 xdcsc->ndone);
2346 for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) {
2347 if (xdcsc->reqs[lcv].mode)
2348 printf("running %d: mode %d done %d errs %d errno 0x%x\n",
2349 lcv,
2350 xdcsc->reqs[lcv].mode, xdcsc->iopbase[lcv].done,
2351 xdcsc->iopbase[lcv].errs, xdcsc->iopbase[lcv].errno);
2352 }
2353 #endif
2354
2355 /* reduce ttl for each request if one goes to zero, reset xdc */
2356 s = splbio();
2357 for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) {
2358 if (xdcsc->reqs[lcv].mode == 0 ||
2359 XD_STATE(xdcsc->reqs[lcv].mode) == XD_SUB_DONE)
2360 continue;
2361 xdcsc->reqs[lcv].ttl--;
2362 if (xdcsc->reqs[lcv].ttl == 0)
2363 reset = 1;
2364 }
2365 if (reset) {
2366 printf("%s: watchdog timeout\n", xdcsc->sc_dev.dv_xname);
2367 xdc_reset(xdcsc, 0, XD_RSET_NONE, XD_ERR_FAIL, NULL);
2368 }
2369 splx(s);
2370
2371 /* until next time */
2372
2373 callout_reset(&xdcsc->sc_tick_ch, XDC_TICKCNT, xdc_tick, xdcsc);
2374 }
2375
2376 /*
2377 * xdc_ioctlcmd: this function provides a user level interface to the
2378 * controller via ioctl. this allows "format" programs to be written
2379 * in user code, and is also useful for some debugging. we return
2380 * an error code. called at user priority.
2381 */
2382 int
2383 xdc_ioctlcmd(xd, dev, xio)
2384 struct xd_softc *xd;
2385 dev_t dev;
2386 struct xd_iocmd *xio;
2387
2388 {
2389 int s, rqno, dummy;
2390 caddr_t dvmabuf = NULL, buf = NULL;
2391 struct xdc_softc *xdcsc;
2392 int rseg, error;
2393 bus_dma_segment_t seg;
2394
2395 /* check sanity of requested command */
2396
2397 switch (xio->cmd) {
2398
2399 case XDCMD_NOP: /* no op: everything should be zero */
2400 if (xio->subfn || xio->dptr || xio->dlen ||
2401 xio->block || xio->sectcnt)
2402 return (EINVAL);
2403 break;
2404
2405 case XDCMD_RD: /* read / write sectors (up to XD_IOCMD_MAXS) */
2406 case XDCMD_WR:
2407 if (xio->subfn || xio->sectcnt > XD_IOCMD_MAXS ||
2408 xio->sectcnt * XDFM_BPS != xio->dlen || xio->dptr == NULL)
2409 return (EINVAL);
2410 break;
2411
2412 case XDCMD_SK: /* seek: doesn't seem useful to export this */
2413 return (EINVAL);
2414
2415 case XDCMD_WRP: /* write parameters */
2416 return (EINVAL);/* not useful, except maybe drive
2417 * parameters... but drive parameters should
2418 * go via disklabel changes */
2419
2420 case XDCMD_RDP: /* read parameters */
2421 if (xio->subfn != XDFUN_DRV ||
2422 xio->dlen || xio->block || xio->dptr)
2423 return (EINVAL); /* allow read drive params to
2424 * get hw_spt */
2425 xio->sectcnt = xd->hw_spt; /* we already know the answer */
2426 return (0);
2427 break;
2428
2429 case XDCMD_XRD: /* extended read/write */
2430 case XDCMD_XWR:
2431
2432 switch (xio->subfn) {
2433
2434 case XDFUN_THD:/* track headers */
2435 if (xio->sectcnt != xd->hw_spt ||
2436 (xio->block % xd->nsect) != 0 ||
2437 xio->dlen != XD_IOCMD_HSZ * xd->hw_spt ||
2438 xio->dptr == NULL)
2439 return (EINVAL);
2440 xio->sectcnt = 0;
2441 break;
2442
2443 case XDFUN_FMT:/* NOTE: also XDFUN_VFY */
2444 if (xio->cmd == XDCMD_XRD)
2445 return (EINVAL); /* no XDFUN_VFY */
2446 if (xio->sectcnt || xio->dlen ||
2447 (xio->block % xd->nsect) != 0 || xio->dptr)
2448 return (EINVAL);
2449 break;
2450
2451 case XDFUN_HDR:/* header, header verify, data, data ECC */
2452 return (EINVAL); /* not yet */
2453
2454 case XDFUN_DM: /* defect map */
2455 case XDFUN_DMX:/* defect map (alternate location) */
2456 if (xio->sectcnt || xio->dlen != XD_IOCMD_DMSZ ||
2457 (xio->block % xd->nsect) != 0 || xio->dptr == NULL)
2458 return (EINVAL);
2459 break;
2460
2461 default:
2462 return (EINVAL);
2463 }
2464 break;
2465
2466 case XDCMD_TST: /* diagnostics */
2467 return (EINVAL);
2468
2469 default:
2470 return (EINVAL);/* ??? */
2471 }
2472
2473 xdcsc = xd->parent;
2474
2475 /* create DVMA buffer for request if needed */
2476 if (xio->dlen) {
2477 if ((error = xd_dmamem_alloc(xdcsc->dmatag, xdcsc->auxmap,
2478 &seg, &rseg,
2479 xio->dlen, &buf,
2480 (bus_addr_t *)&dvmabuf)) != 0) {
2481 return (error);
2482 }
2483
2484 if (xio->cmd == XDCMD_WR || xio->cmd == XDCMD_XWR) {
2485 if ((error = copyin(xio->dptr, buf, xio->dlen)) != 0) {
2486 bus_dmamem_unmap(xdcsc->dmatag, buf, xio->dlen);
2487 bus_dmamem_free(xdcsc->dmatag, &seg, rseg);
2488 return (error);
2489 }
2490 }
2491 }
2492
2493 /* do it! */
2494
2495 error = 0;
2496 s = splbio();
2497 rqno = xdc_cmd(xdcsc, xio->cmd, xio->subfn, xd->xd_drive, xio->block,
2498 xio->sectcnt, dvmabuf, XD_SUB_WAIT);
2499 if (rqno == XD_ERR_FAIL) {
2500 error = EIO;
2501 goto done;
2502 }
2503 xio->errno = xdcsc->reqs[rqno].errno;
2504 xio->tries = xdcsc->reqs[rqno].tries;
2505 XDC_DONE(xdcsc, rqno, dummy);
2506
2507 if (xio->cmd == XDCMD_RD || xio->cmd == XDCMD_XRD)
2508 error = copyout(buf, xio->dptr, xio->dlen);
2509
2510 done:
2511 splx(s);
2512 if (dvmabuf) {
2513 xd_dmamem_free(xdcsc->dmatag, xdcsc->auxmap, &seg, rseg,
2514 xio->dlen, buf);
2515 }
2516 return (error);
2517 }
2518
2519 /*
2520 * xdc_e2str: convert error code number into an error string
2521 */
2522 char *
2523 xdc_e2str(no)
2524 int no;
2525 {
2526 switch (no) {
2527 case XD_ERR_FAIL:
2528 return ("Software fatal error");
2529 case XD_ERR_AOK:
2530 return ("Successful completion");
2531 case XD_ERR_ICYL:
2532 return ("Illegal cylinder address");
2533 case XD_ERR_IHD:
2534 return ("Illegal head address");
2535 case XD_ERR_ISEC:
2536 return ("Illgal sector address");
2537 case XD_ERR_CZER:
2538 return ("Count zero");
2539 case XD_ERR_UIMP:
2540 return ("Unimplemented command");
2541 case XD_ERR_IF1:
2542 return ("Illegal field length 1");
2543 case XD_ERR_IF2:
2544 return ("Illegal field length 2");
2545 case XD_ERR_IF3:
2546 return ("Illegal field length 3");
2547 case XD_ERR_IF4:
2548 return ("Illegal field length 4");
2549 case XD_ERR_IF5:
2550 return ("Illegal field length 5");
2551 case XD_ERR_IF6:
2552 return ("Illegal field length 6");
2553 case XD_ERR_IF7:
2554 return ("Illegal field length 7");
2555 case XD_ERR_ISG:
2556 return ("Illegal scatter/gather length");
2557 case XD_ERR_ISPT:
2558 return ("Not enough sectors per track");
2559 case XD_ERR_ALGN:
2560 return ("Next IOPB address alignment error");
2561 case XD_ERR_SGAL:
2562 return ("Scatter/gather address alignment error");
2563 case XD_ERR_SGEC:
2564 return ("Scatter/gather with auto-ECC");
2565 case XD_ERR_SECC:
2566 return ("Soft ECC corrected");
2567 case XD_ERR_SIGN:
2568 return ("ECC ignored");
2569 case XD_ERR_ASEK:
2570 return ("Auto-seek retry recovered");
2571 case XD_ERR_RTRY:
2572 return ("Soft retry recovered");
2573 case XD_ERR_HECC:
2574 return ("Hard data ECC");
2575 case XD_ERR_NHDR:
2576 return ("Header not found");
2577 case XD_ERR_NRDY:
2578 return ("Drive not ready");
2579 case XD_ERR_TOUT:
2580 return ("Operation timeout");
2581 case XD_ERR_VTIM:
2582 return ("VMEDMA timeout");
2583 case XD_ERR_DSEQ:
2584 return ("Disk sequencer error");
2585 case XD_ERR_HDEC:
2586 return ("Header ECC error");
2587 case XD_ERR_RVFY:
2588 return ("Read verify");
2589 case XD_ERR_VFER:
2590 return ("Fatail VMEDMA error");
2591 case XD_ERR_VBUS:
2592 return ("VMEbus error");
2593 case XD_ERR_DFLT:
2594 return ("Drive faulted");
2595 case XD_ERR_HECY:
2596 return ("Header error/cyliner");
2597 case XD_ERR_HEHD:
2598 return ("Header error/head");
2599 case XD_ERR_NOCY:
2600 return ("Drive not on-cylinder");
2601 case XD_ERR_SEEK:
2602 return ("Seek error");
2603 case XD_ERR_ILSS:
2604 return ("Illegal sector size");
2605 case XD_ERR_SEC:
2606 return ("Soft ECC");
2607 case XD_ERR_WPER:
2608 return ("Write-protect error");
2609 case XD_ERR_IRAM:
2610 return ("IRAM self test failure");
2611 case XD_ERR_MT3:
2612 return ("Maintenance test 3 failure (DSKCEL RAM)");
2613 case XD_ERR_MT4:
2614 return ("Maintenance test 4 failure (header shift reg)");
2615 case XD_ERR_MT5:
2616 return ("Maintenance test 5 failure (VMEDMA regs)");
2617 case XD_ERR_MT6:
2618 return ("Maintenance test 6 failure (REGCEL chip)");
2619 case XD_ERR_MT7:
2620 return ("Maintenance test 7 failure (buffer parity)");
2621 case XD_ERR_MT8:
2622 return ("Maintenance test 8 failure (disk FIFO)");
2623 case XD_ERR_IOCK:
2624 return ("IOPB checksum miscompare");
2625 case XD_ERR_IODM:
2626 return ("IOPB DMA fatal");
2627 case XD_ERR_IOAL:
2628 return ("IOPB address alignment error");
2629 case XD_ERR_FIRM:
2630 return ("Firmware error");
2631 case XD_ERR_MMOD:
2632 return ("Illegal maintenance mode test number");
2633 case XD_ERR_ACFL:
2634 return ("ACFAIL asserted");
2635 default:
2636 return ("Unknown error");
2637 }
2638 }
2639