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