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