esp_sbus.c revision 1.41 1 /* $NetBSD: esp_sbus.c,v 1.41 2008/02/13 04:17:26 simonb 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.41 2008/02/13 04:17:26 simonb 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 panic("%s: no corresponding DMA device", device_xname(self));
313 esc->sc_dma = device_private(dma_dev);
314 esc->sc_dma->sc_client = sc;
315
316 /*
317 * The `ESC' DMA chip must be reset before we can access
318 * the esp registers.
319 */
320 if (esc->sc_dma->sc_rev == DMAREV_ESC)
321 DMA_RESET(esc->sc_dma);
322
323 /*
324 * Map my registers in, if they aren't already in virtual
325 * address space.
326 */
327 if (sa->sa_npromvaddrs) {
328 sbus_promaddr_to_handle(sa->sa_bustag,
329 sa->sa_promvaddrs[0], &esc->sc_reg);
330 } else {
331 if (sbus_bus_map(sa->sa_bustag,
332 sa->sa_slot, sa->sa_offset, sa->sa_size,
333 0, &esc->sc_reg) != 0) {
334 printf("%s @ sbus: cannot map registers\n",
335 self->dv_xname);
336 return;
337 }
338 }
339
340 if (sa->sa_nintr == 0) {
341 /*
342 * No interrupt properties: we quit; this might
343 * happen on e.g. a Sparc X terminal.
344 */
345 printf("\n%s: no interrupt property\n", self->dv_xname);
346 return;
347 }
348
349 esc->sc_pri = sa->sa_pri;
350
351 /* add me to the sbus structures */
352 esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
353 sbus_establish(&esc->sc_sd, &sc->sc_dev);
354
355 if (strcmp("ptscII", sa->sa_name) == 0) {
356 espattach(esc, &esp_sbus_glue1);
357 } else {
358 espattach(esc, &esp_sbus_glue);
359 }
360 }
361
362 void
363 espattach_dma(parent, self, aux)
364 struct device *parent, *self;
365 void *aux;
366 {
367 struct esp_softc *esc = (void *)self;
368 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
369 struct sbus_attach_args *sa = aux;
370
371 if (strcmp("ptscII", sa->sa_name) == 0) {
372 return;
373 }
374
375 esc->sc_bustag = sa->sa_bustag;
376 esc->sc_dmatag = sa->sa_dmatag;
377
378 sc->sc_id = prom_getpropint(sa->sa_node, "initiator-id", 7);
379 sc->sc_freq = prom_getpropint(sa->sa_node, "clock-frequency", -1);
380
381 esc->sc_dma = (struct lsi64854_softc *)parent;
382 esc->sc_dma->sc_client = sc;
383
384 /*
385 * Map my registers in, if they aren't already in virtual
386 * address space.
387 */
388 if (sa->sa_npromvaddrs) {
389 sbus_promaddr_to_handle(sa->sa_bustag,
390 sa->sa_promvaddrs[0], &esc->sc_reg);
391 } else {
392 if (sbus_bus_map(sa->sa_bustag,
393 sa->sa_slot, sa->sa_offset, sa->sa_size,
394 0, &esc->sc_reg) != 0) {
395 printf("%s @ dma: cannot map registers\n",
396 self->dv_xname);
397 return;
398 }
399 }
400
401 if (sa->sa_nintr == 0) {
402 /*
403 * No interrupt properties: we quit; this might
404 * happen on e.g. a Sparc X terminal.
405 */
406 printf("\n%s: no interrupt property\n", self->dv_xname);
407 return;
408 }
409
410 esc->sc_pri = sa->sa_pri;
411
412 /* Assume SBus is grandparent */
413 esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
414 sbus_establish(&esc->sc_sd, parent);
415
416 espattach(esc, &esp_sbus_glue);
417 }
418
419
420 /*
421 * Attach this instance, and then all the sub-devices
422 */
423 void
424 espattach(esc, gluep)
425 struct esp_softc *esc;
426 struct ncr53c9x_glue *gluep;
427 {
428 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
429 void *icookie;
430 unsigned int uid = 0;
431
432 /*
433 * Set up glue for MI code early; we use some of it here.
434 */
435 sc->sc_glue = gluep;
436
437 /* gimme MHz */
438 sc->sc_freq /= 1000000;
439
440 /*
441 * XXX More of this should be in ncr53c9x_attach(), but
442 * XXX should we really poke around the chip that much in
443 * XXX the MI code? Think about this more...
444 */
445
446 /*
447 * It is necessary to try to load the 2nd config register here,
448 * to find out what rev the esp chip is, else the ncr53c9x_reset
449 * will not set up the defaults correctly.
450 */
451 sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
452 sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_RPE;
453 sc->sc_cfg3 = NCRCFG3_CDB;
454 NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
455
456 if ((NCR_READ_REG(sc, NCR_CFG2) & ~NCRCFG2_RSVD) !=
457 (NCRCFG2_SCSI2 | NCRCFG2_RPE)) {
458 sc->sc_rev = NCR_VARIANT_ESP100;
459 } else {
460 sc->sc_cfg2 = NCRCFG2_SCSI2;
461 NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
462 sc->sc_cfg3 = 0;
463 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
464 sc->sc_cfg3 = (NCRCFG3_CDB | NCRCFG3_FCLK);
465 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
466 if (NCR_READ_REG(sc, NCR_CFG3) !=
467 (NCRCFG3_CDB | NCRCFG3_FCLK)) {
468 sc->sc_rev = NCR_VARIANT_ESP100A;
469 } else {
470 /* NCRCFG2_FE enables > 64K transfers */
471 sc->sc_cfg2 |= NCRCFG2_FE;
472 sc->sc_cfg3 = 0;
473 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
474 sc->sc_rev = NCR_VARIANT_ESP200;
475
476 /* XXX spec says it's valid after power up or chip reset */
477 uid = NCR_READ_REG(sc, NCR_UID);
478 if (((uid & 0xf8) >> 3) == 0x0a) /* XXX */
479 sc->sc_rev = NCR_VARIANT_FAS366;
480 }
481 }
482
483 #ifdef ESP_SBUS_DEBUG
484 printf("espattach: revision %d, uid 0x%x\n", sc->sc_rev, uid);
485 #endif
486
487 /*
488 * XXX minsync and maxxfer _should_ be set up in MI code,
489 * XXX but it appears to have some dependency on what sort
490 * XXX of DMA we're hooked up to, etc.
491 */
492
493 /*
494 * This is the value used to start sync negotiations
495 * Note that the NCR register "SYNCTP" is programmed
496 * in "clocks per byte", and has a minimum value of 4.
497 * The SCSI period used in negotiation is one-fourth
498 * of the time (in nanoseconds) needed to transfer one byte.
499 * Since the chip's clock is given in MHz, we have the following
500 * formula: 4 * period = (1000 / freq) * 4
501 */
502 sc->sc_minsync = 1000 / sc->sc_freq;
503
504 /*
505 * Alas, we must now modify the value a bit, because it's
506 * only valid when can switch on FASTCLK and FASTSCSI bits
507 * in config register 3...
508 */
509 switch (sc->sc_rev) {
510 case NCR_VARIANT_ESP100:
511 sc->sc_maxxfer = 64 * 1024;
512 sc->sc_minsync = 0; /* No synch on old chip? */
513 break;
514
515 case NCR_VARIANT_ESP100A:
516 sc->sc_maxxfer = 64 * 1024;
517 /* Min clocks/byte is 5 */
518 sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5);
519 break;
520
521 case NCR_VARIANT_ESP200:
522 case NCR_VARIANT_FAS366:
523 sc->sc_maxxfer = 16 * 1024 * 1024;
524 /* XXX - do actually set FAST* bits */
525 break;
526 }
527
528 /* Establish interrupt channel */
529 icookie = bus_intr_establish(esc->sc_bustag, esc->sc_pri, IPL_BIO,
530 ncr53c9x_intr, sc);
531
532 /* register interrupt stats */
533 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
534 sc->sc_dev.dv_xname, "intr");
535
536 /* Turn on target selection using the `dma' method */
537 if (sc->sc_rev != NCR_VARIANT_FAS366)
538 sc->sc_features |= NCR_F_DMASELECT;
539
540 /* Do the common parts of attachment. */
541 sc->sc_adapter.adapt_minphys = minphys;
542 sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
543 ncr53c9x_attach(sc);
544
545 }
546
547 /*
548 * Glue functions.
549 */
550
551 #ifdef ESP_SBUS_DEBUG
552 int esp_sbus_debug = 0;
553
554 static struct {
555 char *r_name;
556 int r_flag;
557 } esp__read_regnames [] = {
558 { "TCL", 0}, /* 0/00 */
559 { "TCM", 0}, /* 1/04 */
560 { "FIFO", 0}, /* 2/08 */
561 { "CMD", 0}, /* 3/0c */
562 { "STAT", 0}, /* 4/10 */
563 { "INTR", 0}, /* 5/14 */
564 { "STEP", 0}, /* 6/18 */
565 { "FFLAGS", 1}, /* 7/1c */
566 { "CFG1", 1}, /* 8/20 */
567 { "STAT2", 0}, /* 9/24 */
568 { "CFG4", 1}, /* a/28 */
569 { "CFG2", 1}, /* b/2c */
570 { "CFG3", 1}, /* c/30 */
571 { "-none", 1}, /* d/34 */
572 { "TCH", 1}, /* e/38 */
573 { "TCX", 1}, /* f/3c */
574 };
575
576 static struct {
577 char *r_name;
578 int r_flag;
579 } esp__write_regnames[] = {
580 { "TCL", 1}, /* 0/00 */
581 { "TCM", 1}, /* 1/04 */
582 { "FIFO", 0}, /* 2/08 */
583 { "CMD", 0}, /* 3/0c */
584 { "SELID", 1}, /* 4/10 */
585 { "TIMEOUT", 1}, /* 5/14 */
586 { "SYNCTP", 1}, /* 6/18 */
587 { "SYNCOFF", 1}, /* 7/1c */
588 { "CFG1", 1}, /* 8/20 */
589 { "CCF", 1}, /* 9/24 */
590 { "TEST", 1}, /* a/28 */
591 { "CFG2", 1}, /* b/2c */
592 { "CFG3", 1}, /* c/30 */
593 { "-none", 1}, /* d/34 */
594 { "TCH", 1}, /* e/38 */
595 { "TCX", 1}, /* f/3c */
596 };
597 #endif
598
599 u_char
600 esp_read_reg(sc, reg)
601 struct ncr53c9x_softc *sc;
602 int reg;
603 {
604 struct esp_softc *esc = (struct esp_softc *)sc;
605 u_char v;
606
607 v = bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg * 4);
608 #ifdef ESP_SBUS_DEBUG
609 if (esp_sbus_debug && (reg < 0x10) && esp__read_regnames[reg].r_flag)
610 printf("RD:%x <%s> %x\n", reg * 4,
611 ((unsigned)reg < 0x10) ? esp__read_regnames[reg].r_name : "<***>", v);
612 #endif
613 return v;
614 }
615
616 void
617 esp_write_reg(sc, reg, v)
618 struct ncr53c9x_softc *sc;
619 int reg;
620 u_char v;
621 {
622 struct esp_softc *esc = (struct esp_softc *)sc;
623
624 #ifdef ESP_SBUS_DEBUG
625 if (esp_sbus_debug && (reg < 0x10) && esp__write_regnames[reg].r_flag)
626 printf("WR:%x <%s> %x\n", reg * 4,
627 ((unsigned)reg < 0x10) ? esp__write_regnames[reg].r_name : "<***>", v);
628 #endif
629 bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg * 4, v);
630 }
631
632 u_char
633 esp_rdreg1(sc, reg)
634 struct ncr53c9x_softc *sc;
635 int reg;
636 {
637 struct esp_softc *esc = (struct esp_softc *)sc;
638
639 return (bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg));
640 }
641
642 void
643 esp_wrreg1(sc, reg, v)
644 struct ncr53c9x_softc *sc;
645 int reg;
646 u_char v;
647 {
648 struct esp_softc *esc = (struct esp_softc *)sc;
649
650 bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg, v);
651 }
652
653 int
654 esp_dma_isintr(sc)
655 struct ncr53c9x_softc *sc;
656 {
657 struct esp_softc *esc = (struct esp_softc *)sc;
658
659 return (DMA_ISINTR(esc->sc_dma));
660 }
661
662 void
663 esp_dma_reset(sc)
664 struct ncr53c9x_softc *sc;
665 {
666 struct esp_softc *esc = (struct esp_softc *)sc;
667
668 DMA_RESET(esc->sc_dma);
669 }
670
671 int
672 esp_dma_intr(sc)
673 struct ncr53c9x_softc *sc;
674 {
675 struct esp_softc *esc = (struct esp_softc *)sc;
676
677 return (DMA_INTR(esc->sc_dma));
678 }
679
680 int
681 esp_dma_setup(sc, addr, len, datain, dmasize)
682 struct ncr53c9x_softc *sc;
683 void **addr;
684 size_t *len;
685 int datain;
686 size_t *dmasize;
687 {
688 struct esp_softc *esc = (struct esp_softc *)sc;
689
690 return (DMA_SETUP(esc->sc_dma, addr, len, datain, dmasize));
691 }
692
693 void
694 esp_dma_go(sc)
695 struct ncr53c9x_softc *sc;
696 {
697 struct esp_softc *esc = (struct esp_softc *)sc;
698
699 DMA_GO(esc->sc_dma);
700 }
701
702 void
703 esp_dma_stop(sc)
704 struct ncr53c9x_softc *sc;
705 {
706 struct esp_softc *esc = (struct esp_softc *)sc;
707 u_int32_t csr;
708
709 csr = L64854_GCSR(esc->sc_dma);
710 csr &= ~D_EN_DMA;
711 L64854_SCSR(esc->sc_dma, csr);
712 }
713
714 int
715 esp_dma_isactive(sc)
716 struct ncr53c9x_softc *sc;
717 {
718 struct esp_softc *esc = (struct esp_softc *)sc;
719
720 return (DMA_ISACTIVE(esc->sc_dma));
721 }
722
723 #ifdef DDB
724 #include <machine/db_machdep.h>
725 #include <ddb/db_output.h>
726 #include <ddb/db_command.h>
727
728 void db_esp(db_expr_t, bool, db_expr_t, const char*);
729
730 const struct db_command db_esp_command_table[] = {
731 { DDB_ADD_CMD("esp", db_esp, 0,
732 "display status of all esp SCSI controllers and their devices",
733 NULL, NULL) },
734 { DDB_ADD_CMD(NULL, NULL, 0, NULL, NULL, NULL) }
735 };
736
737 static void
738 esp_init_ddb_cmds()
739 {
740 static int db_cmds_initialized = 0;
741
742 if (db_cmds_initialized) return;
743 db_cmds_initialized = 1;
744 (void)db_register_tbl(DDB_MACH_CMD, db_esp_command_table);
745 }
746
747 void
748 db_esp(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
749 {
750 device_t dv;
751 struct ncr53c9x_softc *sc;
752 struct ncr53c9x_ecb *ecb;
753 struct ncr53c9x_linfo *li;
754 int u, t, i;
755
756 for (u=0; u<10; u++) {
757 dv = device_find_by_driver_unit("esp", u);
758 if (dv == NULL)
759 continue;
760 sc = device_private(dv);
761
762 db_printf("esp%d: nexus %p phase %x prev %x dp %p dleft %lx ify %x\n",
763 u, sc->sc_nexus, sc->sc_phase, sc->sc_prevphase,
764 sc->sc_dp, sc->sc_dleft, sc->sc_msgify);
765 db_printf("\tmsgout %x msgpriq %x msgin %x:%x:%x:%x:%x\n",
766 sc->sc_msgout, sc->sc_msgpriq, sc->sc_imess[0],
767 sc->sc_imess[1], sc->sc_imess[2], sc->sc_imess[3],
768 sc->sc_imess[0]);
769 db_printf("ready: ");
770 for (ecb = sc->ready_list.tqh_first; ecb; ecb = ecb->chain.tqe_next) {
771 db_printf("ecb %p ", ecb);
772 if (ecb == ecb->chain.tqe_next) {
773 db_printf("\nWARNING: tailq loop on ecb %p", ecb);
774 break;
775 }
776 }
777 db_printf("\n");
778
779 for (t=0; t<sc->sc_ntarg; t++) {
780 LIST_FOREACH(li, &sc->sc_tinfo[t].luns, link) {
781 db_printf("t%d lun %d untagged %p busy %d used %x\n",
782 t, (int)li->lun, li->untagged, li->busy,
783 li->used);
784 for (i=0; i<256; i++)
785 if ((ecb = li->queued[i])) {
786 db_printf("ecb %p tag %x\n", ecb, i);
787 }
788 }
789 }
790 }
791 }
792 #endif
793
794