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