esp_sbus.c revision 1.16 1 /* $NetBSD: esp_sbus.c,v 1.16 2001/09/26 20:53:14 eeh Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center; Paul Kranenburg.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44 #include <sys/buf.h>
45 #include <sys/malloc.h>
46
47 #include <dev/scsipi/scsi_all.h>
48 #include <dev/scsipi/scsipi_all.h>
49 #include <dev/scsipi/scsiconf.h>
50 #include <dev/scsipi/scsi_message.h>
51
52 #include <machine/bus.h>
53 #include <machine/intr.h>
54 #include <machine/autoconf.h>
55
56 #include <dev/ic/lsi64854reg.h>
57 #include <dev/ic/lsi64854var.h>
58
59 #include <dev/ic/ncr53c9xreg.h>
60 #include <dev/ic/ncr53c9xvar.h>
61
62 #include <dev/sbus/sbusvar.h>
63
64 /* #define ESP_SBUS_DEBUG */
65
66 struct esp_softc {
67 struct ncr53c9x_softc sc_ncr53c9x; /* glue to MI code */
68 struct sbusdev sc_sd; /* sbus device */
69
70 bus_space_tag_t sc_bustag;
71 bus_dma_tag_t sc_dmatag;
72
73 bus_space_handle_t sc_reg; /* the registers */
74 struct lsi64854_softc *sc_dma; /* pointer to my dma */
75
76 int sc_pri; /* SBUS priority */
77 };
78
79 void espattach_sbus __P((struct device *, struct device *, void *));
80 void espattach_dma __P((struct device *, struct device *, void *));
81 int espmatch_sbus __P((struct device *, struct cfdata *, void *));
82
83
84 /* Linkup to the rest of the kernel */
85 struct cfattach esp_sbus_ca = {
86 sizeof(struct esp_softc), espmatch_sbus, espattach_sbus
87 };
88 struct cfattach esp_dma_ca = {
89 sizeof(struct esp_softc), espmatch_sbus, espattach_dma
90 };
91
92 /*
93 * Functions and the switch for the MI code.
94 */
95 static u_char esp_read_reg __P((struct ncr53c9x_softc *, int));
96 static void esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
97 static u_char esp_rdreg1 __P((struct ncr53c9x_softc *, int));
98 static void esp_wrreg1 __P((struct ncr53c9x_softc *, int, u_char));
99 static int esp_dma_isintr __P((struct ncr53c9x_softc *));
100 static void esp_dma_reset __P((struct ncr53c9x_softc *));
101 static int esp_dma_intr __P((struct ncr53c9x_softc *));
102 static int esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
103 size_t *, int, size_t *));
104 static void esp_dma_go __P((struct ncr53c9x_softc *));
105 static void esp_dma_stop __P((struct ncr53c9x_softc *));
106 static int esp_dma_isactive __P((struct ncr53c9x_softc *));
107
108 static struct ncr53c9x_glue esp_sbus_glue = {
109 esp_read_reg,
110 esp_write_reg,
111 esp_dma_isintr,
112 esp_dma_reset,
113 esp_dma_intr,
114 esp_dma_setup,
115 esp_dma_go,
116 esp_dma_stop,
117 esp_dma_isactive,
118 NULL, /* gl_clear_latched_intr */
119 };
120
121 static struct ncr53c9x_glue esp_sbus_glue1 = {
122 esp_rdreg1,
123 esp_wrreg1,
124 esp_dma_isintr,
125 esp_dma_reset,
126 esp_dma_intr,
127 esp_dma_setup,
128 esp_dma_go,
129 esp_dma_stop,
130 esp_dma_isactive,
131 NULL, /* gl_clear_latched_intr */
132 };
133
134 static void espattach __P((struct esp_softc *, struct ncr53c9x_glue *));
135
136 int
137 espmatch_sbus(parent, cf, aux)
138 struct device *parent;
139 struct cfdata *cf;
140 void *aux;
141 {
142 int rv;
143 struct sbus_attach_args *sa = aux;
144
145 if (strcmp("SUNW,fas", sa->sa_name) == 0)
146 return 1;
147
148 rv = (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 ||
149 strcmp("ptscII", sa->sa_name) == 0);
150 return (rv);
151 }
152
153 void
154 espattach_sbus(parent, self, aux)
155 struct device *parent, *self;
156 void *aux;
157 {
158 struct esp_softc *esc = (void *)self;
159 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
160 struct sbus_attach_args *sa = aux;
161 struct lsi64854_softc *lsc;
162 int burst, sbusburst;
163
164 esc->sc_bustag = sa->sa_bustag;
165 esc->sc_dmatag = sa->sa_dmatag;
166
167 sc->sc_id = PROM_getpropint(sa->sa_node, "initiator-id", 7);
168 sc->sc_freq = PROM_getpropint(sa->sa_node, "clock-frequency", -1);
169 if (sc->sc_freq < 0)
170 sc->sc_freq = ((struct sbus_softc *)
171 sc->sc_dev.dv_parent)->sc_clockfreq;
172
173 #ifdef ESP_SBUS_DEBUG
174 printf("%s: espattach_sbus: sc_id %d, freq %d\n",
175 self->dv_xname, sc->sc_id, sc->sc_freq);
176 #endif
177
178 if (strcmp("SUNW,fas", sa->sa_name) == 0) {
179
180 /*
181 * fas has 2 register spaces: dma(lsi64854) and SCSI core (ncr53c9x)
182 */
183 if (sa->sa_nreg != 2) {
184 printf("%s: %d register spaces\n", self->dv_xname, sa->sa_nreg);
185 return;
186 }
187
188 /*
189 * allocate space for dma, in SUNW,fas there are no separate
190 * dma device
191 */
192 lsc = malloc(sizeof (struct lsi64854_softc), M_DEVBUF, M_NOWAIT);
193
194 if (lsc == NULL) {
195 printf("%s: out of memory (lsi64854_softc)\n",
196 self->dv_xname);
197 return;
198 }
199 esc->sc_dma = lsc;
200
201 lsc->sc_bustag = sa->sa_bustag;
202 lsc->sc_dmatag = sa->sa_dmatag;
203
204 bcopy(sc->sc_dev.dv_xname, lsc->sc_dev.dv_xname,
205 sizeof (lsc->sc_dev.dv_xname));
206
207 /* Map dma registers */
208 if (bus_space_map2(sa->sa_bustag,
209 sa->sa_reg[0].sbr_slot,
210 sa->sa_reg[0].sbr_offset,
211 sa->sa_reg[0].sbr_size,
212 BUS_SPACE_MAP_LINEAR,
213 0, &lsc->sc_regs) != 0) {
214 printf("%s: cannot map dma registers\n", self->dv_xname);
215 return;
216 }
217
218 /*
219 * XXX is this common(from bpp.c), the same in dma_sbus...etc.
220 *
221 * Get transfer burst size from PROM and plug it into the
222 * controller registers. This is needed on the Sun4m; do
223 * others need it too?
224 */
225 sbusburst = ((struct sbus_softc *)parent)->sc_burst;
226 if (sbusburst == 0)
227 sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
228
229 burst = PROM_getpropint(sa->sa_node, "burst-sizes", -1);
230
231 #if ESP_SBUS_DEBUG
232 printf("espattach_sbus: burst 0x%x, sbus 0x%x\n",
233 burst, sbusburst);
234 #endif
235
236 if (burst == -1)
237 /* take SBus burst sizes */
238 burst = sbusburst;
239
240 /* Clamp at parent's burst sizes */
241 burst &= sbusburst;
242 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
243 (burst & SBUS_BURST_16) ? 16 : 0;
244
245 lsc->sc_channel = L64854_CHANNEL_SCSI;
246 lsc->sc_client = sc;
247
248 lsi64854_attach(lsc);
249
250 /*
251 * map SCSI core registers
252 */
253 if (sbus_bus_map(sa->sa_bustag,
254 sa->sa_reg[1].sbr_slot,
255 sa->sa_reg[1].sbr_offset,
256 sa->sa_reg[1].sbr_size,
257 BUS_SPACE_MAP_LINEAR,
258 0, &esc->sc_reg) != 0) {
259 printf("%s @ sbus: cannot map scsi core registers\n",
260 self->dv_xname);
261 return;
262 }
263
264 if (sa->sa_nintr == 0) {
265 printf("\n%s: no interrupt property\n", self->dv_xname);
266 return;
267 }
268
269 esc->sc_pri = sa->sa_pri;
270
271 /* add me to the sbus structures */
272 esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
273 sbus_establish(&esc->sc_sd, &sc->sc_dev);
274
275 espattach(esc, &esp_sbus_glue);
276
277 return;
278 }
279
280 /*
281 * Find the DMA by poking around the dma device structures
282 *
283 * What happens here is that if the dma driver has not been
284 * configured, then this returns a NULL pointer. Then when the
285 * dma actually gets configured, it does the opposing test, and
286 * if the sc->sc_esp field in it's softc is NULL, then tries to
287 * find the matching esp driver.
288 */
289 esc->sc_dma = (struct lsi64854_softc *)
290 getdevunit("dma", sc->sc_dev.dv_unit);
291
292 /*
293 * and a back pointer to us, for DMA
294 */
295 if (esc->sc_dma)
296 esc->sc_dma->sc_client = sc;
297 else {
298 printf("\n");
299 panic("espattach: no dma found");
300 }
301
302 /*
303 * The `ESC' DMA chip must be reset before we can access
304 * the esp registers.
305 */
306 if (esc->sc_dma->sc_rev == DMAREV_ESC)
307 DMA_RESET(esc->sc_dma);
308
309 /*
310 * Map my registers in, if they aren't already in virtual
311 * address space.
312 */
313 if (sa->sa_npromvaddrs)
314 esc->sc_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
315 else {
316 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
317 sa->sa_offset,
318 sa->sa_size,
319 BUS_SPACE_MAP_LINEAR,
320 0, &esc->sc_reg) != 0) {
321 printf("%s @ sbus: cannot map registers\n",
322 self->dv_xname);
323 return;
324 }
325 }
326
327 if (sa->sa_nintr == 0) {
328 /*
329 * No interrupt properties: we quit; this might
330 * happen on e.g. a Sparc X terminal.
331 */
332 printf("\n%s: no interrupt property\n", self->dv_xname);
333 return;
334 }
335
336 esc->sc_pri = sa->sa_pri;
337
338 /* add me to the sbus structures */
339 esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
340 sbus_establish(&esc->sc_sd, &sc->sc_dev);
341
342 if (strcmp("ptscII", sa->sa_name) == 0) {
343 espattach(esc, &esp_sbus_glue1);
344 } else {
345 espattach(esc, &esp_sbus_glue);
346 }
347 }
348
349 void
350 espattach_dma(parent, self, aux)
351 struct device *parent, *self;
352 void *aux;
353 {
354 struct esp_softc *esc = (void *)self;
355 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
356 struct sbus_attach_args *sa = aux;
357
358 if (strcmp("ptscII", sa->sa_name) == 0) {
359 return;
360 }
361
362 esc->sc_bustag = sa->sa_bustag;
363 esc->sc_dmatag = sa->sa_dmatag;
364
365 sc->sc_id = PROM_getpropint(sa->sa_node, "initiator-id", 7);
366 sc->sc_freq = PROM_getpropint(sa->sa_node, "clock-frequency", -1);
367
368 esc->sc_dma = (struct lsi64854_softc *)parent;
369 esc->sc_dma->sc_client = sc;
370
371 /*
372 * Map my registers in, if they aren't already in virtual
373 * address space.
374 */
375 if (sa->sa_npromvaddrs)
376 esc->sc_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
377 else {
378 if (bus_space_map2(sa->sa_bustag,
379 sa->sa_slot,
380 sa->sa_offset,
381 sa->sa_size,
382 BUS_SPACE_MAP_LINEAR,
383 0, &esc->sc_reg) != 0) {
384 printf("%s @ dma: cannot map registers\n",
385 self->dv_xname);
386 return;
387 }
388 }
389
390 if (sa->sa_nintr == 0) {
391 /*
392 * No interrupt properties: we quit; this might
393 * happen on e.g. a Sparc X terminal.
394 */
395 printf("\n%s: no interrupt property\n", self->dv_xname);
396 return;
397 }
398
399 esc->sc_pri = sa->sa_pri;
400
401 /* Assume SBus is grandparent */
402 esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
403 sbus_establish(&esc->sc_sd, parent);
404
405 espattach(esc, &esp_sbus_glue);
406 }
407
408
409 /*
410 * Attach this instance, and then all the sub-devices
411 */
412 void
413 espattach(esc, gluep)
414 struct esp_softc *esc;
415 struct ncr53c9x_glue *gluep;
416 {
417 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
418 void *icookie;
419 unsigned int uid = 0;
420
421 /*
422 * Set up glue for MI code early; we use some of it here.
423 */
424 sc->sc_glue = gluep;
425
426 /* gimme Mhz */
427 sc->sc_freq /= 1000000;
428
429 /*
430 * XXX More of this should be in ncr53c9x_attach(), but
431 * XXX should we really poke around the chip that much in
432 * XXX the MI code? Think about this more...
433 */
434
435 /*
436 * It is necessary to try to load the 2nd config register here,
437 * to find out what rev the esp chip is, else the ncr53c9x_reset
438 * will not set up the defaults correctly.
439 */
440 sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
441 sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_RPE;
442 sc->sc_cfg3 = NCRCFG3_CDB;
443 NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
444
445 if ((NCR_READ_REG(sc, NCR_CFG2) & ~NCRCFG2_RSVD) !=
446 (NCRCFG2_SCSI2 | NCRCFG2_RPE)) {
447 sc->sc_rev = NCR_VARIANT_ESP100;
448 } else {
449 sc->sc_cfg2 = NCRCFG2_SCSI2;
450 NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
451 sc->sc_cfg3 = 0;
452 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
453 sc->sc_cfg3 = (NCRCFG3_CDB | NCRCFG3_FCLK);
454 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
455 if (NCR_READ_REG(sc, NCR_CFG3) !=
456 (NCRCFG3_CDB | NCRCFG3_FCLK)) {
457 sc->sc_rev = NCR_VARIANT_ESP100A;
458 } else {
459 /* NCRCFG2_FE enables > 64K transfers */
460 sc->sc_cfg2 |= NCRCFG2_FE;
461 sc->sc_cfg3 = 0;
462 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
463 sc->sc_rev = NCR_VARIANT_ESP200;
464
465 /* XXX spec says it's valid after power up or chip reset */
466 uid = NCR_READ_REG(sc, NCR_UID);
467 if (((uid & 0xf8) >> 3) == 0x0a) /* XXX */
468 sc->sc_rev = NCR_VARIANT_FAS366;
469 }
470 }
471
472 #ifdef ESP_SBUS_DEBUG
473 printf("espattach: revision %d, uid 0x%x\n", sc->sc_rev, uid);
474 #endif
475
476 /*
477 * XXX minsync and maxxfer _should_ be set up in MI code,
478 * XXX but it appears to have some dependency on what sort
479 * XXX of DMA we're hooked up to, etc.
480 */
481
482 /*
483 * This is the value used to start sync negotiations
484 * Note that the NCR register "SYNCTP" is programmed
485 * in "clocks per byte", and has a minimum value of 4.
486 * The SCSI period used in negotiation is one-fourth
487 * of the time (in nanoseconds) needed to transfer one byte.
488 * Since the chip's clock is given in MHz, we have the following
489 * formula: 4 * period = (1000 / freq) * 4
490 */
491 sc->sc_minsync = 1000 / sc->sc_freq;
492
493 /*
494 * Alas, we must now modify the value a bit, because it's
495 * only valid when can switch on FASTCLK and FASTSCSI bits
496 * in config register 3...
497 */
498 switch (sc->sc_rev) {
499 case NCR_VARIANT_ESP100:
500 sc->sc_maxxfer = 64 * 1024;
501 sc->sc_minsync = 0; /* No synch on old chip? */
502 break;
503
504 case NCR_VARIANT_ESP100A:
505 sc->sc_maxxfer = 64 * 1024;
506 /* Min clocks/byte is 5 */
507 sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5);
508 break;
509
510 case NCR_VARIANT_ESP200:
511 case NCR_VARIANT_FAS366:
512 sc->sc_maxxfer = 16 * 1024 * 1024;
513 /* XXX - do actually set FAST* bits */
514 break;
515 }
516
517 /* Establish interrupt channel */
518 icookie = bus_intr_establish(esc->sc_bustag, esc->sc_pri, IPL_BIO, 0,
519 ncr53c9x_intr, sc);
520
521 /* register interrupt stats */
522 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
523 sc->sc_dev.dv_xname, "intr");
524
525 /* Turn on target selection using the `dma' method */
526 if (sc->sc_rev != NCR_VARIANT_FAS366)
527 sc->sc_features |= NCR_F_DMASELECT;
528
529 /* Do the common parts of attachment. */
530 sc->sc_adapter.adapt_minphys = minphys;
531 sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
532 ncr53c9x_attach(sc);
533
534 }
535
536 /*
537 * Glue functions.
538 */
539
540 #ifdef ESP_SBUS_DEBUG
541 int esp_sbus_debug = 0;
542
543 static struct {
544 char *r_name;
545 int r_flag;
546 } esp__read_regnames [] = {
547 { "TCL", 0}, /* 0/00 */
548 { "TCM", 0}, /* 1/04 */
549 { "FIFO", 0}, /* 2/08 */
550 { "CMD", 0}, /* 3/0c */
551 { "STAT", 0}, /* 4/10 */
552 { "INTR", 0}, /* 5/14 */
553 { "STEP", 0}, /* 6/18 */
554 { "FFLAGS", 1}, /* 7/1c */
555 { "CFG1", 1}, /* 8/20 */
556 { "STAT2", 0}, /* 9/24 */
557 { "CFG4", 1}, /* a/28 */
558 { "CFG2", 1}, /* b/2c */
559 { "CFG3", 1}, /* c/30 */
560 { "-none", 1}, /* d/34 */
561 { "TCH", 1}, /* e/38 */
562 { "TCX", 1}, /* f/3c */
563 };
564
565 static struct {
566 char *r_name;
567 int r_flag;
568 } esp__write_regnames[] = {
569 { "TCL", 1}, /* 0/00 */
570 { "TCM", 1}, /* 1/04 */
571 { "FIFO", 0}, /* 2/08 */
572 { "CMD", 0}, /* 3/0c */
573 { "SELID", 1}, /* 4/10 */
574 { "TIMEOUT", 1}, /* 5/14 */
575 { "SYNCTP", 1}, /* 6/18 */
576 { "SYNCOFF", 1}, /* 7/1c */
577 { "CFG1", 1}, /* 8/20 */
578 { "CCF", 1}, /* 9/24 */
579 { "TEST", 1}, /* a/28 */
580 { "CFG2", 1}, /* b/2c */
581 { "CFG3", 1}, /* c/30 */
582 { "-none", 1}, /* d/34 */
583 { "TCH", 1}, /* e/38 */
584 { "TCX", 1}, /* f/3c */
585 };
586 #endif
587
588 u_char
589 esp_read_reg(sc, reg)
590 struct ncr53c9x_softc *sc;
591 int reg;
592 {
593 struct esp_softc *esc = (struct esp_softc *)sc;
594 u_char v;
595
596 v = bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg * 4);
597 #ifdef ESP_SBUS_DEBUG
598 if (esp_sbus_debug && (reg < 0x10) && esp__read_regnames[reg].r_flag)
599 printf("RD:%x <%s> %x\n", reg * 4,
600 ((unsigned)reg < 0x10) ? esp__read_regnames[reg].r_name : "<***>", v);
601 #endif
602 return v;
603 }
604
605 void
606 esp_write_reg(sc, reg, v)
607 struct ncr53c9x_softc *sc;
608 int reg;
609 u_char v;
610 {
611 struct esp_softc *esc = (struct esp_softc *)sc;
612
613 #ifdef ESP_SBUS_DEBUG
614 if (esp_sbus_debug && (reg < 0x10) && esp__write_regnames[reg].r_flag)
615 printf("WR:%x <%s> %x\n", reg * 4,
616 ((unsigned)reg < 0x10) ? esp__write_regnames[reg].r_name : "<***>", v);
617 #endif
618 bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg * 4, v);
619 }
620
621 u_char
622 esp_rdreg1(sc, reg)
623 struct ncr53c9x_softc *sc;
624 int reg;
625 {
626 struct esp_softc *esc = (struct esp_softc *)sc;
627
628 return (bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg));
629 }
630
631 void
632 esp_wrreg1(sc, reg, v)
633 struct ncr53c9x_softc *sc;
634 int reg;
635 u_char v;
636 {
637 struct esp_softc *esc = (struct esp_softc *)sc;
638
639 bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg, v);
640 }
641
642 int
643 esp_dma_isintr(sc)
644 struct ncr53c9x_softc *sc;
645 {
646 struct esp_softc *esc = (struct esp_softc *)sc;
647
648 return (DMA_ISINTR(esc->sc_dma));
649 }
650
651 void
652 esp_dma_reset(sc)
653 struct ncr53c9x_softc *sc;
654 {
655 struct esp_softc *esc = (struct esp_softc *)sc;
656
657 DMA_RESET(esc->sc_dma);
658 }
659
660 int
661 esp_dma_intr(sc)
662 struct ncr53c9x_softc *sc;
663 {
664 struct esp_softc *esc = (struct esp_softc *)sc;
665
666 return (DMA_INTR(esc->sc_dma));
667 }
668
669 int
670 esp_dma_setup(sc, addr, len, datain, dmasize)
671 struct ncr53c9x_softc *sc;
672 caddr_t *addr;
673 size_t *len;
674 int datain;
675 size_t *dmasize;
676 {
677 struct esp_softc *esc = (struct esp_softc *)sc;
678
679 return (DMA_SETUP(esc->sc_dma, addr, len, datain, dmasize));
680 }
681
682 void
683 esp_dma_go(sc)
684 struct ncr53c9x_softc *sc;
685 {
686 struct esp_softc *esc = (struct esp_softc *)sc;
687
688 DMA_GO(esc->sc_dma);
689 }
690
691 void
692 esp_dma_stop(sc)
693 struct ncr53c9x_softc *sc;
694 {
695 struct esp_softc *esc = (struct esp_softc *)sc;
696 u_int32_t csr;
697
698 csr = L64854_GCSR(esc->sc_dma);
699 csr &= ~D_EN_DMA;
700 L64854_SCSR(esc->sc_dma, csr);
701 }
702
703 int
704 esp_dma_isactive(sc)
705 struct ncr53c9x_softc *sc;
706 {
707 struct esp_softc *esc = (struct esp_softc *)sc;
708
709 return (DMA_ISACTIVE(esc->sc_dma));
710 }
711
712 #include "opt_ddb.h"
713 #ifdef DDB
714 #include <machine/db_machdep.h>
715 #include <ddb/db_output.h>
716
717 void db_esp __P((db_expr_t, int, db_expr_t, char*));
718
719 void
720 db_esp(addr, have_addr, count, modif)
721 db_expr_t addr;
722 int have_addr;
723 db_expr_t count;
724 char *modif;
725 {
726 struct ncr53c9x_softc *sc;
727 struct ncr53c9x_ecb *ecb;
728 struct ncr53c9x_linfo *li;
729 int u, t, i;
730
731 for (u=0; u<10; u++) {
732 sc = (struct ncr53c9x_softc *)
733 getdevunit("esp", u);
734 if (!sc) continue;
735
736 db_printf("esp%d: nexus %p phase %x prev %x dp %p dleft %lx ify %x\n",
737 u, sc->sc_nexus, sc->sc_phase, sc->sc_prevphase,
738 sc->sc_dp, sc->sc_dleft, sc->sc_msgify);
739 db_printf("\tmsgout %x msgpriq %x msgin %x:%x:%x:%x:%x\n",
740 sc->sc_msgout, sc->sc_msgpriq, sc->sc_imess[0],
741 sc->sc_imess[1], sc->sc_imess[2], sc->sc_imess[3],
742 sc->sc_imess[0]);
743 db_printf("ready: ");
744 for (ecb = sc->ready_list.tqh_first; ecb; ecb = ecb->chain.tqe_next) {
745 db_printf("ecb %p ", ecb);
746 if (ecb == ecb->chain.tqe_next) {
747 db_printf("\nWARNING: tailq loop on ecb %p", ecb);
748 break;
749 }
750 }
751 db_printf("\n");
752
753 for (t=0; t<NCR_NTARG; t++) {
754 LIST_FOREACH(li, &sc->sc_tinfo[t].luns, link) {
755 db_printf("t%d lun %d untagged %p busy %d used %x\n",
756 t, (int)li->lun, li->untagged, li->busy,
757 li->used);
758 for (i=0; i<256; i++)
759 if ((ecb = li->queued[i])) {
760 db_printf("ecb %p tag %x\n", ecb, i);
761 }
762 }
763 }
764 }
765 }
766 #endif
767
768