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