hcsc.c revision 1.8.2.2 1 1.8.2.2 nathanw /* $NetBSD: hcsc.c,v 1.8.2.2 2002/04/01 07:46:59 nathanw Exp $ */
2 1.8.2.2 nathanw
3 1.8.2.2 nathanw /*
4 1.8.2.2 nathanw * Copyright (c) 2001 Ben Harris
5 1.8.2.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 1.8.2.2 nathanw * All rights reserved.
7 1.8.2.2 nathanw *
8 1.8.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
9 1.8.2.2 nathanw * by Mark Brinicombe of Causality Limited.
10 1.8.2.2 nathanw *
11 1.8.2.2 nathanw * Redistribution and use in source and binary forms, with or without
12 1.8.2.2 nathanw * modification, are permitted provided that the following conditions
13 1.8.2.2 nathanw * are met:
14 1.8.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
15 1.8.2.2 nathanw * notice, this list of conditions and the following disclaimer.
16 1.8.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
17 1.8.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
18 1.8.2.2 nathanw * documentation and/or other materials provided with the distribution.
19 1.8.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
20 1.8.2.2 nathanw * must display the following acknowledgement:
21 1.8.2.2 nathanw * This product includes software developed by the NetBSD
22 1.8.2.2 nathanw * Foundation, Inc. and its contributors.
23 1.8.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.8.2.2 nathanw * contributors may be used to endorse or promote products derived
25 1.8.2.2 nathanw * from this software without specific prior written permission.
26 1.8.2.2 nathanw *
27 1.8.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.8.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.8.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.8.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.8.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.8.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.8.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.8.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.8.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.8.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.8.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
38 1.8.2.2 nathanw */
39 1.8.2.2 nathanw /*
40 1.8.2.2 nathanw * Copyright (c) 1996, 1997 Matthias Pfaller.
41 1.8.2.2 nathanw * All rights reserved.
42 1.8.2.2 nathanw *
43 1.8.2.2 nathanw * Redistribution and use in source and binary forms, with or without
44 1.8.2.2 nathanw * modification, are permitted provided that the following conditions
45 1.8.2.2 nathanw * are met:
46 1.8.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
47 1.8.2.2 nathanw * notice, this list of conditions and the following disclaimer.
48 1.8.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
49 1.8.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
50 1.8.2.2 nathanw * documentation and/or other materials provided with the distribution.
51 1.8.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
52 1.8.2.2 nathanw * must display the following acknowledgement:
53 1.8.2.2 nathanw * This product includes software developed by Matthias Pfaller.
54 1.8.2.2 nathanw * 4. The name of the author may not be used to endorse or promote products
55 1.8.2.2 nathanw * derived from this software without specific prior written permission
56 1.8.2.2 nathanw *
57 1.8.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 1.8.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.8.2.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.8.2.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 1.8.2.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 1.8.2.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 1.8.2.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 1.8.2.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 1.8.2.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 1.8.2.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.8.2.2 nathanw */
68 1.8.2.2 nathanw
69 1.8.2.2 nathanw /*
70 1.8.2.2 nathanw * HCCS 8-bit SCSI driver using the generic NCR5380 driver
71 1.8.2.2 nathanw *
72 1.8.2.2 nathanw * Andy Armstrong gives some details of the HCCS SCSI cards at
73 1.8.2.2 nathanw * <URL:http://www.armlinux.org/~webmail/linux-arm/1997-08/msg00042.html>.
74 1.8.2.2 nathanw */
75 1.8.2.2 nathanw
76 1.8.2.2 nathanw #include <sys/cdefs.h>
77 1.8.2.2 nathanw __KERNEL_RCSID(0, "$NetBSD: hcsc.c,v 1.8.2.2 2002/04/01 07:46:59 nathanw Exp $");
78 1.8.2.2 nathanw
79 1.8.2.2 nathanw #include <sys/param.h>
80 1.8.2.2 nathanw
81 1.8.2.2 nathanw #include <sys/systm.h>
82 1.8.2.2 nathanw #include <sys/kernel.h>
83 1.8.2.2 nathanw #include <sys/device.h>
84 1.8.2.2 nathanw #include <sys/buf.h>
85 1.8.2.2 nathanw #include <dev/scsipi/scsi_all.h>
86 1.8.2.2 nathanw #include <dev/scsipi/scsipi_all.h>
87 1.8.2.2 nathanw #include <dev/scsipi/scsiconf.h>
88 1.8.2.2 nathanw
89 1.8.2.2 nathanw #include <dev/ic/ncr5380reg.h>
90 1.8.2.2 nathanw #include <dev/ic/ncr5380var.h>
91 1.8.2.2 nathanw
92 1.8.2.2 nathanw #include <machine/bootconfig.h>
93 1.8.2.2 nathanw
94 1.8.2.2 nathanw #include <dev/podulebus/podulebus.h>
95 1.8.2.2 nathanw #include <dev/podulebus/podules.h>
96 1.8.2.2 nathanw #include <dev/podulebus/powerromreg.h>
97 1.8.2.2 nathanw
98 1.8.2.2 nathanw #include <dev/podulebus/hcscreg.h>
99 1.8.2.2 nathanw
100 1.8.2.2 nathanw void hcsc_attach (struct device *, struct device *, void *);
101 1.8.2.2 nathanw int hcsc_match (struct device *, struct cfdata *, void *);
102 1.8.2.2 nathanw
103 1.8.2.2 nathanw static int hcsc_pdma_in(struct ncr5380_softc *, int, int, u_char *);
104 1.8.2.2 nathanw static int hcsc_pdma_out(struct ncr5380_softc *, int, int, u_char *);
105 1.8.2.2 nathanw
106 1.8.2.2 nathanw
107 1.8.2.2 nathanw /*
108 1.8.2.2 nathanw * HCCS 8-bit SCSI softc structure.
109 1.8.2.2 nathanw *
110 1.8.2.2 nathanw * Contains the generic ncr5380 device node, podule information and
111 1.8.2.2 nathanw * global information required by the driver.
112 1.8.2.2 nathanw */
113 1.8.2.2 nathanw
114 1.8.2.2 nathanw struct hcsc_softc {
115 1.8.2.2 nathanw struct ncr5380_softc sc_ncr5380;
116 1.8.2.2 nathanw bus_space_tag_t sc_pdmat;
117 1.8.2.2 nathanw bus_space_handle_t sc_pdmah;
118 1.8.2.2 nathanw void *sc_ih;
119 1.8.2.2 nathanw struct evcnt sc_intrcnt;
120 1.8.2.2 nathanw };
121 1.8.2.2 nathanw
122 1.8.2.2 nathanw struct cfattach hcsc_ca = {
123 1.8.2.2 nathanw sizeof(struct hcsc_softc), hcsc_match, hcsc_attach
124 1.8.2.2 nathanw };
125 1.8.2.2 nathanw
126 1.8.2.2 nathanw /*
127 1.8.2.2 nathanw * Card probe function
128 1.8.2.2 nathanw *
129 1.8.2.2 nathanw * Just match the manufacturer and podule ID's
130 1.8.2.2 nathanw */
131 1.8.2.2 nathanw
132 1.8.2.2 nathanw int
133 1.8.2.2 nathanw hcsc_match(struct device *parent, struct cfdata *cf, void *aux)
134 1.8.2.2 nathanw {
135 1.8.2.2 nathanw struct podulebus_attach_args *pa = aux;
136 1.8.2.2 nathanw
137 1.8.2.2 nathanw /* Normal ROM */
138 1.8.2.2 nathanw if (pa->pa_product == PODULE_HCCS_IDESCSI &&
139 1.8.2.2 nathanw strncmp(pa->pa_descr, "SCSI", 4) == 0)
140 1.8.2.2 nathanw return 1;
141 1.8.2.2 nathanw /* PowerROM */
142 1.8.2.2 nathanw if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
143 1.8.2.2 nathanw podulebus_initloader(pa) == 0 &&
144 1.8.2.2 nathanw podloader_callloader(pa, 0, 0) == PRID_HCCS_SCSI1)
145 1.8.2.2 nathanw return 1;
146 1.8.2.2 nathanw return 0;
147 1.8.2.2 nathanw }
148 1.8.2.2 nathanw
149 1.8.2.2 nathanw /*
150 1.8.2.2 nathanw * Card attach function
151 1.8.2.2 nathanw *
152 1.8.2.2 nathanw */
153 1.8.2.2 nathanw
154 1.8.2.2 nathanw void
155 1.8.2.2 nathanw hcsc_attach(struct device *parent, struct device *self, void *aux)
156 1.8.2.2 nathanw {
157 1.8.2.2 nathanw struct hcsc_softc *sc = (struct hcsc_softc *)self;
158 1.8.2.2 nathanw struct podulebus_attach_args *pa = aux;
159 1.8.2.2 nathanw #ifndef NCR5380_USE_BUS_SPACE
160 1.8.2.2 nathanw u_char *iobase;
161 1.8.2.2 nathanw #endif
162 1.8.2.2 nathanw char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
163 1.8.2.2 nathanw
164 1.8.2.2 nathanw sc->sc_ncr5380.sc_min_dma_len = 0;
165 1.8.2.2 nathanw sc->sc_ncr5380.sc_no_disconnect = 0;
166 1.8.2.2 nathanw sc->sc_ncr5380.sc_parity_disable = 0;
167 1.8.2.2 nathanw
168 1.8.2.2 nathanw sc->sc_ncr5380.sc_dma_alloc = NULL;
169 1.8.2.2 nathanw sc->sc_ncr5380.sc_dma_free = NULL;
170 1.8.2.2 nathanw sc->sc_ncr5380.sc_dma_poll = NULL;
171 1.8.2.2 nathanw sc->sc_ncr5380.sc_dma_setup = NULL;
172 1.8.2.2 nathanw sc->sc_ncr5380.sc_dma_start = NULL;
173 1.8.2.2 nathanw sc->sc_ncr5380.sc_dma_eop = NULL;
174 1.8.2.2 nathanw sc->sc_ncr5380.sc_dma_stop = NULL;
175 1.8.2.2 nathanw sc->sc_ncr5380.sc_intr_on = NULL;
176 1.8.2.2 nathanw sc->sc_ncr5380.sc_intr_off = NULL;
177 1.8.2.2 nathanw
178 1.8.2.2 nathanw #ifdef NCR5380_USE_BUS_SPACE
179 1.8.2.2 nathanw sc->sc_ncr5380.sc_regt = pa->pa_fast_t;
180 1.8.2.2 nathanw bus_space_map(sc->sc_ncr5380.sc_regt,
181 1.8.2.2 nathanw pa->pa_fast_base + HCSC_DP8490_OFFSET, 8, 0,
182 1.8.2.2 nathanw &sc->sc_ncr5380.sc_regh);
183 1.8.2.2 nathanw sc->sc_ncr5380.sci_r0 = 0;
184 1.8.2.2 nathanw sc->sc_ncr5380.sci_r1 = 1;
185 1.8.2.2 nathanw sc->sc_ncr5380.sci_r2 = 2;
186 1.8.2.2 nathanw sc->sc_ncr5380.sci_r3 = 3;
187 1.8.2.2 nathanw sc->sc_ncr5380.sci_r4 = 4;
188 1.8.2.2 nathanw sc->sc_ncr5380.sci_r5 = 5;
189 1.8.2.2 nathanw sc->sc_ncr5380.sci_r6 = 6;
190 1.8.2.2 nathanw sc->sc_ncr5380.sci_r7 = 7;
191 1.8.2.2 nathanw #else
192 1.8.2.2 nathanw iobase = (u_char *)pa->pa_fast_base + HCSC_DP8490_OFFSET;
193 1.8.2.2 nathanw sc->sc_ncr5380.sci_r0 = iobase + 0;
194 1.8.2.2 nathanw sc->sc_ncr5380.sci_r1 = iobase + 4;
195 1.8.2.2 nathanw sc->sc_ncr5380.sci_r2 = iobase + 8;
196 1.8.2.2 nathanw sc->sc_ncr5380.sci_r3 = iobase + 12;
197 1.8.2.2 nathanw sc->sc_ncr5380.sci_r4 = iobase + 16;
198 1.8.2.2 nathanw sc->sc_ncr5380.sci_r5 = iobase + 20;
199 1.8.2.2 nathanw sc->sc_ncr5380.sci_r6 = iobase + 24;
200 1.8.2.2 nathanw sc->sc_ncr5380.sci_r7 = iobase + 28;
201 1.8.2.2 nathanw #endif
202 1.8.2.2 nathanw sc->sc_pdmat = pa->pa_mod_t;
203 1.8.2.2 nathanw bus_space_map(sc->sc_pdmat, pa->pa_mod_base + HCSC_PDMA_OFFSET, 1, 0,
204 1.8.2.2 nathanw &sc->sc_pdmah);
205 1.8.2.2 nathanw
206 1.8.2.2 nathanw sc->sc_ncr5380.sc_rev = NCR_VARIANT_DP8490;
207 1.8.2.2 nathanw
208 1.8.2.2 nathanw sc->sc_ncr5380.sc_pio_in = hcsc_pdma_in;
209 1.8.2.2 nathanw sc->sc_ncr5380.sc_pio_out = hcsc_pdma_out;
210 1.8.2.2 nathanw
211 1.8.2.2 nathanw /* Provide an override for the host id */
212 1.8.2.2 nathanw sc->sc_ncr5380.sc_channel.chan_id = 7;
213 1.8.2.2 nathanw sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
214 1.8.2.2 nathanw (void)get_bootconf_option(boot_args, hi_option,
215 1.8.2.2 nathanw BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
216 1.8.2.2 nathanw sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
217 1.8.2.2 nathanw
218 1.8.2.2 nathanw printf(": host ID %d\n", sc->sc_ncr5380.sc_channel.chan_id);
219 1.8.2.2 nathanw
220 1.8.2.2 nathanw evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
221 1.8.2.2 nathanw self->dv_xname, "intr");
222 1.8.2.2 nathanw sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, ncr5380_intr,
223 1.8.2.2 nathanw sc, &sc->sc_intrcnt);
224 1.8.2.2 nathanw
225 1.8.2.2 nathanw ncr5380_attach(&sc->sc_ncr5380);
226 1.8.2.2 nathanw }
227 1.8.2.2 nathanw
228 1.8.2.2 nathanw #ifndef HCSC_TSIZE_OUT
229 1.8.2.2 nathanw #define HCSC_TSIZE_OUT 512
230 1.8.2.2 nathanw #endif
231 1.8.2.2 nathanw
232 1.8.2.2 nathanw #ifndef HCSC_TSIZE_IN
233 1.8.2.2 nathanw #define HCSC_TSIZE_IN 512
234 1.8.2.2 nathanw #endif
235 1.8.2.2 nathanw
236 1.8.2.2 nathanw #define TIMEOUT 1000000
237 1.8.2.2 nathanw
238 1.8.2.2 nathanw static __inline int
239 1.8.2.2 nathanw hcsc_ready(struct ncr5380_softc *sc)
240 1.8.2.2 nathanw {
241 1.8.2.2 nathanw int i;
242 1.8.2.2 nathanw
243 1.8.2.2 nathanw for (i = TIMEOUT; i > 0; i--) {
244 1.8.2.2 nathanw if ((NCR5380_READ(sc,sci_csr) &
245 1.8.2.2 nathanw (SCI_CSR_DREQ | SCI_CSR_PHASE_MATCH)) ==
246 1.8.2.2 nathanw (SCI_CSR_DREQ | SCI_CSR_PHASE_MATCH))
247 1.8.2.2 nathanw return(1);
248 1.8.2.2 nathanw
249 1.8.2.2 nathanw if ((NCR5380_READ(sc, sci_csr) & SCI_CSR_PHASE_MATCH) == 0 ||
250 1.8.2.2 nathanw SCI_BUSY(sc) == 0)
251 1.8.2.2 nathanw return(0);
252 1.8.2.2 nathanw }
253 1.8.2.2 nathanw printf("%s: ready timeout\n", sc->sc_dev.dv_xname);
254 1.8.2.2 nathanw return(0);
255 1.8.2.2 nathanw }
256 1.8.2.2 nathanw
257 1.8.2.2 nathanw
258 1.8.2.2 nathanw
259 1.8.2.2 nathanw /* Return zero on success. */
260 1.8.2.2 nathanw static __inline void hcsc_wait_not_req(struct ncr5380_softc *sc)
261 1.8.2.2 nathanw {
262 1.8.2.2 nathanw int timo;
263 1.8.2.2 nathanw for (timo = TIMEOUT; timo; timo--) {
264 1.8.2.2 nathanw if ((NCR5380_READ(sc, sci_bus_csr) & SCI_BUS_REQ) == 0 ||
265 1.8.2.2 nathanw (NCR5380_READ(sc, sci_csr) & SCI_CSR_PHASE_MATCH) == 0 ||
266 1.8.2.2 nathanw SCI_BUSY(sc) == 0) {
267 1.8.2.2 nathanw return;
268 1.8.2.2 nathanw }
269 1.8.2.2 nathanw }
270 1.8.2.2 nathanw printf("%s: pdma not_req timeout\n", sc->sc_dev.dv_xname);
271 1.8.2.2 nathanw }
272 1.8.2.2 nathanw
273 1.8.2.2 nathanw static int
274 1.8.2.2 nathanw hcsc_pdma_in(struct ncr5380_softc *ncr_sc, int phase, int datalen,
275 1.8.2.2 nathanw u_char *data)
276 1.8.2.2 nathanw {
277 1.8.2.2 nathanw struct hcsc_softc *sc = (void *)ncr_sc;
278 1.8.2.2 nathanw bus_space_tag_t pdmat = sc->sc_pdmat;
279 1.8.2.2 nathanw bus_space_handle_t pdmah = sc->sc_pdmah;
280 1.8.2.2 nathanw int s, resid, len;
281 1.8.2.2 nathanw
282 1.8.2.2 nathanw s = splbio();
283 1.8.2.2 nathanw
284 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
285 1.8.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) | SCI_MODE_DMA);
286 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_irecv, 0);
287 1.8.2.2 nathanw
288 1.8.2.2 nathanw resid = datalen;
289 1.8.2.2 nathanw while (resid > 0) {
290 1.8.2.2 nathanw len = min(resid, HCSC_TSIZE_IN);
291 1.8.2.2 nathanw if (hcsc_ready(ncr_sc) == 0)
292 1.8.2.2 nathanw goto interrupt;
293 1.8.2.2 nathanw bus_space_read_multi_1(pdmat, pdmah, 0, data, len);
294 1.8.2.2 nathanw data += len;
295 1.8.2.2 nathanw resid -= len;
296 1.8.2.2 nathanw }
297 1.8.2.2 nathanw
298 1.8.2.2 nathanw hcsc_wait_not_req(ncr_sc);
299 1.8.2.2 nathanw
300 1.8.2.2 nathanw interrupt:
301 1.8.2.2 nathanw SCI_CLR_INTR(ncr_sc);
302 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
303 1.8.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) & ~SCI_MODE_DMA);
304 1.8.2.2 nathanw splx(s);
305 1.8.2.2 nathanw return datalen - resid;
306 1.8.2.2 nathanw }
307 1.8.2.2 nathanw
308 1.8.2.2 nathanw static int
309 1.8.2.2 nathanw hcsc_pdma_out(struct ncr5380_softc *ncr_sc, int phase, int datalen,
310 1.8.2.2 nathanw u_char *data)
311 1.8.2.2 nathanw {
312 1.8.2.2 nathanw struct hcsc_softc *sc = (void *)ncr_sc;
313 1.8.2.2 nathanw bus_space_tag_t pdmat = sc->sc_pdmat;
314 1.8.2.2 nathanw bus_space_handle_t pdmah = sc->sc_pdmah;
315 1.8.2.2 nathanw int i, s, icmd, resid;
316 1.8.2.2 nathanw
317 1.8.2.2 nathanw s = splbio();
318 1.8.2.2 nathanw icmd = NCR5380_READ(ncr_sc, sci_icmd) & SCI_ICMD_RMASK;
319 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_icmd, icmd | SCI_ICMD_DATA);
320 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
321 1.8.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) | SCI_MODE_DMA);
322 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_dma_send, 0);
323 1.8.2.2 nathanw
324 1.8.2.2 nathanw resid = datalen;
325 1.8.2.2 nathanw if (hcsc_ready(ncr_sc) == 0)
326 1.8.2.2 nathanw goto interrupt;
327 1.8.2.2 nathanw
328 1.8.2.2 nathanw if (resid > HCSC_TSIZE_OUT) {
329 1.8.2.2 nathanw /*
330 1.8.2.2 nathanw * Because of the chips DMA prefetch, phase changes
331 1.8.2.2 nathanw * etc, won't be detected until we have written at
332 1.8.2.2 nathanw * least one byte more. We pre-write 4 bytes so
333 1.8.2.2 nathanw * subsequent transfers will be aligned to a 4 byte
334 1.8.2.2 nathanw * boundary. Assuming disconects will only occur on
335 1.8.2.2 nathanw * block boundaries, we then correct for the pre-write
336 1.8.2.2 nathanw * when and if we get a phase change. If the chip had
337 1.8.2.2 nathanw * DMA byte counting hardware, the assumption would not
338 1.8.2.2 nathanw * be necessary.
339 1.8.2.2 nathanw */
340 1.8.2.2 nathanw bus_space_write_multi_1(pdmat, pdmah, 0, data, 4);
341 1.8.2.2 nathanw data += 4;
342 1.8.2.2 nathanw resid -= 4;
343 1.8.2.2 nathanw
344 1.8.2.2 nathanw for (; resid >= HCSC_TSIZE_OUT; resid -= HCSC_TSIZE_OUT) {
345 1.8.2.2 nathanw if (hcsc_ready(ncr_sc) == 0) {
346 1.8.2.2 nathanw resid += 4; /* Overshot */
347 1.8.2.2 nathanw goto interrupt;
348 1.8.2.2 nathanw }
349 1.8.2.2 nathanw bus_space_write_multi_1(pdmat, pdmah, 0, data,
350 1.8.2.2 nathanw HCSC_TSIZE_OUT);
351 1.8.2.2 nathanw data += HCSC_TSIZE_OUT;
352 1.8.2.2 nathanw }
353 1.8.2.2 nathanw if (hcsc_ready(ncr_sc) == 0) {
354 1.8.2.2 nathanw resid += 4; /* Overshot */
355 1.8.2.2 nathanw goto interrupt;
356 1.8.2.2 nathanw }
357 1.8.2.2 nathanw }
358 1.8.2.2 nathanw
359 1.8.2.2 nathanw if (resid) {
360 1.8.2.2 nathanw bus_space_write_multi_1(pdmat, pdmah, 0, data, resid);
361 1.8.2.2 nathanw resid = 0;
362 1.8.2.2 nathanw }
363 1.8.2.2 nathanw for (i = TIMEOUT; i > 0; i--) {
364 1.8.2.2 nathanw if ((NCR5380_READ(ncr_sc, sci_csr)
365 1.8.2.2 nathanw & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH))
366 1.8.2.2 nathanw != SCI_CSR_DREQ)
367 1.8.2.2 nathanw break;
368 1.8.2.2 nathanw }
369 1.8.2.2 nathanw if (i != 0)
370 1.8.2.2 nathanw bus_space_write_1(pdmat, pdmah, 0, 0);
371 1.8.2.2 nathanw else
372 1.8.2.2 nathanw printf("%s: timeout waiting for final SCI_DSR_DREQ.\n",
373 1.8.2.2 nathanw ncr_sc->sc_dev.dv_xname);
374 1.8.2.2 nathanw
375 1.8.2.2 nathanw hcsc_wait_not_req(ncr_sc);
376 1.8.2.2 nathanw interrupt:
377 1.8.2.2 nathanw SCI_CLR_INTR(ncr_sc);
378 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
379 1.8.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) & ~SCI_MODE_DMA);
380 1.8.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_icmd, icmd);
381 1.8.2.2 nathanw splx(s);
382 1.8.2.2 nathanw return(datalen - resid);
383 1.8.2.2 nathanw }
384