oak.c revision 1.6.2.5 1 1.6.2.5 nathanw /* $NetBSD: oak.c,v 1.6.2.5 2002/10/18 02:43:37 nathanw Exp $ */
2 1.6.2.2 nathanw
3 1.6.2.2 nathanw /*
4 1.6.2.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.6.2.2 nathanw * All rights reserved.
6 1.6.2.2 nathanw *
7 1.6.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.6.2.2 nathanw * by Mark Brinicombe of Causality Limited.
9 1.6.2.2 nathanw *
10 1.6.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.6.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.6.2.2 nathanw * are met:
13 1.6.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.6.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.6.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.6.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.6.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.6.2.2 nathanw * must display the following acknowledgement:
20 1.6.2.2 nathanw * This product includes software developed by the NetBSD
21 1.6.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.6.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.6.2.2 nathanw * from this software without specific prior written permission.
25 1.6.2.2 nathanw *
26 1.6.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.6.2.2 nathanw */
38 1.6.2.2 nathanw
39 1.6.2.2 nathanw /*
40 1.6.2.2 nathanw * Oak Solutions SCSI 1 driver using the generic NCR5380 driver.
41 1.6.2.2 nathanw *
42 1.6.2.2 nathanw * From <URL:http://foldoc.doc.ic.ac.uk/acorn/doc/scsi>:
43 1.6.2.2 nathanw * --------8<--------
44 1.6.2.2 nathanw * From: Hugo Fiennes
45 1.6.2.2 nathanw * [...]
46 1.6.2.2 nathanw * The oak scsi plays some other tricks to get max around 2.2Mb/sec:
47 1.6.2.2 nathanw * it is a 16- bit interface (using their own hardware and an 8-bit
48 1.6.2.2 nathanw * scsi controller to 'double-up' the data). What it does is: every
49 1.6.2.2 nathanw * 128 bytes it uses a polling loop (see above) to check data is
50 1.6.2.2 nathanw * present and the drive has reported no errors, etc. Inside each 128
51 1.6.2.2 nathanw * byte block it just reads data as fast as it can: on a normal card
52 1.6.2.2 nathanw * this would result in disaster if the drive wasn't fast enough to
53 1.6.2.2 nathanw * feed the machine: on the oak card however, the hardware will not
54 1.6.2.2 nathanw * assert IOGT (IO grant), so hanging the machine in a wait state
55 1.6.2.2 nathanw * until data is ready. This can have problems: if the drive is to
56 1.6.2.2 nathanw * slow (unlikely) the machine will completely stiff as the ARM3 can't
57 1.6.2.2 nathanw * be kept in such a state for more than 10(?) us.
58 1.6.2.2 nathanw * -------->8--------
59 1.6.2.2 nathanw *
60 1.6.2.2 nathanw * So far, my attempts at doing this have failed, though.
61 1.6.2.2 nathanw *
62 1.6.2.2 nathanw * This card has to be polled: it doesn't have anything connected to
63 1.6.2.2 nathanw * PIRQ*. This seems to be a common failing of Archimedes disc
64 1.6.2.2 nathanw * controllers.
65 1.6.2.2 nathanw */
66 1.6.2.2 nathanw
67 1.6.2.2 nathanw #include <sys/cdefs.h>
68 1.6.2.5 nathanw __KERNEL_RCSID(0, "$NetBSD: oak.c,v 1.6.2.5 2002/10/18 02:43:37 nathanw Exp $");
69 1.6.2.2 nathanw
70 1.6.2.2 nathanw #include <sys/param.h>
71 1.6.2.2 nathanw
72 1.6.2.2 nathanw #include <sys/systm.h>
73 1.6.2.2 nathanw #include <sys/kernel.h>
74 1.6.2.2 nathanw #include <sys/device.h>
75 1.6.2.2 nathanw #include <sys/buf.h>
76 1.6.2.2 nathanw #include <dev/scsipi/scsi_all.h>
77 1.6.2.2 nathanw #include <dev/scsipi/scsipi_all.h>
78 1.6.2.2 nathanw #include <dev/scsipi/scsiconf.h>
79 1.6.2.2 nathanw
80 1.6.2.2 nathanw #include <dev/ic/ncr5380reg.h>
81 1.6.2.2 nathanw #include <dev/ic/ncr5380var.h>
82 1.6.2.2 nathanw
83 1.6.2.2 nathanw #include <machine/bootconfig.h>
84 1.6.2.2 nathanw
85 1.6.2.2 nathanw #include <dev/podulebus/podulebus.h>
86 1.6.2.2 nathanw #include <dev/podulebus/podules.h>
87 1.6.2.2 nathanw #include <dev/podulebus/powerromreg.h>
88 1.6.2.2 nathanw
89 1.6.2.2 nathanw #include <dev/podulebus/oakreg.h>
90 1.6.2.2 nathanw
91 1.6.2.2 nathanw void oak_attach (struct device *, struct device *, void *);
92 1.6.2.2 nathanw int oak_match (struct device *, struct cfdata *, void *);
93 1.6.2.2 nathanw
94 1.6.2.2 nathanw #if 0
95 1.6.2.2 nathanw static int oak_pdma_in(struct ncr5380_softc *, int, int, u_char *);
96 1.6.2.2 nathanw static int oak_pdma_out(struct ncr5380_softc *, int, int, u_char *);
97 1.6.2.2 nathanw #endif
98 1.6.2.2 nathanw
99 1.6.2.2 nathanw /*
100 1.6.2.2 nathanw * Oak SCSI 1 softc structure.
101 1.6.2.2 nathanw *
102 1.6.2.2 nathanw * Contains the generic ncr5380 device node, podule information and
103 1.6.2.2 nathanw * global information required by the driver.
104 1.6.2.2 nathanw */
105 1.6.2.2 nathanw
106 1.6.2.2 nathanw struct oak_softc {
107 1.6.2.2 nathanw struct ncr5380_softc sc_ncr5380;
108 1.6.2.2 nathanw bus_space_tag_t sc_pdmat;
109 1.6.2.2 nathanw bus_space_handle_t sc_pdmah;
110 1.6.2.2 nathanw };
111 1.6.2.2 nathanw
112 1.6.2.5 nathanw CFATTACH_DECL(oak, sizeof(struct oak_softc),
113 1.6.2.5 nathanw oak_match, oak_attach, NULL, NULL);
114 1.6.2.2 nathanw
115 1.6.2.2 nathanw /*
116 1.6.2.2 nathanw * Card probe function
117 1.6.2.2 nathanw *
118 1.6.2.2 nathanw * Just match the manufacturer and podule ID's
119 1.6.2.2 nathanw */
120 1.6.2.2 nathanw
121 1.6.2.2 nathanw int
122 1.6.2.2 nathanw oak_match(struct device *parent, struct cfdata *cf, void *aux)
123 1.6.2.2 nathanw {
124 1.6.2.2 nathanw struct podulebus_attach_args *pa = aux;
125 1.6.2.2 nathanw
126 1.6.2.4 nathanw if (pa->pa_product == PODULE_OAK_SCSI)
127 1.6.2.2 nathanw return 1;
128 1.6.2.2 nathanw
129 1.6.2.2 nathanw /* PowerROM */
130 1.6.2.2 nathanw if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
131 1.6.2.2 nathanw podulebus_initloader(pa) == 0 &&
132 1.6.2.2 nathanw podloader_callloader(pa, 0, 0) == PRID_OAK_SCSI1)
133 1.6.2.2 nathanw return 1;
134 1.6.2.2 nathanw
135 1.6.2.2 nathanw return 0;
136 1.6.2.2 nathanw }
137 1.6.2.2 nathanw
138 1.6.2.2 nathanw /*
139 1.6.2.2 nathanw * Card attach function
140 1.6.2.2 nathanw *
141 1.6.2.2 nathanw */
142 1.6.2.2 nathanw
143 1.6.2.2 nathanw void
144 1.6.2.2 nathanw oak_attach(struct device *parent, struct device *self, void *aux)
145 1.6.2.2 nathanw {
146 1.6.2.2 nathanw struct oak_softc *sc = (struct oak_softc *)self;
147 1.6.2.2 nathanw struct podulebus_attach_args *pa = aux;
148 1.6.2.3 nathanw #ifndef NCR5380_USE_BUS_SPACE
149 1.6.2.2 nathanw u_char *iobase;
150 1.6.2.3 nathanw #endif
151 1.6.2.2 nathanw char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
152 1.6.2.2 nathanw
153 1.6.2.2 nathanw sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
154 1.6.2.2 nathanw sc->sc_ncr5380.sc_min_dma_len = 0;
155 1.6.2.2 nathanw sc->sc_ncr5380.sc_no_disconnect = 0xff;
156 1.6.2.2 nathanw sc->sc_ncr5380.sc_parity_disable = 0;
157 1.6.2.2 nathanw
158 1.6.2.2 nathanw sc->sc_ncr5380.sc_dma_alloc = NULL;
159 1.6.2.2 nathanw sc->sc_ncr5380.sc_dma_free = NULL;
160 1.6.2.2 nathanw sc->sc_ncr5380.sc_dma_poll = NULL;
161 1.6.2.2 nathanw sc->sc_ncr5380.sc_dma_setup = NULL;
162 1.6.2.2 nathanw sc->sc_ncr5380.sc_dma_start = NULL;
163 1.6.2.2 nathanw sc->sc_ncr5380.sc_dma_eop = NULL;
164 1.6.2.2 nathanw sc->sc_ncr5380.sc_dma_stop = NULL;
165 1.6.2.2 nathanw sc->sc_ncr5380.sc_intr_on = NULL;
166 1.6.2.2 nathanw sc->sc_ncr5380.sc_intr_off = NULL;
167 1.6.2.2 nathanw
168 1.6.2.2 nathanw #ifdef NCR5380_USE_BUS_SPACE
169 1.6.2.2 nathanw sc->sc_ncr5380.sc_regt = pa->pa_mod_t;
170 1.6.2.2 nathanw bus_space_map(sc->sc_ncr5380.sc_regt, pa->pa_mod_base, 8, 0,
171 1.6.2.2 nathanw &sc->sc_ncr5380.sc_regh);
172 1.6.2.2 nathanw sc->sc_ncr5380.sci_r0 = 0;
173 1.6.2.2 nathanw sc->sc_ncr5380.sci_r1 = 1;
174 1.6.2.2 nathanw sc->sc_ncr5380.sci_r2 = 2;
175 1.6.2.2 nathanw sc->sc_ncr5380.sci_r3 = 3;
176 1.6.2.2 nathanw sc->sc_ncr5380.sci_r4 = 4;
177 1.6.2.2 nathanw sc->sc_ncr5380.sci_r5 = 5;
178 1.6.2.2 nathanw sc->sc_ncr5380.sci_r6 = 6;
179 1.6.2.2 nathanw sc->sc_ncr5380.sci_r7 = 7;
180 1.6.2.2 nathanw #else
181 1.6.2.2 nathanw iobase = (u_char *)pa->pa_mod_base;
182 1.6.2.2 nathanw sc->sc_ncr5380.sci_r0 = iobase + 0;
183 1.6.2.2 nathanw sc->sc_ncr5380.sci_r1 = iobase + 4;
184 1.6.2.2 nathanw sc->sc_ncr5380.sci_r2 = iobase + 8;
185 1.6.2.2 nathanw sc->sc_ncr5380.sci_r3 = iobase + 12;
186 1.6.2.2 nathanw sc->sc_ncr5380.sci_r4 = iobase + 16;
187 1.6.2.2 nathanw sc->sc_ncr5380.sci_r5 = iobase + 20;
188 1.6.2.2 nathanw sc->sc_ncr5380.sci_r6 = iobase + 24;
189 1.6.2.2 nathanw sc->sc_ncr5380.sci_r7 = iobase + 28;
190 1.6.2.2 nathanw #endif
191 1.6.2.2 nathanw sc->sc_pdmat = pa->pa_mod_t;
192 1.6.2.2 nathanw bus_space_map(sc->sc_pdmat, pa->pa_mod_base + OAK_PDMA_OFFSET, 0x20, 0,
193 1.6.2.2 nathanw &sc->sc_pdmah);
194 1.6.2.2 nathanw
195 1.6.2.2 nathanw sc->sc_ncr5380.sc_rev = NCR_VARIANT_NCR5380;
196 1.6.2.2 nathanw
197 1.6.2.2 nathanw sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in;
198 1.6.2.2 nathanw sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out;
199 1.6.2.2 nathanw
200 1.6.2.2 nathanw /* Provide an override for the host id */
201 1.6.2.2 nathanw sc->sc_ncr5380.sc_channel.chan_id = 7;
202 1.6.2.2 nathanw sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
203 1.6.2.2 nathanw (void)get_bootconf_option(boot_args, hi_option,
204 1.6.2.2 nathanw BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
205 1.6.2.2 nathanw sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
206 1.6.2.2 nathanw
207 1.6.2.2 nathanw printf(": host=%d, using 8 bit PIO\n",
208 1.6.2.2 nathanw sc->sc_ncr5380.sc_channel.chan_id);
209 1.6.2.2 nathanw
210 1.6.2.2 nathanw ncr5380_attach(&sc->sc_ncr5380);
211 1.6.2.2 nathanw }
212 1.6.2.2 nathanw
213 1.6.2.2 nathanw /*
214 1.6.2.2 nathanw * XXX The code below doesn't work correctly. I probably need more
215 1.6.2.2 nathanw * details on how the card works. [bjh21 20011202]
216 1.6.2.2 nathanw */
217 1.6.2.2 nathanw #if 0
218 1.6.2.2 nathanw
219 1.6.2.2 nathanw #ifndef OAK_TSIZE_OUT
220 1.6.2.2 nathanw #define OAK_TSIZE_OUT 128
221 1.6.2.2 nathanw #endif
222 1.6.2.2 nathanw
223 1.6.2.2 nathanw #ifndef OAK_TSIZE_IN
224 1.6.2.2 nathanw #define OAK_TSIZE_IN 128
225 1.6.2.2 nathanw #endif
226 1.6.2.2 nathanw
227 1.6.2.2 nathanw #define TIMEOUT 1000000
228 1.6.2.2 nathanw
229 1.6.2.2 nathanw static __inline int
230 1.6.2.2 nathanw oak_ready(struct ncr5380_softc *sc)
231 1.6.2.2 nathanw {
232 1.6.2.2 nathanw int i;
233 1.6.2.2 nathanw int status;
234 1.6.2.2 nathanw
235 1.6.2.2 nathanw for (i = TIMEOUT; i > 0; i--) {
236 1.6.2.2 nathanw status = NCR5380_READ(sc, sci_csr);
237 1.6.2.2 nathanw if ((status & (SCI_CSR_DREQ | SCI_CSR_PHASE_MATCH)) ==
238 1.6.2.2 nathanw (SCI_CSR_DREQ | SCI_CSR_PHASE_MATCH))
239 1.6.2.2 nathanw return(1);
240 1.6.2.2 nathanw
241 1.6.2.2 nathanw if ((status & SCI_CSR_PHASE_MATCH) == 0 ||
242 1.6.2.2 nathanw SCI_BUSY(sc) == 0)
243 1.6.2.2 nathanw return(0);
244 1.6.2.2 nathanw }
245 1.6.2.2 nathanw printf("%s: ready timeout\n", sc->sc_dev.dv_xname);
246 1.6.2.2 nathanw return(0);
247 1.6.2.2 nathanw
248 1.6.2.2 nathanw #if 0 /* The Linux driver does this: */
249 1.6.2.2 nathanw struct oak_softc *sc = (void *)ncr_sc;
250 1.6.2.2 nathanw bus_space_tag_t pdmat = sc->sc_pdmat;
251 1.6.2.2 nathanw bus_space_handle_t pdmah = sc->sc_pdmah;
252 1.6.2.2 nathanw int i, status;
253 1.6.2.2 nathanw
254 1.6.2.2 nathanw for (i = TIMEOUT; i > 0; i--) {
255 1.6.2.2 nathanw status = bus_space_read_2(pdmat, pdmah, OAK_PDMA_STATUS);
256 1.6.2.2 nathanw if (status & 0x200)
257 1.6.2.2 nathanw return(0);
258 1.6.2.2 nathanw if (status & 0x100)
259 1.6.2.2 nathanw return(1);
260 1.6.2.2 nathanw }
261 1.6.2.2 nathanw printf("%s: ready timeout, status = 0x%x\n", ncr_sc->sc_dev.dv_xname,
262 1.6.2.2 nathanw status);
263 1.6.2.2 nathanw return(0);
264 1.6.2.2 nathanw #endif
265 1.6.2.2 nathanw }
266 1.6.2.2 nathanw
267 1.6.2.2 nathanw
268 1.6.2.2 nathanw
269 1.6.2.2 nathanw /* Return zero on success. */
270 1.6.2.2 nathanw static __inline void oak_wait_not_req(struct ncr5380_softc *sc)
271 1.6.2.2 nathanw {
272 1.6.2.2 nathanw int timo;
273 1.6.2.2 nathanw for (timo = TIMEOUT; timo; timo--) {
274 1.6.2.2 nathanw if ((NCR5380_READ(sc, sci_bus_csr) & SCI_BUS_REQ) == 0 ||
275 1.6.2.2 nathanw (NCR5380_READ(sc, sci_csr) & SCI_CSR_PHASE_MATCH) == 0 ||
276 1.6.2.2 nathanw SCI_BUSY(sc) == 0) {
277 1.6.2.2 nathanw return;
278 1.6.2.2 nathanw }
279 1.6.2.2 nathanw }
280 1.6.2.2 nathanw printf("%s: pdma not_req timeout\n", sc->sc_dev.dv_xname);
281 1.6.2.2 nathanw }
282 1.6.2.2 nathanw
283 1.6.2.2 nathanw static int
284 1.6.2.2 nathanw oak_pdma_in(struct ncr5380_softc *ncr_sc, int phase, int datalen,
285 1.6.2.2 nathanw u_char *data)
286 1.6.2.2 nathanw {
287 1.6.2.2 nathanw struct oak_softc *sc = (void *)ncr_sc;
288 1.6.2.2 nathanw bus_space_tag_t pdmat = sc->sc_pdmat;
289 1.6.2.2 nathanw bus_space_handle_t pdmah = sc->sc_pdmah;
290 1.6.2.2 nathanw int s, resid, len;
291 1.6.2.2 nathanw
292 1.6.2.2 nathanw s = splbio();
293 1.6.2.2 nathanw
294 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
295 1.6.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) | SCI_MODE_DMA);
296 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_irecv, 0);
297 1.6.2.2 nathanw
298 1.6.2.2 nathanw resid = datalen;
299 1.6.2.2 nathanw while (resid > 0) {
300 1.6.2.2 nathanw len = min(resid, OAK_TSIZE_IN);
301 1.6.2.2 nathanw if (oak_ready(ncr_sc) == 0)
302 1.6.2.2 nathanw goto interrupt;
303 1.6.2.2 nathanw KASSERT(BUS_SPACE_ALIGNED_POINTER(data, u_int16_t));
304 1.6.2.2 nathanw bus_space_read_multi_2(pdmat, pdmah, OAK_PDMA_READ,
305 1.6.2.2 nathanw (u_int16_t *)data, len/2);
306 1.6.2.2 nathanw data += len;
307 1.6.2.2 nathanw resid -= len;
308 1.6.2.2 nathanw }
309 1.6.2.2 nathanw
310 1.6.2.2 nathanw oak_wait_not_req(ncr_sc);
311 1.6.2.2 nathanw
312 1.6.2.2 nathanw interrupt:
313 1.6.2.2 nathanw SCI_CLR_INTR(ncr_sc);
314 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
315 1.6.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) & ~SCI_MODE_DMA);
316 1.6.2.2 nathanw splx(s);
317 1.6.2.2 nathanw return datalen - resid;
318 1.6.2.2 nathanw }
319 1.6.2.2 nathanw
320 1.6.2.2 nathanw static int
321 1.6.2.2 nathanw oak_pdma_out(struct ncr5380_softc *ncr_sc, int phase, int datalen,
322 1.6.2.2 nathanw u_char *data)
323 1.6.2.2 nathanw {
324 1.6.2.2 nathanw struct oak_softc *sc = (void *)ncr_sc;
325 1.6.2.2 nathanw bus_space_tag_t pdmat = sc->sc_pdmat;
326 1.6.2.2 nathanw bus_space_handle_t pdmah = sc->sc_pdmah;
327 1.6.2.2 nathanw int i, s, icmd, resid;
328 1.6.2.2 nathanw
329 1.6.2.2 nathanw s = splbio();
330 1.6.2.2 nathanw icmd = NCR5380_READ(ncr_sc, sci_icmd) & SCI_ICMD_RMASK;
331 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_icmd, icmd | SCI_ICMD_DATA);
332 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
333 1.6.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) | SCI_MODE_DMA);
334 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_dma_send, 0);
335 1.6.2.2 nathanw
336 1.6.2.2 nathanw resid = datalen;
337 1.6.2.2 nathanw if (oak_ready(ncr_sc) == 0)
338 1.6.2.2 nathanw goto interrupt;
339 1.6.2.2 nathanw
340 1.6.2.2 nathanw if (resid > OAK_TSIZE_OUT) {
341 1.6.2.2 nathanw /*
342 1.6.2.2 nathanw * Because of the chips DMA prefetch, phase changes
343 1.6.2.2 nathanw * etc, won't be detected until we have written at
344 1.6.2.2 nathanw * least one byte more. We pre-write 4 bytes so
345 1.6.2.2 nathanw * subsequent transfers will be aligned to a 4 byte
346 1.6.2.2 nathanw * boundary. Assuming disconects will only occur on
347 1.6.2.2 nathanw * block boundaries, we then correct for the pre-write
348 1.6.2.2 nathanw * when and if we get a phase change. If the chip had
349 1.6.2.2 nathanw * DMA byte counting hardware, the assumption would not
350 1.6.2.2 nathanw * be necessary.
351 1.6.2.2 nathanw */
352 1.6.2.2 nathanw KASSERT(BUS_SPACE_ALIGNED_POINTER(data, u_int16_t));
353 1.6.2.2 nathanw bus_space_write_multi_2(pdmat, pdmah, OAK_PDMA_WRITE,
354 1.6.2.2 nathanw (u_int16_t *)data, 4/2);
355 1.6.2.2 nathanw data += 4;
356 1.6.2.2 nathanw resid -= 4;
357 1.6.2.2 nathanw
358 1.6.2.2 nathanw for (; resid >= OAK_TSIZE_OUT; resid -= OAK_TSIZE_OUT) {
359 1.6.2.2 nathanw if (oak_ready(ncr_sc) == 0) {
360 1.6.2.2 nathanw resid += 4; /* Overshot */
361 1.6.2.2 nathanw goto interrupt;
362 1.6.2.2 nathanw }
363 1.6.2.2 nathanw bus_space_write_multi_2(pdmat, pdmah, OAK_PDMA_WRITE,
364 1.6.2.2 nathanw (u_int16_t *)data, OAK_TSIZE_OUT/2);
365 1.6.2.2 nathanw data += OAK_TSIZE_OUT;
366 1.6.2.2 nathanw }
367 1.6.2.2 nathanw if (oak_ready(ncr_sc) == 0) {
368 1.6.2.2 nathanw resid += 4; /* Overshot */
369 1.6.2.2 nathanw goto interrupt;
370 1.6.2.2 nathanw }
371 1.6.2.2 nathanw }
372 1.6.2.2 nathanw
373 1.6.2.2 nathanw if (resid) {
374 1.6.2.2 nathanw bus_space_write_multi_2(pdmat, pdmah, OAK_PDMA_WRITE,
375 1.6.2.2 nathanw (u_int16_t *)data, resid/2);
376 1.6.2.2 nathanw resid = 0;
377 1.6.2.2 nathanw }
378 1.6.2.2 nathanw for (i = TIMEOUT; i > 0; i--) {
379 1.6.2.2 nathanw if ((NCR5380_READ(ncr_sc, sci_csr)
380 1.6.2.2 nathanw & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH))
381 1.6.2.2 nathanw != SCI_CSR_DREQ)
382 1.6.2.2 nathanw break;
383 1.6.2.2 nathanw }
384 1.6.2.2 nathanw if (i != 0)
385 1.6.2.2 nathanw bus_space_write_2(pdmat, pdmah, OAK_PDMA_WRITE, 0);
386 1.6.2.2 nathanw else
387 1.6.2.2 nathanw printf("%s: timeout waiting for final SCI_DSR_DREQ.\n",
388 1.6.2.2 nathanw ncr_sc->sc_dev.dv_xname);
389 1.6.2.2 nathanw
390 1.6.2.2 nathanw oak_wait_not_req(ncr_sc);
391 1.6.2.2 nathanw interrupt:
392 1.6.2.2 nathanw SCI_CLR_INTR(ncr_sc);
393 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_mode,
394 1.6.2.2 nathanw NCR5380_READ(ncr_sc, sci_mode) & ~SCI_MODE_DMA);
395 1.6.2.2 nathanw NCR5380_WRITE(ncr_sc, sci_icmd, icmd);
396 1.6.2.2 nathanw splx(s);
397 1.6.2.2 nathanw return(datalen - resid);
398 1.6.2.2 nathanw }
399 1.6.2.2 nathanw #endif
400