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