ncr.c revision 1.21 1 1.21 ragge /* $NetBSD: ncr.c,v 1.21 1999/08/27 17:49:42 ragge Exp $ */
2 1.1 ragge
3 1.16 ragge /*-
4 1.16 ragge * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 ragge * All rights reserved.
6 1.1 ragge *
7 1.16 ragge * This code is derived from software contributed to The NetBSD Foundation
8 1.16 ragge * by Adam Glass, David Jones, Gordon W. Ross, and Jens A. Nilsson.
9 1.16 ragge *
10 1.1 ragge * Redistribution and use in source and binary forms, with or without
11 1.1 ragge * modification, are permitted provided that the following conditions
12 1.1 ragge * are met:
13 1.1 ragge * 1. Redistributions of source code must retain the above copyright
14 1.1 ragge * notice, this list of conditions and the following disclaimer.
15 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ragge * notice, this list of conditions and the following disclaimer in the
17 1.1 ragge * documentation and/or other materials provided with the distribution.
18 1.16 ragge * 3. All advertising materials mentioning features or use of this software
19 1.1 ragge * must display the following acknowledgement:
20 1.16 ragge * This product includes software developed by the NetBSD
21 1.16 ragge * Foundation, Inc. and its contributors.
22 1.16 ragge * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.16 ragge * contributors may be used to endorse or promote products derived
24 1.16 ragge * from this software without specific prior written permission.
25 1.16 ragge *
26 1.16 ragge * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.16 ragge * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.16 ragge * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.16 ragge * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.16 ragge * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.16 ragge * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.16 ragge * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.16 ragge * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.16 ragge * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.16 ragge * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.16 ragge * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ragge */
38 1.1 ragge
39 1.1 ragge /*
40 1.16 ragge * This file contains the machine-dependent parts of the NCR-5380
41 1.16 ragge * controller. The machine-independent parts are in ncr5380sbc.c.
42 1.16 ragge *
43 1.16 ragge * Note: Only PIO transfers for now which implicates very bad
44 1.16 ragge * performance. DMA support will come soon.
45 1.16 ragge *
46 1.16 ragge * Jens A. Nilsson.
47 1.16 ragge *
48 1.16 ragge * Credits:
49 1.16 ragge *
50 1.16 ragge * This code is based on arch/sun3/dev/si*
51 1.16 ragge * Written by David Jones, Gordon Ross, and Adam Glass.
52 1.1 ragge */
53 1.1 ragge
54 1.1 ragge #include <sys/param.h>
55 1.1 ragge #include <sys/systm.h>
56 1.16 ragge #include <sys/errno.h>
57 1.1 ragge #include <sys/kernel.h>
58 1.16 ragge #include <sys/malloc.h>
59 1.16 ragge #include <sys/device.h>
60 1.1 ragge #include <sys/buf.h>
61 1.1 ragge #include <sys/proc.h>
62 1.1 ragge #include <sys/user.h>
63 1.1 ragge
64 1.9 bouyer #include <dev/scsipi/scsi_all.h>
65 1.9 bouyer #include <dev/scsipi/scsipi_all.h>
66 1.9 bouyer #include <dev/scsipi/scsipi_debug.h>
67 1.9 bouyer #include <dev/scsipi/scsiconf.h>
68 1.1 ragge
69 1.1 ragge #include <dev/ic/ncr5380reg.h>
70 1.1 ragge #include <dev/ic/ncr5380var.h>
71 1.1 ragge
72 1.16 ragge #include <machine/vsbus.h>
73 1.16 ragge #include <machine/bus.h>
74 1.21 ragge #include <machine/sid.h>
75 1.1 ragge
76 1.16 ragge #include "ioconf.h"
77 1.1 ragge
78 1.16 ragge #define MIN_DMA_LEN 128
79 1.1 ragge
80 1.16 ragge #ifdef notyet
81 1.1 ragge struct si_dma_handle {
82 1.16 ragge int dh_flags;
83 1.16 ragge #define SIDH_BUSY 1
84 1.16 ragge #define SIDH_OUT 2
85 1.16 ragge u_char *dh_addr;
86 1.1 ragge };
87 1.16 ragge #endif
88 1.1 ragge
89 1.1 ragge struct si_softc {
90 1.1 ragge struct ncr5380_softc ncr_sc;
91 1.18 ragge caddr_t sca_regs;
92 1.1 ragge };
93 1.1 ragge
94 1.1 ragge /* This is copied from julian's bt driver */
95 1.1 ragge /* "so we have a default dev struct for our link struct." */
96 1.9 bouyer static struct scsipi_device si_dev = {
97 1.16 ragge NULL, /* Use default error handler. */
98 1.16 ragge NULL, /* Use default start handler. */
99 1.16 ragge NULL, /* Use default async handler. */
100 1.16 ragge NULL, /* Use default "done" routine. */
101 1.1 ragge };
102 1.1 ragge
103 1.16 ragge static int si_match(struct device *, struct cfdata *, void *);
104 1.16 ragge static void si_attach(struct device *, struct device *, void *);
105 1.16 ragge static void si_minphys(struct buf *);
106 1.16 ragge static void si_intr(int);
107 1.16 ragge void dk_establish(void);
108 1.1 ragge
109 1.1 ragge struct cfattach ncr_ca = {
110 1.16 ragge sizeof(struct si_softc), si_match, si_attach
111 1.1 ragge };
112 1.1 ragge
113 1.1 ragge void
114 1.16 ragge dk_establish(void)
115 1.1 ragge {
116 1.1 ragge #if 0
117 1.16 ragge printf("faking dk_establish()...\n");
118 1.1 ragge #endif
119 1.1 ragge }
120 1.1 ragge
121 1.16 ragge static int
122 1.16 ragge si_match(parent, cf, aux)
123 1.16 ragge struct device *parent;
124 1.16 ragge struct cfdata *cf;
125 1.16 ragge void *aux;
126 1.1 ragge {
127 1.16 ragge struct vsbus_attach_args *va = aux;
128 1.18 ragge volatile char *si_csr = (char *) va->va_addr;
129 1.1 ragge
130 1.21 ragge if (vax_boardtype == VAX_BTYP_49)
131 1.21 ragge return 0;
132 1.19 ragge /* This is the way Linux autoprobes the interrupt MK-990321 */
133 1.19 ragge si_csr[12] = 0;
134 1.19 ragge si_csr[16] = 0x80;
135 1.19 ragge si_csr[0] = 0x80;
136 1.19 ragge si_csr[4] = 5; /* 0xcf */
137 1.18 ragge DELAY(100000);
138 1.18 ragge va->va_ivec = si_intr;
139 1.18 ragge return 1;
140 1.1 ragge }
141 1.1 ragge
142 1.16 ragge static void
143 1.18 ragge si_attach(parent, self, aux)
144 1.1 ragge struct device *parent, *self;
145 1.18 ragge void *aux;
146 1.1 ragge {
147 1.18 ragge struct vsbus_attach_args *va = aux;
148 1.1 ragge struct si_softc *sc = (struct si_softc *) self;
149 1.16 ragge struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
150 1.1 ragge
151 1.16 ragge printf("\n");
152 1.18 ragge sc->sca_regs = (caddr_t)vax_map_physmem(va->va_paddr, 1);
153 1.1 ragge /*
154 1.16 ragge * MD function pointers used by the MI code.
155 1.1 ragge */
156 1.16 ragge ncr_sc->sc_pio_out = ncr5380_pio_out;
157 1.16 ragge ncr_sc->sc_pio_in = ncr5380_pio_in;
158 1.16 ragge
159 1.16 ragge #ifdef notyet
160 1.16 ragge ncr_sc->sc_dma_alloc = si_dma_alloc;
161 1.16 ragge ncr_sc->sc_dma_free = si_dma_free;
162 1.16 ragge ncr_sc->sc_dma_setup = si_dma_setup;
163 1.16 ragge ncr_sc->sc_dma_start = si_dma_start;
164 1.16 ragge ncr_sc->sc_dma_poll = si_dma_poll;
165 1.16 ragge ncr_sc->sc_dma_eop = si_dma_eop;
166 1.16 ragge ncr_sc->sc_dma_stop = si_dma_stop;
167 1.1 ragge #endif
168 1.16 ragge ncr_sc->sc_intr_on = NULL /*si_intr_on*/;
169 1.16 ragge ncr_sc->sc_intr_off = NULL /*si_intr_off*/;
170 1.1 ragge
171 1.16 ragge ncr_sc->sc_dma_alloc = NULL;
172 1.16 ragge ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
173 1.15 thorpej
174 1.15 thorpej /*
175 1.15 thorpej * Fill in the adapter.
176 1.15 thorpej */
177 1.15 thorpej ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
178 1.15 thorpej ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
179 1.15 thorpej
180 1.1 ragge /*
181 1.1 ragge * Fill in the prototype scsi_link.
182 1.1 ragge */
183 1.9 bouyer ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
184 1.1 ragge ncr_sc->sc_link.adapter_softc = sc;
185 1.16 ragge ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
186 1.15 thorpej ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
187 1.1 ragge ncr_sc->sc_link.device = &si_dev;
188 1.9 bouyer ncr_sc->sc_link.type = BUS_SCSI;
189 1.16 ragge
190 1.1 ragge /*
191 1.16 ragge * Initialize fields used by the MI code.
192 1.1 ragge */
193 1.18 ragge ncr_sc->sci_r0 = sc->sca_regs; /* CUR_DATA/OUT_DATA (rw) */
194 1.18 ragge ncr_sc->sci_r1 = sc->sca_regs + 4; /* INI_CMD (rw) */
195 1.18 ragge ncr_sc->sci_r2 = sc->sca_regs + 8; /* MODE (rw) */
196 1.18 ragge ncr_sc->sci_r3 = sc->sca_regs + 12; /* TAR_CMD (rw) */
197 1.18 ragge ncr_sc->sci_r4 = sc->sca_regs + 16; /* CUR_STAT/SEL_ENA (rw) */
198 1.18 ragge ncr_sc->sci_r5 = sc->sca_regs + 20; /* STATUS/DMA_SEND (rw) */
199 1.18 ragge ncr_sc->sci_r6 = sc->sca_regs + 24; /* IN_DATA/DMA_TRCV (rw) */
200 1.18 ragge ncr_sc->sci_r7 = sc->sca_regs + 28; /* RESET/DMA_IRCV (rw) */
201 1.1 ragge
202 1.20 ragge ncr_sc->sc_no_disconnect = 0xff;
203 1.1 ragge /*
204 1.16 ragge * Initialize si board itself.
205 1.1 ragge */
206 1.1 ragge ncr5380_init(ncr_sc);
207 1.1 ragge ncr5380_reset_scsibus(ncr_sc);
208 1.1 ragge
209 1.16 ragge config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
210 1.1 ragge }
211 1.1 ragge
212 1.16 ragge static void
213 1.1 ragge si_minphys(struct buf *bp)
214 1.1 ragge {
215 1.1 ragge #if 0
216 1.16 ragge printf("minphys: blkno=%d, bcount=%d, data=0x%x, flags=%x\n",
217 1.16 ragge bp->b_blkno, (int) bp->b_bcount,
218 1.16 ragge (unsigned) bp->b_data, (unsigned) bp->b_flags);
219 1.1 ragge #endif
220 1.1 ragge }
221 1.1 ragge
222 1.16 ragge static void
223 1.16 ragge si_intr(int arg)
224 1.1 ragge {
225 1.16 ragge ncr5380_intr(ncr_cd.cd_devs[arg]);
226 1.1 ragge }
227 1.1 ragge
228