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