wdsc.c revision 1.27 1 1.27 agc /* $NetBSD: wdsc.c,v 1.27 2003/08/07 16:28:41 agc Exp $ */
2 1.1 chuck
3 1.1 chuck /*
4 1.1 chuck * Copyright (c) 1982, 1990 The Regents of the University of California.
5 1.1 chuck * All rights reserved.
6 1.1 chuck *
7 1.1 chuck * Redistribution and use in source and binary forms, with or without
8 1.1 chuck * modification, are permitted provided that the following conditions
9 1.1 chuck * are met:
10 1.1 chuck * 1. Redistributions of source code must retain the above copyright
11 1.1 chuck * notice, this list of conditions and the following disclaimer.
12 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chuck * notice, this list of conditions and the following disclaimer in the
14 1.1 chuck * documentation and/or other materials provided with the distribution.
15 1.27 agc * 3. Neither the name of the University nor the names of its contributors
16 1.27 agc * may be used to endorse or promote products derived from this software
17 1.27 agc * without specific prior written permission.
18 1.27 agc *
19 1.27 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.27 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.27 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.27 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.27 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.27 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.27 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.27 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.27 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.27 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.27 agc * SUCH DAMAGE.
30 1.27 agc *
31 1.27 agc * @(#)wdsc.c
32 1.27 agc */
33 1.27 agc
34 1.27 agc /*
35 1.27 agc * Copyright (c) 1996 Steve Woodford
36 1.27 agc *
37 1.27 agc * Redistribution and use in source and binary forms, with or without
38 1.27 agc * modification, are permitted provided that the following conditions
39 1.27 agc * are met:
40 1.27 agc * 1. Redistributions of source code must retain the above copyright
41 1.27 agc * notice, this list of conditions and the following disclaimer.
42 1.27 agc * 2. Redistributions in binary form must reproduce the above copyright
43 1.27 agc * notice, this list of conditions and the following disclaimer in the
44 1.27 agc * documentation and/or other materials provided with the distribution.
45 1.1 chuck * 3. All advertising materials mentioning features or use of this software
46 1.1 chuck * must display the following acknowledgement:
47 1.1 chuck * This product includes software developed by the University of
48 1.1 chuck * California, Berkeley and its contributors.
49 1.1 chuck * 4. Neither the name of the University nor the names of its contributors
50 1.1 chuck * may be used to endorse or promote products derived from this software
51 1.1 chuck * without specific prior written permission.
52 1.1 chuck *
53 1.1 chuck * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 1.1 chuck * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 1.1 chuck * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 1.1 chuck * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 1.1 chuck * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 1.1 chuck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 1.1 chuck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 1.1 chuck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 1.1 chuck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 1.1 chuck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 1.1 chuck * SUCH DAMAGE.
64 1.1 chuck *
65 1.1 chuck * @(#)wdsc.c
66 1.1 chuck */
67 1.26 lukem
68 1.26 lukem #include <sys/cdefs.h>
69 1.27 agc __KERNEL_RCSID(0, "$NetBSD: wdsc.c,v 1.27 2003/08/07 16:28:41 agc Exp $");
70 1.2 chuck
71 1.1 chuck #include <sys/param.h>
72 1.1 chuck #include <sys/systm.h>
73 1.1 chuck #include <sys/kernel.h>
74 1.1 chuck #include <sys/device.h>
75 1.2 chuck
76 1.10 bouyer #include <dev/scsipi/scsi_all.h>
77 1.10 bouyer #include <dev/scsipi/scsipi_all.h>
78 1.10 bouyer #include <dev/scsipi/scsiconf.h>
79 1.2 chuck
80 1.16 scw #include <machine/cpu.h>
81 1.17 scw #include <machine/bus.h>
82 1.3 chuck #include <machine/autoconf.h>
83 1.3 chuck
84 1.2 chuck #include <mvme68k/dev/dmavar.h>
85 1.1 chuck #include <mvme68k/dev/pccreg.h>
86 1.2 chuck #include <mvme68k/dev/pccvar.h>
87 1.1 chuck #include <mvme68k/dev/sbicreg.h>
88 1.1 chuck #include <mvme68k/dev/sbicvar.h>
89 1.1 chuck #include <mvme68k/dev/wdscreg.h>
90 1.1 chuck
91 1.2 chuck void wdsc_pcc_attach __P((struct device *, struct device *, void *));
92 1.9 gwr int wdsc_pcc_match __P((struct device *, struct cfdata *, void *));
93 1.1 chuck
94 1.23 thorpej CFATTACH_DECL(wdsc_pcc, sizeof(struct sbic_softc),
95 1.23 thorpej wdsc_pcc_match, wdsc_pcc_attach, NULL, NULL);
96 1.17 scw
97 1.17 scw extern struct cfdriver wdsc_cd;
98 1.17 scw
99 1.1 chuck void wdsc_enintr __P((struct sbic_softc *));
100 1.1 chuck int wdsc_dmago __P((struct sbic_softc *, char *, int, int));
101 1.1 chuck int wdsc_dmanext __P((struct sbic_softc *));
102 1.1 chuck void wdsc_dmastop __P((struct sbic_softc *));
103 1.2 chuck int wdsc_dmaintr __P((void *));
104 1.2 chuck int wdsc_scsiintr __P((void *));
105 1.1 chuck
106 1.1 chuck /*
107 1.1 chuck * Match for SCSI devices on the onboard WD33C93 chip
108 1.1 chuck */
109 1.1 chuck int
110 1.9 gwr wdsc_pcc_match(pdp, cf, auxp)
111 1.1 chuck struct device *pdp;
112 1.9 gwr struct cfdata *cf;
113 1.9 gwr void *auxp;
114 1.1 chuck {
115 1.2 chuck struct pcc_attach_args *pa = auxp;
116 1.2 chuck
117 1.2 chuck if (strcmp(pa->pa_name, wdsc_cd.cd_name))
118 1.2 chuck return (0);
119 1.2 chuck
120 1.2 chuck pa->pa_ipl = cf->pcccf_ipl;
121 1.2 chuck return (1);
122 1.1 chuck }
123 1.1 chuck
124 1.1 chuck /*
125 1.1 chuck * Attach the wdsc driver
126 1.1 chuck */
127 1.1 chuck void
128 1.2 chuck wdsc_pcc_attach(pdp, dp, auxp)
129 1.1 chuck struct device *pdp, *dp;
130 1.1 chuck void *auxp;
131 1.1 chuck {
132 1.17 scw struct sbic_softc *sc;
133 1.17 scw struct pcc_attach_args *pa;
134 1.17 scw bus_space_handle_t bush;
135 1.21 scw static struct evcnt evcnt; /* XXXSCW: Temporary hack */
136 1.1 chuck
137 1.17 scw sc = (struct sbic_softc *)dp;
138 1.17 scw pa = auxp;
139 1.17 scw
140 1.17 scw bus_space_map(pa->pa_bust, pa->pa_offset, 0x20, 0, &bush);
141 1.1 chuck
142 1.17 scw /*
143 1.17 scw * XXXSCW: We *need* an MI, bus_spaced WD33C93 driver...
144 1.17 scw */
145 1.17 scw sc->sc_sbicp = (sbic_regmap_p) bush;
146 1.1 chuck
147 1.21 scw sc->sc_driver = (void *) &evcnt;
148 1.1 chuck sc->sc_enintr = wdsc_enintr;
149 1.1 chuck sc->sc_dmago = wdsc_dmago;
150 1.1 chuck sc->sc_dmanext = wdsc_dmanext;
151 1.1 chuck sc->sc_dmastop = wdsc_dmastop;
152 1.1 chuck sc->sc_dmacmd = 0;
153 1.1 chuck
154 1.20 bouyer sc->sc_adapter.adapt_dev = &sc->sc_dev;
155 1.20 bouyer sc->sc_adapter.adapt_nchannels = 1;
156 1.20 bouyer sc->sc_adapter.adapt_openings = 7;
157 1.20 bouyer sc->sc_adapter.adapt_max_periph = 1;
158 1.20 bouyer sc->sc_adapter.adapt_ioctl = NULL;
159 1.20 bouyer sc->sc_adapter.adapt_minphys = sbic_minphys;
160 1.20 bouyer sc->sc_adapter.adapt_request = sbic_scsi_request;
161 1.20 bouyer
162 1.20 bouyer sc->sc_channel.chan_adapter = &sc->sc_adapter;
163 1.20 bouyer sc->sc_channel.chan_bustype = &scsi_bustype;
164 1.20 bouyer sc->sc_channel.chan_channel = 0;
165 1.20 bouyer sc->sc_channel.chan_ntargets = 8;
166 1.20 bouyer sc->sc_channel.chan_nluns = 8;
167 1.20 bouyer sc->sc_channel.chan_id = 7;
168 1.1 chuck
169 1.20 bouyer printf(": WD33C93 SCSI, target %d\n", sc->sc_channel.chan_id);
170 1.1 chuck
171 1.1 chuck /*
172 1.25 wiz * Everything is a valid DMA address.
173 1.1 chuck */
174 1.1 chuck sc->sc_dmamask = 0;
175 1.1 chuck
176 1.1 chuck /*
177 1.1 chuck * The onboard WD33C93 of the '147 is usually clocked at 10MHz...
178 1.1 chuck * (We use 10 times this for accuracy in later calculations)
179 1.1 chuck */
180 1.1 chuck sc->sc_clkfreq = 100;
181 1.1 chuck
182 1.1 chuck /*
183 1.1 chuck * Initialise the hardware
184 1.1 chuck */
185 1.1 chuck sbicinit(sc);
186 1.1 chuck
187 1.1 chuck /*
188 1.1 chuck * Fix up the interrupts
189 1.1 chuck */
190 1.2 chuck sc->sc_ipl = pa->pa_ipl & PCC_IMASK;
191 1.1 chuck
192 1.17 scw pcc_reg_write(sys_pcc, PCCREG_SCSI_INTR_CTRL, PCC_ICLEAR);
193 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_INTR_CTRL, PCC_ICLEAR);
194 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_CONTROL, 0);
195 1.17 scw
196 1.21 scw evcnt_attach_dynamic(&evcnt, EVCNT_TYPE_INTR, pccintr_evcnt(sc->sc_ipl),
197 1.21 scw "disk", sc->sc_dev.dv_xname);
198 1.21 scw pccintr_establish(PCCV_DMA, wdsc_dmaintr, sc->sc_ipl, sc, &evcnt);
199 1.21 scw pccintr_establish(PCCV_SCSI, wdsc_scsiintr, sc->sc_ipl, sc, &evcnt);
200 1.17 scw pcc_reg_write(sys_pcc, PCCREG_SCSI_INTR_CTRL,
201 1.17 scw sc->sc_ipl | PCC_IENABLE | PCC_ICLEAR);
202 1.1 chuck
203 1.20 bouyer (void)config_found(dp, &sc->sc_channel, scsiprint);
204 1.1 chuck }
205 1.1 chuck
206 1.1 chuck /*
207 1.1 chuck * Enable DMA interrupts
208 1.1 chuck */
209 1.1 chuck void
210 1.1 chuck wdsc_enintr(dev)
211 1.1 chuck struct sbic_softc *dev;
212 1.1 chuck {
213 1.1 chuck dev->sc_flags |= SBICF_INTR;
214 1.1 chuck
215 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_INTR_CTRL,
216 1.17 scw dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR);
217 1.1 chuck }
218 1.1 chuck
219 1.1 chuck /*
220 1.1 chuck * Prime the hardware for a DMA transfer
221 1.1 chuck */
222 1.1 chuck int
223 1.1 chuck wdsc_dmago(dev, addr, count, flags)
224 1.1 chuck struct sbic_softc *dev;
225 1.1 chuck char *addr;
226 1.1 chuck int count, flags;
227 1.1 chuck {
228 1.1 chuck /*
229 1.1 chuck * Set up the command word based on flags
230 1.1 chuck */
231 1.1 chuck if ( (flags & DMAGO_READ) == 0 )
232 1.1 chuck dev->sc_dmacmd = DMAC_CSR_ENABLE | DMAC_CSR_WRITE;
233 1.1 chuck else
234 1.1 chuck dev->sc_dmacmd = DMAC_CSR_ENABLE;
235 1.1 chuck
236 1.1 chuck dev->sc_flags |= SBICF_INTR;
237 1.1 chuck dev->sc_tcnt = dev->sc_cur->dc_count << 1;
238 1.1 chuck
239 1.1 chuck /*
240 1.1 chuck * Prime the hardware.
241 1.1 chuck * Note, it's probably not necessary to do this here, since dmanext
242 1.1 chuck * is called just prior to the actual transfer.
243 1.1 chuck */
244 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_CONTROL, 0);
245 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_INTR_CTRL,
246 1.17 scw dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR);
247 1.17 scw pcc_reg_write32(sys_pcc, PCCREG_DMA_DATA_ADDR,
248 1.17 scw (u_int32_t) dev->sc_cur->dc_addr);
249 1.17 scw pcc_reg_write32(sys_pcc, PCCREG_DMA_BYTE_COUNT,
250 1.17 scw (u_int32_t) dev->sc_tcnt | (1 << 24));
251 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_CONTROL, dev->sc_dmacmd);
252 1.1 chuck
253 1.1 chuck return(dev->sc_tcnt);
254 1.1 chuck }
255 1.1 chuck
256 1.1 chuck /*
257 1.1 chuck * Prime the hardware for the next DMA transfer
258 1.1 chuck */
259 1.1 chuck int
260 1.1 chuck wdsc_dmanext(dev)
261 1.1 chuck struct sbic_softc *dev;
262 1.1 chuck {
263 1.1 chuck if ( dev->sc_cur > dev->sc_last ) {
264 1.1 chuck /*
265 1.1 chuck * Shouldn't happen !!
266 1.1 chuck */
267 1.7 christos printf("wdsc_dmanext at end !!!\n");
268 1.1 chuck wdsc_dmastop(dev);
269 1.1 chuck return(0);
270 1.1 chuck }
271 1.1 chuck
272 1.1 chuck dev->sc_tcnt = dev->sc_cur->dc_count << 1;
273 1.1 chuck
274 1.1 chuck /*
275 1.1 chuck * Load the next DMA address
276 1.1 chuck */
277 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_CONTROL, 0);
278 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_INTR_CTRL,
279 1.17 scw dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR);
280 1.17 scw pcc_reg_write32(sys_pcc, PCCREG_DMA_DATA_ADDR,
281 1.17 scw (u_int32_t) dev->sc_cur->dc_addr);
282 1.17 scw pcc_reg_write32(sys_pcc, PCCREG_DMA_BYTE_COUNT,
283 1.17 scw (u_int32_t) dev->sc_tcnt | (1 << 24));
284 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_CONTROL, dev->sc_dmacmd);
285 1.1 chuck
286 1.1 chuck return(dev->sc_tcnt);
287 1.1 chuck }
288 1.1 chuck
289 1.1 chuck /*
290 1.1 chuck * Stop DMA, and disable interrupts
291 1.1 chuck */
292 1.1 chuck void
293 1.1 chuck wdsc_dmastop(dev)
294 1.1 chuck struct sbic_softc *dev;
295 1.1 chuck {
296 1.17 scw int s;
297 1.1 chuck
298 1.1 chuck s = splbio();
299 1.1 chuck
300 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_CONTROL, 0);
301 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_INTR_CTRL, dev->sc_ipl | PCC_ICLEAR);
302 1.1 chuck
303 1.1 chuck splx(s);
304 1.1 chuck }
305 1.1 chuck
306 1.1 chuck /*
307 1.1 chuck * Come here following a DMA interrupt
308 1.1 chuck */
309 1.1 chuck int
310 1.2 chuck wdsc_dmaintr(arg)
311 1.2 chuck void *arg;
312 1.1 chuck {
313 1.2 chuck struct sbic_softc *dev = arg;
314 1.17 scw int found = 0;
315 1.1 chuck
316 1.1 chuck /*
317 1.1 chuck * Really a DMA interrupt?
318 1.1 chuck */
319 1.17 scw if ( (pcc_reg_read(sys_pcc, PCCREG_DMA_INTR_CTRL) & 0x80) == 0 )
320 1.1 chuck return(0);
321 1.1 chuck
322 1.1 chuck /*
323 1.1 chuck * Was it a completion interrupt?
324 1.1 chuck * XXXSCW Note: Support for other DMA interrupts is required, eg. buserr
325 1.1 chuck */
326 1.17 scw if ( pcc_reg_read(sys_pcc, PCCREG_DMA_CONTROL) & DMAC_CSR_DONE ) {
327 1.1 chuck ++found;
328 1.1 chuck
329 1.17 scw pcc_reg_write(sys_pcc, PCCREG_DMA_INTR_CTRL,
330 1.17 scw dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR);
331 1.1 chuck }
332 1.1 chuck
333 1.1 chuck return(found);
334 1.1 chuck }
335 1.1 chuck
336 1.1 chuck /*
337 1.1 chuck * Come here for SCSI interrupts
338 1.1 chuck */
339 1.1 chuck int
340 1.2 chuck wdsc_scsiintr(arg)
341 1.2 chuck void *arg;
342 1.1 chuck {
343 1.2 chuck struct sbic_softc *dev = arg;
344 1.17 scw int found;
345 1.1 chuck
346 1.1 chuck /*
347 1.1 chuck * Really a SCSI interrupt?
348 1.1 chuck */
349 1.17 scw if ( (pcc_reg_read(sys_pcc, PCCREG_SCSI_INTR_CTRL) & 0x80) == 0 )
350 1.1 chuck return(0);
351 1.1 chuck
352 1.1 chuck /*
353 1.1 chuck * Go handle it
354 1.1 chuck */
355 1.1 chuck found = sbicintr(dev);
356 1.1 chuck
357 1.1 chuck /*
358 1.1 chuck * Acknowledge and clear the interrupt
359 1.1 chuck */
360 1.17 scw pcc_reg_write(sys_pcc, PCCREG_SCSI_INTR_CTRL,
361 1.17 scw dev->sc_ipl | PCC_IENABLE | PCC_ICLEAR);
362 1.1 chuck
363 1.1 chuck return(found);
364 1.1 chuck }
365