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