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