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