esp_mca.c revision 1.3.4.2 1 1.3.4.2 thorpej /* $NetBSD: esp_mca.c,v 1.3.4.2 2002/01/10 19:55:59 thorpej Exp $ */
2 1.3.4.2 thorpej
3 1.3.4.2 thorpej /*-
4 1.3.4.2 thorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.3.4.2 thorpej * All rights reserved.
6 1.3.4.2 thorpej *
7 1.3.4.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.3.4.2 thorpej * by Jaromir Dolecek <jdolecek (at) NetBSD.org>.
9 1.3.4.2 thorpej *
10 1.3.4.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.3.4.2 thorpej * modification, are permitted provided that the following conditions
12 1.3.4.2 thorpej * are met:
13 1.3.4.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.3.4.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.3.4.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.4.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.3.4.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.3.4.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.3.4.2 thorpej * must display the following acknowledgement:
20 1.3.4.2 thorpej * This product includes software developed by the NetBSD
21 1.3.4.2 thorpej * Foundation, Inc. and its contributors.
22 1.3.4.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3.4.2 thorpej * contributors may be used to endorse or promote products derived
24 1.3.4.2 thorpej * from this software without specific prior written permission.
25 1.3.4.2 thorpej *
26 1.3.4.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3.4.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3.4.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3.4.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3.4.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3.4.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3.4.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3.4.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3.4.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3.4.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3.4.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.3.4.2 thorpej */
38 1.3.4.2 thorpej
39 1.3.4.2 thorpej /*
40 1.3.4.2 thorpej * Driver for NCR 53c90, MCA version, with 86c01 DMA controller chip.
41 1.3.4.2 thorpej *
42 1.3.4.2 thorpej * Some of the information used to write this driver was taken
43 1.3.4.2 thorpej * from Tymm Twillman <tymm (at) computer.org>'s Linux MCA NC53c90 driver,
44 1.3.4.2 thorpej * in drivers/scsi/mca_53c9x.c
45 1.3.4.2 thorpej */
46 1.3.4.2 thorpej
47 1.3.4.2 thorpej #include <sys/types.h>
48 1.3.4.2 thorpej #include <sys/param.h>
49 1.3.4.2 thorpej #include <sys/systm.h>
50 1.3.4.2 thorpej #include <sys/kernel.h>
51 1.3.4.2 thorpej #include <sys/errno.h>
52 1.3.4.2 thorpej #include <sys/ioctl.h>
53 1.3.4.2 thorpej #include <sys/device.h>
54 1.3.4.2 thorpej #include <sys/buf.h>
55 1.3.4.2 thorpej #include <sys/proc.h>
56 1.3.4.2 thorpej #include <sys/user.h>
57 1.3.4.2 thorpej #include <sys/queue.h>
58 1.3.4.2 thorpej
59 1.3.4.2 thorpej #include <dev/scsipi/scsi_all.h>
60 1.3.4.2 thorpej #include <dev/scsipi/scsipi_all.h>
61 1.3.4.2 thorpej #include <dev/scsipi/scsiconf.h>
62 1.3.4.2 thorpej #include <dev/scsipi/scsi_message.h>
63 1.3.4.2 thorpej
64 1.3.4.2 thorpej #include <machine/bus.h>
65 1.3.4.2 thorpej #include <machine/cpu.h>
66 1.3.4.2 thorpej
67 1.3.4.2 thorpej #include <dev/ic/ncr53c9xreg.h>
68 1.3.4.2 thorpej #include <dev/ic/ncr53c9xvar.h>
69 1.3.4.2 thorpej
70 1.3.4.2 thorpej #include <dev/mca/espvar.h>
71 1.3.4.2 thorpej #include <dev/mca/espreg.h>
72 1.3.4.2 thorpej
73 1.3.4.2 thorpej #include <dev/mca/mcavar.h>
74 1.3.4.2 thorpej #include <dev/mca/mcareg.h>
75 1.3.4.2 thorpej #include <dev/mca/mcadevs.h>
76 1.3.4.2 thorpej
77 1.3.4.2 thorpej #if 0
78 1.3.4.2 thorpej #if defined(DEBUG) && !defined(NCR53C9X_DEBUG)
79 1.3.4.2 thorpej #define NCR53C9X_DEBUG
80 1.3.4.2 thorpej #endif
81 1.3.4.2 thorpej #endif
82 1.3.4.2 thorpej
83 1.3.4.2 thorpej #ifdef NCR53C9X_DEBUG
84 1.3.4.2 thorpej static int esp_mca_debug = 0;
85 1.3.4.2 thorpej #define DPRINTF(x) if (esp_mca_debug) printf x;
86 1.3.4.2 thorpej #else
87 1.3.4.2 thorpej #define DPRINTF(x)
88 1.3.4.2 thorpej #endif
89 1.3.4.2 thorpej
90 1.3.4.2 thorpej #define ESP_MCA_IOSIZE 0x20
91 1.3.4.2 thorpej #define ESP_REG_OFFSET 0x10
92 1.3.4.2 thorpej
93 1.3.4.2 thorpej static void esp_mca_attach __P((struct device *, struct device *, void *));
94 1.3.4.2 thorpej static int esp_mca_match __P((struct device *, struct cfdata *, void *));
95 1.3.4.2 thorpej
96 1.3.4.2 thorpej /* Linkup to the rest of the kernel */
97 1.3.4.2 thorpej struct cfattach esp_mca_ca = {
98 1.3.4.2 thorpej sizeof(struct esp_softc), esp_mca_match, esp_mca_attach
99 1.3.4.2 thorpej };
100 1.3.4.2 thorpej
101 1.3.4.2 thorpej /*
102 1.3.4.2 thorpej * Functions and the switch for the MI code.
103 1.3.4.2 thorpej */
104 1.3.4.2 thorpej static u_char esp_read_reg __P((struct ncr53c9x_softc *, int));
105 1.3.4.2 thorpej static void esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
106 1.3.4.2 thorpej static int esp_dma_isintr __P((struct ncr53c9x_softc *));
107 1.3.4.2 thorpej static void esp_dma_reset __P((struct ncr53c9x_softc *));
108 1.3.4.2 thorpej static int esp_dma_intr __P((struct ncr53c9x_softc *));
109 1.3.4.2 thorpej static int esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
110 1.3.4.2 thorpej size_t *, int, size_t *));
111 1.3.4.2 thorpej static void esp_dma_go __P((struct ncr53c9x_softc *));
112 1.3.4.2 thorpej static void esp_dma_stop __P((struct ncr53c9x_softc *));
113 1.3.4.2 thorpej static int esp_dma_isactive __P((struct ncr53c9x_softc *));
114 1.3.4.2 thorpej
115 1.3.4.2 thorpej static struct ncr53c9x_glue esp_glue = {
116 1.3.4.2 thorpej esp_read_reg,
117 1.3.4.2 thorpej esp_write_reg,
118 1.3.4.2 thorpej esp_dma_isintr,
119 1.3.4.2 thorpej esp_dma_reset,
120 1.3.4.2 thorpej esp_dma_intr,
121 1.3.4.2 thorpej esp_dma_setup,
122 1.3.4.2 thorpej esp_dma_go,
123 1.3.4.2 thorpej esp_dma_stop,
124 1.3.4.2 thorpej esp_dma_isactive,
125 1.3.4.2 thorpej NULL, /* gl_clear_latched_intr */
126 1.3.4.2 thorpej };
127 1.3.4.2 thorpej
128 1.3.4.2 thorpej static int
129 1.3.4.2 thorpej esp_mca_match(parent, cf, aux)
130 1.3.4.2 thorpej struct device *parent;
131 1.3.4.2 thorpej struct cfdata *cf;
132 1.3.4.2 thorpej void *aux;
133 1.3.4.2 thorpej {
134 1.3.4.2 thorpej struct mca_attach_args *ma = aux;
135 1.3.4.2 thorpej
136 1.3.4.2 thorpej switch (ma->ma_id) {
137 1.3.4.2 thorpej case MCA_PRODUCT_NCR53C90:
138 1.3.4.2 thorpej return 1;
139 1.3.4.2 thorpej }
140 1.3.4.2 thorpej
141 1.3.4.2 thorpej return 0;
142 1.3.4.2 thorpej }
143 1.3.4.2 thorpej
144 1.3.4.2 thorpej static void
145 1.3.4.2 thorpej esp_mca_attach(parent, self, aux)
146 1.3.4.2 thorpej struct device *parent, *self;
147 1.3.4.2 thorpej void *aux;
148 1.3.4.2 thorpej {
149 1.3.4.2 thorpej struct mca_attach_args *ma = aux;
150 1.3.4.2 thorpej struct esp_softc *esc = (void *)self;
151 1.3.4.2 thorpej struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
152 1.3.4.2 thorpej u_int16_t iobase;
153 1.3.4.2 thorpej int scsi_id, irq, drq, error;
154 1.3.4.2 thorpej bus_space_handle_t ioh;
155 1.3.4.2 thorpej int pos2, pos3, pos5;
156 1.3.4.2 thorpej
157 1.3.4.2 thorpej static const u_int16_t ncrmca_iobase[] = {
158 1.3.4.2 thorpej 0, 0x240, 0x340, 0x400, 0x420, 0x3240, 0x8240, 0xa240
159 1.3.4.2 thorpej };
160 1.3.4.2 thorpej
161 1.3.4.2 thorpej /*
162 1.3.4.2 thorpej * NCR SCSI Adapter (ADF 7f4f)
163 1.3.4.2 thorpej *
164 1.3.4.2 thorpej * POS register 2: (adf pos0)
165 1.3.4.2 thorpej *
166 1.3.4.2 thorpej * 7 6 5 4 3 2 1 0
167 1.3.4.2 thorpej * \_/ \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
168 1.3.4.2 thorpej * | \____ I/O base (32B): 001=0x240 010=0x340 011=0x400
169 1.3.4.2 thorpej * | 100=0x420 101=0x3240 110=0x8240 111=0xa240
170 1.3.4.2 thorpej * \__________ IRQ: 00=3 01=5 10=7 11=9
171 1.3.4.2 thorpej *
172 1.3.4.2 thorpej * POS register 3: (adf pos1)
173 1.3.4.2 thorpej *
174 1.3.4.2 thorpej * 7 6 5 4 3 2 1 0
175 1.3.4.2 thorpej * 1 1 1 | \_____/
176 1.3.4.2 thorpej * | \__ DMA level
177 1.3.4.2 thorpej * \_________ Fairness: 1=enabled 0=disabled
178 1.3.4.2 thorpej *
179 1.3.4.2 thorpej * POS register 5: (adf pos3)
180 1.3.4.2 thorpej *
181 1.3.4.2 thorpej * 7 6 5 4 3 2 1 0
182 1.3.4.2 thorpej * 1 | \___/
183 1.3.4.2 thorpej * | \__ Static Ram: 0xC8000-0xC87FF + XX*0x4000
184 1.3.4.2 thorpej * \___________ Host Adapter ID: 1=7 0=6
185 1.3.4.2 thorpej */
186 1.3.4.2 thorpej
187 1.3.4.2 thorpej pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
188 1.3.4.2 thorpej pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
189 1.3.4.2 thorpej pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
190 1.3.4.2 thorpej
191 1.3.4.2 thorpej iobase = ncrmca_iobase[(pos2 & 0x0e) >> 1];
192 1.3.4.2 thorpej irq = 3 + 2*((pos2 & 0x30) >> 4);
193 1.3.4.2 thorpej drq = (pos3 & 0x0f);
194 1.3.4.2 thorpej scsi_id = 6 + ((pos5 & 0x20) ? 1 : 0);
195 1.3.4.2 thorpej
196 1.3.4.2 thorpej printf(" slot %d irq %d drq %d: NCR SCSI Adapter\n",
197 1.3.4.2 thorpej ma->ma_slot + 1, irq, drq);
198 1.3.4.2 thorpej
199 1.3.4.2 thorpej /* Map the 86C01 registers */
200 1.3.4.2 thorpej if (bus_space_map(ma->ma_iot, iobase, ESP_MCA_IOSIZE, 0, &ioh)) {
201 1.3.4.2 thorpej printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
202 1.3.4.2 thorpej return;
203 1.3.4.2 thorpej }
204 1.3.4.2 thorpej
205 1.3.4.2 thorpej esc->sc_iot = ma->ma_iot;
206 1.3.4.2 thorpej esc->sc_ioh = ioh;
207 1.3.4.2 thorpej
208 1.3.4.2 thorpej /* Submap the 'esp' registers */
209 1.3.4.2 thorpej if (bus_space_subregion(ma->ma_iot, ioh, ESP_REG_OFFSET,
210 1.3.4.2 thorpej ESP_MCA_IOSIZE-ESP_REG_OFFSET, &esc->sc_esp_ioh)) {
211 1.3.4.2 thorpej printf("%s: can't subregion i/o space\n", sc->sc_dev.dv_xname);
212 1.3.4.2 thorpej return;
213 1.3.4.2 thorpej }
214 1.3.4.2 thorpej
215 1.3.4.2 thorpej /* Setup DMA map */
216 1.3.4.2 thorpej esc->sc_dmat = ma->ma_dmat;
217 1.3.4.2 thorpej if ((error = mca_dmamap_create(esc->sc_dmat, MAXPHYS,
218 1.3.4.2 thorpej BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW | MCABUS_DMA_IOPORT,
219 1.3.4.2 thorpej &esc->sc_xfer, drq)) != 0){
220 1.3.4.2 thorpej printf("%s: couldn't create DMA map - error %d\n",
221 1.3.4.2 thorpej sc->sc_dev.dv_xname, error);
222 1.3.4.2 thorpej return;
223 1.3.4.2 thorpej }
224 1.3.4.2 thorpej
225 1.3.4.2 thorpej /* MI code glue */
226 1.3.4.2 thorpej sc->sc_id = scsi_id;
227 1.3.4.2 thorpej sc->sc_freq = 25; /* Mhz */
228 1.3.4.2 thorpej
229 1.3.4.2 thorpej sc->sc_glue = &esp_glue;
230 1.3.4.2 thorpej
231 1.3.4.2 thorpej sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB; //| NCRCFG1_SLOW;
232 1.3.4.2 thorpej /* No point setting sc_cfg[2345], they won't be used */
233 1.3.4.2 thorpej
234 1.3.4.2 thorpej sc->sc_rev = NCR_VARIANT_NCR53C90_86C01;
235 1.3.4.2 thorpej sc->sc_minsync = 0;
236 1.3.4.2 thorpej
237 1.3.4.2 thorpej /* max 64KB DMA */
238 1.3.4.2 thorpej sc->sc_maxxfer = 64 * 1024;
239 1.3.4.2 thorpej
240 1.3.4.2 thorpej /* Establish interrupt */
241 1.3.4.2 thorpej esc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_BIO, ncr53c9x_intr,
242 1.3.4.2 thorpej esc);
243 1.3.4.2 thorpej if (esc->sc_ih == NULL) {
244 1.3.4.2 thorpej printf("%s: couldn't establish interrupt\n",
245 1.3.4.2 thorpej sc->sc_dev.dv_xname);
246 1.3.4.2 thorpej return;
247 1.3.4.2 thorpej }
248 1.3.4.2 thorpej
249 1.3.4.2 thorpej /*
250 1.3.4.2 thorpej * Massage the 86C01 chip - setup MCA DMA controller for DMA via
251 1.3.4.2 thorpej * the 86C01 register, and enable 86C01 interrupts.
252 1.3.4.2 thorpej */
253 1.3.4.2 thorpej mca_dma_set_ioport(drq, iobase + N86C01_PIO);
254 1.3.4.2 thorpej
255 1.3.4.2 thorpej bus_space_write_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE,
256 1.3.4.2 thorpej bus_space_read_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE)
257 1.3.4.2 thorpej | N86C01_INTR_ENABLE);
258 1.3.4.2 thorpej
259 1.3.4.2 thorpej /*
260 1.3.4.2 thorpej * Now try to attach all the sub-devices
261 1.3.4.2 thorpej */
262 1.3.4.2 thorpej sc->sc_adapter.adapt_minphys = minphys;
263 1.3.4.2 thorpej sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
264 1.3.4.2 thorpej
265 1.3.4.2 thorpej /* Do the common parts of attachment. */
266 1.3.4.2 thorpej printf("%s", sc->sc_dev.dv_xname);
267 1.3.4.2 thorpej ncr53c9x_attach(sc);
268 1.3.4.2 thorpej }
269 1.3.4.2 thorpej
270 1.3.4.2 thorpej /*
271 1.3.4.2 thorpej * Glue functions.
272 1.3.4.2 thorpej */
273 1.3.4.2 thorpej
274 1.3.4.2 thorpej static u_char
275 1.3.4.2 thorpej esp_read_reg(sc, reg)
276 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
277 1.3.4.2 thorpej int reg;
278 1.3.4.2 thorpej {
279 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *)sc;
280 1.3.4.2 thorpej
281 1.3.4.2 thorpej return (bus_space_read_1(esc->sc_iot, esc->sc_esp_ioh, reg));
282 1.3.4.2 thorpej }
283 1.3.4.2 thorpej
284 1.3.4.2 thorpej static void
285 1.3.4.2 thorpej esp_write_reg(sc, reg, val)
286 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
287 1.3.4.2 thorpej int reg;
288 1.3.4.2 thorpej u_char val;
289 1.3.4.2 thorpej {
290 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *)sc;
291 1.3.4.2 thorpej
292 1.3.4.2 thorpej bus_space_write_1(esc->sc_iot, esc->sc_esp_ioh, reg, val);
293 1.3.4.2 thorpej }
294 1.3.4.2 thorpej
295 1.3.4.2 thorpej static int
296 1.3.4.2 thorpej esp_dma_isintr(sc)
297 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
298 1.3.4.2 thorpej {
299 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *)sc;
300 1.3.4.2 thorpej
301 1.3.4.2 thorpej DPRINTF(("[esp_dma_isintr] "));
302 1.3.4.2 thorpej return (bus_space_read_1(esc->sc_iot, esc->sc_ioh,
303 1.3.4.2 thorpej N86C01_STATUS) & N86C01_IRQ_PEND);
304 1.3.4.2 thorpej }
305 1.3.4.2 thorpej
306 1.3.4.2 thorpej static void
307 1.3.4.2 thorpej esp_dma_reset(sc)
308 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
309 1.3.4.2 thorpej {
310 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *)sc;
311 1.3.4.2 thorpej
312 1.3.4.2 thorpej DPRINTF(("[esp_dma_reset] "));
313 1.3.4.2 thorpej
314 1.3.4.2 thorpej if (esc->sc_flags & ESP_XFER_LOADED) {
315 1.3.4.2 thorpej bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
316 1.3.4.2 thorpej esc->sc_flags &= ~ESP_XFER_LOADED;
317 1.3.4.2 thorpej }
318 1.3.4.2 thorpej
319 1.3.4.2 thorpej if (esc->sc_flags & ESP_XFER_ACTIVE) {
320 1.3.4.2 thorpej esc->sc_flags &= ~ESP_XFER_ACTIVE;
321 1.3.4.2 thorpej mca_disk_unbusy();
322 1.3.4.2 thorpej }
323 1.3.4.2 thorpej }
324 1.3.4.2 thorpej
325 1.3.4.2 thorpej static int
326 1.3.4.2 thorpej esp_dma_intr(sc)
327 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
328 1.3.4.2 thorpej {
329 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *) sc;
330 1.3.4.2 thorpej DPRINTF(("[esp_dma_intr] "));
331 1.3.4.2 thorpej
332 1.3.4.2 thorpej if ((esc->sc_flags & ESP_XFER_ACTIVE) == 0) {
333 1.3.4.2 thorpej printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
334 1.3.4.2 thorpej return (-1);
335 1.3.4.2 thorpej }
336 1.3.4.2 thorpej
337 1.3.4.2 thorpej if ((sc->sc_espintr & NCRINTR_BS) == 0) {
338 1.3.4.2 thorpej esc->sc_flags &= ~ESP_XFER_ACTIVE;
339 1.3.4.2 thorpej mca_disk_unbusy();
340 1.3.4.2 thorpej return (0);
341 1.3.4.2 thorpej }
342 1.3.4.2 thorpej
343 1.3.4.2 thorpej sc->sc_espstat |= NCRSTAT_TC; /* XXX */
344 1.3.4.2 thorpej
345 1.3.4.2 thorpej if ((sc->sc_espstat & NCRSTAT_TC) == 0) {
346 1.3.4.2 thorpej printf("%s: DMA not complete?\n", sc->sc_dev.dv_xname);
347 1.3.4.2 thorpej return (1);
348 1.3.4.2 thorpej }
349 1.3.4.2 thorpej
350 1.3.4.2 thorpej bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0,
351 1.3.4.2 thorpej *esc->sc_xfer_len,
352 1.3.4.2 thorpej (esc->sc_flags & ESP_XFER_READ)
353 1.3.4.2 thorpej ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
354 1.3.4.2 thorpej
355 1.3.4.2 thorpej bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
356 1.3.4.2 thorpej esc->sc_flags &= ~ESP_XFER_LOADED;
357 1.3.4.2 thorpej
358 1.3.4.2 thorpej *esc->sc_xfer_addr += *esc->sc_xfer_len;
359 1.3.4.2 thorpej *esc->sc_xfer_len = 0;
360 1.3.4.2 thorpej
361 1.3.4.2 thorpej esc->sc_flags &= ~ESP_XFER_ACTIVE;
362 1.3.4.2 thorpej mca_disk_unbusy();
363 1.3.4.2 thorpej
364 1.3.4.2 thorpej return (0);
365 1.3.4.2 thorpej }
366 1.3.4.2 thorpej
367 1.3.4.2 thorpej /*
368 1.3.4.2 thorpej * Setup DMA transfer.
369 1.3.4.2 thorpej */
370 1.3.4.2 thorpej static int
371 1.3.4.2 thorpej esp_dma_setup(sc, addr, len, datain, dmasize)
372 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
373 1.3.4.2 thorpej caddr_t *addr;
374 1.3.4.2 thorpej size_t *len;
375 1.3.4.2 thorpej int datain;
376 1.3.4.2 thorpej size_t *dmasize;
377 1.3.4.2 thorpej {
378 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *) sc;
379 1.3.4.2 thorpej int error;
380 1.3.4.2 thorpej int fl;
381 1.3.4.2 thorpej
382 1.3.4.2 thorpej DPRINTF(("[esp_dma_setup] "));
383 1.3.4.2 thorpej
384 1.3.4.2 thorpej if (esc->sc_flags & ESP_XFER_LOADED) {
385 1.3.4.2 thorpej printf("%s: esp_dma_setup: unloading leaked xfer\n",
386 1.3.4.2 thorpej sc->sc_dev.dv_xname);
387 1.3.4.2 thorpej bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
388 1.3.4.2 thorpej esc->sc_flags &= ~ESP_XFER_LOADED;
389 1.3.4.2 thorpej }
390 1.3.4.2 thorpej
391 1.3.4.2 thorpej /* Load the buffer for DMA transfer. */
392 1.3.4.2 thorpej fl = (datain) ? BUS_DMA_READ : BUS_DMA_WRITE;
393 1.3.4.2 thorpej
394 1.3.4.2 thorpej if ((error = bus_dmamap_load(esc->sc_dmat, esc->sc_xfer, *addr,
395 1.3.4.2 thorpej *len, NULL, BUS_DMA_STREAMING|fl))) {
396 1.3.4.2 thorpej printf("%s: esp_dma_setup: unable to load DMA buffer - error %d\n",
397 1.3.4.2 thorpej sc->sc_dev.dv_xname, error);
398 1.3.4.2 thorpej return (error);
399 1.3.4.2 thorpej }
400 1.3.4.2 thorpej
401 1.3.4.2 thorpej bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0,
402 1.3.4.2 thorpej *len, (datain) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
403 1.3.4.2 thorpej
404 1.3.4.2 thorpej esc->sc_flags |= ESP_XFER_LOADED | (datain ? ESP_XFER_READ : 0);
405 1.3.4.2 thorpej esc->sc_xfer_addr = addr;
406 1.3.4.2 thorpej esc->sc_xfer_len = len;
407 1.3.4.2 thorpej
408 1.3.4.2 thorpej return (0);
409 1.3.4.2 thorpej }
410 1.3.4.2 thorpej
411 1.3.4.2 thorpej static void
412 1.3.4.2 thorpej esp_dma_go(sc)
413 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
414 1.3.4.2 thorpej {
415 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *) sc;
416 1.3.4.2 thorpej DPRINTF(("[esp_dma_go] "));
417 1.3.4.2 thorpej
418 1.3.4.2 thorpej esc->sc_flags |= ESP_XFER_ACTIVE;
419 1.3.4.2 thorpej mca_disk_busy();
420 1.3.4.2 thorpej }
421 1.3.4.2 thorpej
422 1.3.4.2 thorpej static void
423 1.3.4.2 thorpej esp_dma_stop(sc)
424 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
425 1.3.4.2 thorpej {
426 1.3.4.2 thorpej DPRINTF(("[esp_dma_stop] "));
427 1.3.4.2 thorpej
428 1.3.4.2 thorpej panic("%s: stop not yet implemented", sc->sc_dev.dv_xname);
429 1.3.4.2 thorpej }
430 1.3.4.2 thorpej
431 1.3.4.2 thorpej static int
432 1.3.4.2 thorpej esp_dma_isactive(sc)
433 1.3.4.2 thorpej struct ncr53c9x_softc *sc;
434 1.3.4.2 thorpej {
435 1.3.4.2 thorpej struct esp_softc *esc = (struct esp_softc *) sc;
436 1.3.4.2 thorpej DPRINTF(("[esp_dma_isactive] "));
437 1.3.4.2 thorpej
438 1.3.4.2 thorpej return (esc->sc_flags & ESP_XFER_ACTIVE);
439 1.3.4.2 thorpej }
440