sc_vme.c revision 1.3 1 /* $NetBSD: sc_vme.c,v 1.3 2001/11/13 06:17:07 lukem 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 <sys/cdefs.h>
72 __KERNEL_RCSID(0, "$NetBSD: sc_vme.c,v 1.3 2001/11/13 06:17:07 lukem Exp $");
73
74 #include "opt_ddb.h"
75
76 #include <sys/types.h>
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/kernel.h>
80 #include <sys/malloc.h>
81 #include <sys/errno.h>
82 #include <sys/device.h>
83 #include <sys/buf.h>
84
85 #include <machine/bus.h>
86 #include <machine/intr.h>
87
88 #include <dev/vme/vmereg.h>
89 #include <dev/vme/vmevar.h>
90
91 #include <dev/scsipi/scsi_all.h>
92 #include <dev/scsipi/scsipi_all.h>
93 #include <dev/scsipi/scsipi_debug.h>
94 #include <dev/scsipi/scsiconf.h>
95
96 #if !defined(DDB) && !defined(Debugger)
97 #define Debugger()
98 #endif
99
100 #ifndef DEBUG
101 #define DEBUG XXX
102 #endif
103
104 #include <dev/ic/sunscpalvar.h>
105
106 #include <dev/vme/screg.h>
107
108 /*
109 * Transfers smaller than this are done using PIO
110 * (on assumption they're not worth DMA overhead)
111 */
112 #define MIN_DMA_LEN 128
113
114 int sunsc_vme_options = 0;
115
116 static int sc_vme_match __P((struct device *, struct cfdata *, void *));
117 static void sc_vme_attach __P((struct device *, struct device *, void *));
118 static int sc_vme_intr __P((void *));
119
120 /* Auto-configuration glue. */
121 struct cfattach sc_vme_ca = {
122 sizeof(struct sunscpal_softc), sc_vme_match, sc_vme_attach
123 };
124
125 static int
126 sc_vme_match(parent, cf, aux)
127 struct device *parent;
128 struct cfdata *cf;
129 void *aux;
130 {
131 struct vme_attach_args *va = aux;
132 vme_chipset_tag_t ct = va->va_vct;
133 vme_am_t mod;
134 vme_addr_t vme_addr;
135
136 /* Make sure there is something there... */
137 mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
138 vme_addr = va->r[0].offset;
139
140 if (vme_probe(ct, vme_addr, 1, mod, VME_D8, NULL, 0) != 0)
141 return (0);
142
143 /*
144 * If this is a VME SCSI board, we have to determine whether
145 * it is an "sc" (Sun2) or "si" (Sun3) SCSI board. This can
146 * be determined using the fact that the "sc" board occupies
147 * 4K bytes in VME space but the "si" board occupies 2K bytes.
148 */
149 return (vme_probe(ct, vme_addr + 0x801, 1, mod, VME_D8, NULL, 0) == 0);
150 }
151
152 static void
153 sc_vme_attach(parent, self, aux)
154 struct device *parent, *self;
155 void *aux;
156 {
157 struct sunscpal_softc *sc = (struct sunscpal_softc *) self;
158 struct vme_attach_args *va = aux;
159 vme_chipset_tag_t ct = va->va_vct;
160 bus_space_tag_t bt;
161 bus_space_handle_t bh;
162 vme_mapresc_t resc;
163 vme_intr_handle_t ih;
164 vme_am_t mod;
165 int i;
166
167 sc->sunscpal_dmat = va->va_bdt;
168
169 mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
170
171 if (vme_space_map(ct, va->r[0].offset, SCREG_BANK_SZ,
172 mod, VME_D8, 0, &bt, &bh, &resc) != 0)
173 panic("%s: vme_space_map", sc->sc_dev.dv_xname);
174
175 sc->sunscpal_regt = bt;
176 sc->sunscpal_regh = bh;
177
178 vme_intr_map(ct, va->ilevel, va->ivector, &ih);
179 vme_intr_establish(ct, ih, IPL_BIO, sc_vme_intr, sc);
180
181 printf("\n");
182
183 /*
184 * Initialize fields used by the MI code
185 */
186
187 /* PAL register bank offsets */
188 sc->sunscpal_data = SCREG_DATA;
189 sc->sunscpal_cmd_stat = SCREG_CMD_STAT;
190 sc->sunscpal_icr = SCREG_ICR;
191 sc->sunscpal_dma_addr_h = SCREG_DMA_ADDR_H;
192 sc->sunscpal_dma_addr_l = SCREG_DMA_ADDR_L;
193 sc->sunscpal_dma_count = SCREG_DMA_COUNT;
194 sc->sunscpal_intvec = SCREG_INTVEC;
195
196 /* Miscellaneous. */
197 sc->sc_min_dma_len = MIN_DMA_LEN;
198 sc->sc_rev = SUNSCPAL_VARIANT_501_1045;
199
200 /*
201 * Allocate DMA handles.
202 */
203 i = SUNSCPAL_OPENINGS * sizeof(struct sunscpal_dma_handle);
204 sc->sc_dma_handles = (struct sunscpal_dma_handle *)malloc(i, M_DEVBUF, M_NOWAIT);
205 if (sc->sc_dma_handles == NULL)
206 panic("sc: dma handle malloc failed\n");
207
208 for (i = 0; i < SUNSCPAL_OPENINGS; i++) {
209 sc->sc_dma_handles[i].dh_flags = 0;
210
211 /* Allocate a DMA handle */
212 if (vme_dmamap_create(
213 ct, /* VME chip tag */
214 SUNSCPAL_MAX_DMA_LEN, /* size */
215 VME_AM_A24, /* address modifier */
216 VME_D16, /* data size */
217 0, /* swap */
218 1, /* nsegments */
219 SUNSCPAL_MAX_DMA_LEN, /* maxsegsz */
220 0, /* boundary */
221 BUS_DMA_NOWAIT,
222 &sc->sc_dma_handles[i].dh_dmamap) != 0) {
223
224 printf("%s: DMA buffer map create error\n",
225 sc->sc_dev.dv_xname);
226 return;
227 }
228 }
229
230 /*
231 * Set up interrupts on the board.
232 */
233 SUNSCPAL_WRITE_1(sc, sunscpal_intvec, va->ivector & 0xFF);
234
235 /* Do the common attach stuff. */
236 printf("%s", sc->sc_dev.dv_xname);
237 sunscpal_attach(sc, (sc->sc_dev.dv_cfdata->cf_flags ? sc->sc_dev.dv_cfdata->cf_flags : sunsc_vme_options));
238 }
239
240 static int
241 sc_vme_intr(void *arg)
242 {
243 struct sunscpal_softc *sc = arg;
244 int claimed;
245
246 claimed = sunscpal_intr(sc);
247 #ifdef DEBUG
248 if (!claimed) {
249 printf("sc_vme_intr: spurious from SBC\n");
250 }
251 #endif
252 /* Yes, we DID cause this interrupt. */
253 claimed = 1;
254
255 return (claimed);
256 }
257
258