sc_vme.c revision 1.2 1 /* $NetBSD: sc_vme.c,v 1.2 2001/06/27 20:17:20 fredette Exp $ */
2
3 /*-
4 * Copyright (c) 1996,2000,2001 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, Jason R. Thorpe,
9 * Paul Kranenburg, and Matt Fredette.
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 /*
41 * This file contains VME bus-dependent of the `sc' SCSI adapter.
42 * This hardware is frequently found on Sun 2, Sun 3, and Sun 4 machines.
43 *
44 * The SCSI machinery on this adapter is implemented by an Sun custom
45 * chipset, which is handled by the chipset driver in /sys/dev/ic/sunscpal.c
46 */
47
48 /*
49 * This driver originated as an MD implementation for the `si' VME driver.
50 * The notes pertaining to that history are included below.
51 *
52 * David Jones wrote the initial version of this module for NetBSD/sun3,
53 * which included support for the VME adapter only. (no reselection).
54 *
55 * Gordon Ross added support for the Sun 3 OBIO adapter, and re-worked
56 * both the VME and OBIO code to support disconnect/reselect.
57 * (Required figuring out the hardware "features" noted above.)
58 *
59 * The autoconfiguration boilerplate came from Adam Glass.
60 *
61 * Jason R. Thorpe ported the autoconfiguration and VME portions to
62 * NetBSD/sparc, and added initial support for the 4/100 "SCSI Weird",
63 * a wacky OBIO variant of the VME SCSI-3. Many thanks to Chuck Cranor
64 * for lots of helpful tips and suggestions. Thanks also to Paul Kranenburg
65 * and Chris Torek for bits of insight needed along the way. Thanks to
66 * David Gilbert and Andrew Gillham who risked filesystem life-and-limb
67 * for the sake of testing. Andrew Gillham helped work out the bugs
68 * the 4/100 DMA code.
69 */
70
71 #include "opt_ddb.h"
72
73 #include <sys/types.h>
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/kernel.h>
77 #include <sys/malloc.h>
78 #include <sys/errno.h>
79 #include <sys/device.h>
80 #include <sys/buf.h>
81
82 #include <machine/bus.h>
83 #include <machine/intr.h>
84
85 #include <dev/vme/vmereg.h>
86 #include <dev/vme/vmevar.h>
87
88 #include <dev/scsipi/scsi_all.h>
89 #include <dev/scsipi/scsipi_all.h>
90 #include <dev/scsipi/scsipi_debug.h>
91 #include <dev/scsipi/scsiconf.h>
92
93 #if !defined(DDB) && !defined(Debugger)
94 #define Debugger()
95 #endif
96
97 #ifndef DEBUG
98 #define DEBUG XXX
99 #endif
100
101 #include <dev/ic/sunscpalvar.h>
102
103 #include <dev/vme/screg.h>
104
105 /*
106 * Transfers smaller than this are done using PIO
107 * (on assumption they're not worth DMA overhead)
108 */
109 #define MIN_DMA_LEN 128
110
111 int sunsc_vme_options = 0;
112
113 static int sc_vme_match __P((struct device *, struct cfdata *, void *));
114 static void sc_vme_attach __P((struct device *, struct device *, void *));
115 static int sc_vme_intr __P((void *));
116
117 /* Auto-configuration glue. */
118 struct cfattach sc_vme_ca = {
119 sizeof(struct sunscpal_softc), sc_vme_match, sc_vme_attach
120 };
121
122 static int
123 sc_vme_match(parent, cf, aux)
124 struct device *parent;
125 struct cfdata *cf;
126 void *aux;
127 {
128 struct vme_attach_args *va = aux;
129 vme_chipset_tag_t ct = va->va_vct;
130 vme_am_t mod;
131 vme_addr_t vme_addr;
132
133 /* Make sure there is something there... */
134 mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
135 vme_addr = va->r[0].offset;
136
137 if (vme_probe(ct, vme_addr, 1, mod, VME_D8, NULL, 0) != 0)
138 return (0);
139
140 /*
141 * If this is a VME SCSI board, we have to determine whether
142 * it is an "sc" (Sun2) or "si" (Sun3) SCSI board. This can
143 * be determined using the fact that the "sc" board occupies
144 * 4K bytes in VME space but the "si" board occupies 2K bytes.
145 */
146 return (vme_probe(ct, vme_addr + 0x801, 1, mod, VME_D8, NULL, 0) == 0);
147 }
148
149 static void
150 sc_vme_attach(parent, self, aux)
151 struct device *parent, *self;
152 void *aux;
153 {
154 struct sunscpal_softc *sc = (struct sunscpal_softc *) self;
155 struct vme_attach_args *va = aux;
156 vme_chipset_tag_t ct = va->va_vct;
157 bus_space_tag_t bt;
158 bus_space_handle_t bh;
159 vme_mapresc_t resc;
160 vme_intr_handle_t ih;
161 vme_am_t mod;
162 int i;
163
164 sc->sunscpal_dmat = va->va_bdt;
165
166 mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
167
168 if (vme_space_map(ct, va->r[0].offset, SCREG_BANK_SZ,
169 mod, VME_D8, 0, &bt, &bh, &resc) != 0)
170 panic("%s: vme_space_map", sc->sc_dev.dv_xname);
171
172 sc->sunscpal_regt = bt;
173 sc->sunscpal_regh = bh;
174
175 vme_intr_map(ct, va->ilevel, va->ivector, &ih);
176 vme_intr_establish(ct, ih, IPL_BIO, sc_vme_intr, sc);
177
178 printf("\n");
179
180 /*
181 * Initialize fields used by the MI code
182 */
183
184 /* PAL register bank offsets */
185 sc->sunscpal_data = SCREG_DATA;
186 sc->sunscpal_cmd_stat = SCREG_CMD_STAT;
187 sc->sunscpal_icr = SCREG_ICR;
188 sc->sunscpal_dma_addr_h = SCREG_DMA_ADDR_H;
189 sc->sunscpal_dma_addr_l = SCREG_DMA_ADDR_L;
190 sc->sunscpal_dma_count = SCREG_DMA_COUNT;
191 sc->sunscpal_intvec = SCREG_INTVEC;
192
193 /* Miscellaneous. */
194 sc->sc_min_dma_len = MIN_DMA_LEN;
195 sc->sc_rev = SUNSCPAL_VARIANT_501_1045;
196
197 /*
198 * Allocate DMA handles.
199 */
200 i = SUNSCPAL_OPENINGS * sizeof(struct sunscpal_dma_handle);
201 sc->sc_dma_handles = (struct sunscpal_dma_handle *)malloc(i, M_DEVBUF, M_NOWAIT);
202 if (sc->sc_dma_handles == NULL)
203 panic("sc: dma handle malloc failed\n");
204
205 for (i = 0; i < SUNSCPAL_OPENINGS; i++) {
206 sc->sc_dma_handles[i].dh_flags = 0;
207
208 /* Allocate a DMA handle */
209 if (vme_dmamap_create(
210 ct, /* VME chip tag */
211 SUNSCPAL_MAX_DMA_LEN, /* size */
212 VME_AM_A24, /* address modifier */
213 VME_D16, /* data size */
214 0, /* swap */
215 1, /* nsegments */
216 SUNSCPAL_MAX_DMA_LEN, /* maxsegsz */
217 0, /* boundary */
218 BUS_DMA_NOWAIT,
219 &sc->sc_dma_handles[i].dh_dmamap) != 0) {
220
221 printf("%s: DMA buffer map create error\n",
222 sc->sc_dev.dv_xname);
223 return;
224 }
225 }
226
227 /*
228 * Set up interrupts on the board.
229 */
230 SUNSCPAL_WRITE_1(sc, sunscpal_intvec, va->ivector & 0xFF);
231
232 /* Do the common attach stuff. */
233 printf("%s", sc->sc_dev.dv_xname);
234 sunscpal_attach(sc, (sc->sc_dev.dv_cfdata->cf_flags ? sc->sc_dev.dv_cfdata->cf_flags : sunsc_vme_options));
235 }
236
237 static int
238 sc_vme_intr(void *arg)
239 {
240 struct sunscpal_softc *sc = arg;
241 int claimed;
242
243 claimed = sunscpal_intr(sc);
244 #ifdef DEBUG
245 if (!claimed) {
246 printf("sc_vme_intr: spurious from SBC\n");
247 }
248 #endif
249 /* Yes, we DID cause this interrupt. */
250 claimed = 1;
251
252 return (claimed);
253 }
254
255