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