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