scsi.c revision 1.13 1 1.13 tsutsui /* $NetBSD: scsi.c,v 1.13 2023/02/12 08:25:09 tsutsui Exp $ */
2 1.1 dbj /*
3 1.1 dbj * Copyright (c) 1994, 1997 Rolf Grossmann
4 1.1 dbj * All rights reserved.
5 1.1 dbj *
6 1.1 dbj * Redistribution and use in source and binary forms, with or without
7 1.1 dbj * modification, are permitted provided that the following conditions
8 1.1 dbj * are met:
9 1.1 dbj * 1. Redistributions of source code must retain the above copyright
10 1.1 dbj * notice, this list of conditions and the following disclaimer.
11 1.1 dbj * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 dbj * notice, this list of conditions and the following disclaimer in the
13 1.1 dbj * documentation and/or other materials provided with the distribution.
14 1.1 dbj * 3. All advertising materials mentioning features or use of this software
15 1.1 dbj * must display the following acknowledgement:
16 1.1 dbj * This product includes software developed by Rolf Grossmann.
17 1.1 dbj * 4. The name of the author may not be used to endorse or promote products
18 1.1 dbj * derived from this software without specific prior written permission
19 1.1 dbj *
20 1.1 dbj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 dbj * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 dbj * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 dbj * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 dbj * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 dbj * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 dbj * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 dbj * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 dbj * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 dbj * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 dbj */
31 1.1 dbj
32 1.1 dbj #include <sys/param.h>
33 1.1 dbj #include <next68k/dev/espreg.h>
34 1.3 jdolecek #include <dev/ic/ncr53c9xreg.h>
35 1.1 dbj #include <dev/scsipi/scsi_message.h>
36 1.1 dbj #include <next68k/next68k/nextrom.h>
37 1.1 dbj #include "scsireg.h"
38 1.1 dbj #include "dmareg.h"
39 1.1 dbj #include "scsivar.h"
40 1.1 dbj
41 1.1 dbj #include <lib/libsa/stand.h>
42 1.1 dbj
43 1.13 tsutsui #include "samachdep.h"
44 1.13 tsutsui
45 1.1 dbj struct scsi_softc scsi_softc, *sc = &scsi_softc;
46 1.1 dbj char the_dma_buffer[MAX_DMASIZE+DMA_ENDALIGNMENT], *dma_buffer;
47 1.1 dbj
48 1.1 dbj int scsi_msgin(void);
49 1.1 dbj int dma_start(char *addr, int len);
50 1.1 dbj int dma_done(void);
51 1.1 dbj
52 1.2 dbj void scsierror(char *error);
53 1.9 he short scsi_getbyte(volatile uint8_t *sr);
54 1.2 dbj int scsi_wait_for_intr(void);
55 1.2 dbj
56 1.4 christos #define NDPRINTF(x)
57 1.4 christos #define PRINTF(x)
58 1.4 christos /* printf x; */
59 1.12 tsutsui #ifdef SCSI_DEBUG
60 1.1 dbj #define DPRINTF(x) printf x;
61 1.1 dbj #else
62 1.1 dbj #define DPRINTF(x)
63 1.1 dbj #endif
64 1.1 dbj
65 1.1 dbj void
66 1.1 dbj scsi_init(void)
67 1.1 dbj {
68 1.9 he volatile uint8_t *sr;
69 1.1 dbj struct dma_dev *dma;
70 1.1 dbj
71 1.1 dbj sr = P_SCSI;
72 1.1 dbj dma = (struct dma_dev *)P_SCSI_CSR;
73 1.1 dbj
74 1.1 dbj dma_buffer = DMA_ALIGN(char *, the_dma_buffer);
75 1.11 tsutsui
76 1.1 dbj P_FLOPPY[FLP_CTRL] &= ~FLC_82077_SEL; /* select SCSI chip */
77 1.1 dbj
78 1.6 wiz /* first reset DMA */
79 1.1 dbj dma->dd_csr = DMACSR_RESET;
80 1.1 dbj DELAY(200);
81 1.1 dbj sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB | ESPDCTL_RESET;
82 1.1 dbj DELAY(10);
83 1.1 dbj sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB;
84 1.1 dbj DELAY(10);
85 1.1 dbj
86 1.1 dbj /* then reset the SCSI chip */
87 1.3 jdolecek sr[NCR_CMD] = NCRCMD_RSTCHIP;
88 1.3 jdolecek sr[NCR_CMD] = NCRCMD_NOP;
89 1.1 dbj DELAY(500);
90 1.1 dbj
91 1.1 dbj /* now reset the SCSI bus */
92 1.3 jdolecek sr[NCR_CMD] = NCRCMD_RSTSCSI;
93 1.4 christos DELAY(4000000); /* XXX should be about 2-3 seconds at least */
94 1.11 tsutsui
95 1.1 dbj /* then reset the SCSI chip again and initialize it properly */
96 1.3 jdolecek sr[NCR_CMD] = NCRCMD_RSTCHIP;
97 1.3 jdolecek sr[NCR_CMD] = NCRCMD_NOP;
98 1.1 dbj DELAY(500);
99 1.3 jdolecek sr[NCR_CFG1] = NCRCFG1_SLOW | NCRCFG1_BUSID;
100 1.3 jdolecek sr[NCR_CFG2] = 0;
101 1.3 jdolecek sr[NCR_CCF] = 4; /* S5RCLKCONV_FACTOR(20); */
102 1.3 jdolecek sr[NCR_TIMEOUT] = 152; /* S5RSELECT_TIMEOUT(20,250); */
103 1.3 jdolecek sr[NCR_SYNCOFF] = 0;
104 1.3 jdolecek sr[NCR_SYNCTP] = 5;
105 1.1 dbj /*
106 1.1 dbj sc->sc_intrstatus = sr->s5r_intrstatus;
107 1.1 dbj sc->sc_intrstatus = sr->s5r_intrstatus;
108 1.1 dbj */
109 1.3 jdolecek sr[NCR_CFG1] = NCRCFG1_PARENB | NCRCFG1_BUSID;
110 1.1 dbj
111 1.1 dbj sc->sc_state = SCSI_IDLE;
112 1.1 dbj }
113 1.1 dbj
114 1.1 dbj void
115 1.1 dbj scsierror(char *error)
116 1.1 dbj {
117 1.1 dbj printf("scsierror: %s.\n", error);
118 1.1 dbj }
119 1.1 dbj
120 1.1 dbj short
121 1.9 he scsi_getbyte(volatile uint8_t *sr)
122 1.1 dbj {
123 1.11 tsutsui if ((sr[NCR_FFLAG] & NCRFIFO_FF) == 0)
124 1.1 dbj {
125 1.1 dbj printf("getbyte: no data!\n");
126 1.1 dbj return -1;
127 1.1 dbj }
128 1.3 jdolecek return sr[NCR_FIFO];
129 1.1 dbj }
130 1.1 dbj
131 1.1 dbj int
132 1.1 dbj scsi_wait_for_intr(void)
133 1.1 dbj {
134 1.1 dbj #define MON(type, off) (*(type *)((u_int) (mg) + off))
135 1.1 dbj volatile int *intrstat = MON(volatile int *,MG_intrstat);
136 1.4 christos #ifdef SCSI_DEBUG
137 1.4 christos /* volatile int *intrmask = MON(volatile int *,MG_intrmask); */
138 1.4 christos #endif
139 1.1 dbj int count;
140 1.1 dbj
141 1.2 dbj for(count = 0; count < SCSI_TIMEOUT; count++) {
142 1.4 christos NDPRINTF((" *intrstat = 0x%x\t*intrmask = 0x%x\n",*intrstat,*intrmask));
143 1.2 dbj
144 1.1 dbj if (*intrstat & SCSI_INTR)
145 1.1 dbj return 0;
146 1.2 dbj }
147 1.1 dbj
148 1.1 dbj printf("scsiicmd: timed out.\n");
149 1.1 dbj return -1;
150 1.1 dbj }
151 1.1 dbj
152 1.1 dbj int
153 1.1 dbj scsiicmd(char target, char lun,
154 1.1 dbj u_char *cbuf, int clen,
155 1.4 christos char *addr, int *len)
156 1.1 dbj {
157 1.9 he volatile uint8_t *sr;
158 1.1 dbj int i;
159 1.1 dbj
160 1.1 dbj DPRINTF(("scsiicmd: [%x, %d] -> %d (%lx, %d)\n",*cbuf, clen,
161 1.4 christos target, (long)addr, *len));
162 1.1 dbj sr = P_SCSI;
163 1.1 dbj
164 1.1 dbj if (sc->sc_state != SCSI_IDLE) {
165 1.1 dbj scsierror("scsiiscmd: bad state");
166 1.1 dbj return EIO;
167 1.1 dbj }
168 1.1 dbj sc->sc_result = 0;
169 1.1 dbj
170 1.1 dbj /* select target */
171 1.3 jdolecek sr[NCR_CMD] = NCRCMD_FLUSH;
172 1.1 dbj DELAY(10);
173 1.3 jdolecek sr[NCR_SELID] = target;
174 1.3 jdolecek sr[NCR_FIFO] = MSG_IDENTIFY(lun, 0);
175 1.1 dbj for (i=0; i<clen; i++)
176 1.3 jdolecek sr[NCR_FIFO] = cbuf[i];
177 1.3 jdolecek sr[NCR_CMD] = NCRCMD_SELATN;
178 1.1 dbj sc->sc_state = SCSI_SELECTING;
179 1.11 tsutsui
180 1.1 dbj while(sc->sc_state != SCSI_DONE) {
181 1.1 dbj if (scsi_wait_for_intr()) /* maybe we'd better use real intrs ? */
182 1.1 dbj return EIO;
183 1.1 dbj
184 1.1 dbj if (sc->sc_state == SCSI_DMA)
185 1.1 dbj {
186 1.6 wiz /* registers are not valid on DMA intr */
187 1.1 dbj sc->sc_status = sc->sc_seqstep = sc->sc_intrstatus = 0;
188 1.6 wiz DPRINTF(("scsiicmd: DMA intr\n"));
189 1.4 christos sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB | ESPDCTL_DMARD;
190 1.1 dbj }
191 1.4 christos
192 1.4 christos /* scsi processing */
193 1.4 christos sc->sc_status = sr[NCR_STAT];
194 1.4 christos sc->sc_seqstep = sr[NCR_STEP];
195 1.4 christos sc->sc_intrstatus = sr[NCR_INTR];
196 1.4 christos redo:
197 1.4 christos DPRINTF(("scsiicmd: regs[intr=%x, stat=%x, step=%x]\n",
198 1.4 christos sc->sc_intrstatus, sc->sc_status, sc->sc_seqstep));
199 1.11 tsutsui
200 1.3 jdolecek if (sc->sc_intrstatus & NCRINTR_SBR) {
201 1.1 dbj scsierror("scsi bus reset");
202 1.1 dbj return EIO;
203 1.1 dbj }
204 1.11 tsutsui
205 1.3 jdolecek if ((sc->sc_status & NCRSTAT_GE)
206 1.3 jdolecek || (sc->sc_intrstatus & NCRINTR_ILL)) {
207 1.1 dbj scsierror("software error");
208 1.1 dbj return EIO;
209 1.1 dbj }
210 1.3 jdolecek if (sc->sc_status & NCRSTAT_PE)
211 1.1 dbj {
212 1.1 dbj scsierror("parity error");
213 1.1 dbj return EIO;
214 1.1 dbj }
215 1.1 dbj
216 1.1 dbj switch(sc->sc_state)
217 1.1 dbj {
218 1.1 dbj case SCSI_SELECTING:
219 1.11 tsutsui if (sc->sc_intrstatus & NCRINTR_DIS)
220 1.1 dbj {
221 1.1 dbj sc->sc_state = SCSI_IDLE;
222 1.1 dbj return EUNIT; /* device not present */
223 1.1 dbj }
224 1.11 tsutsui
225 1.3 jdolecek #define NCRINTR_DONE (NCRINTR_BS | NCRINTR_FC)
226 1.3 jdolecek if ((sc->sc_intrstatus & NCRINTR_DONE) != NCRINTR_DONE)
227 1.1 dbj {
228 1.1 dbj scsierror("selection failed");
229 1.1 dbj return EIO;
230 1.1 dbj }
231 1.1 dbj sc->sc_state = SCSI_HASBUS;
232 1.1 dbj break;
233 1.1 dbj case SCSI_HASBUS:
234 1.3 jdolecek if (sc->sc_intrstatus & NCRINTR_DIS)
235 1.1 dbj {
236 1.1 dbj scsierror("target disconnected");
237 1.1 dbj return EIO;
238 1.1 dbj }
239 1.1 dbj break;
240 1.1 dbj case SCSI_DMA:
241 1.3 jdolecek if (sc->sc_intrstatus & NCRINTR_DIS)
242 1.1 dbj {
243 1.1 dbj scsierror("target disconnected");
244 1.1 dbj return EIO;
245 1.1 dbj }
246 1.4 christos *len = dma_done();
247 1.4 christos if (*len < 0) {
248 1.4 christos *len = 0;
249 1.4 christos return EIO;
250 1.4 christos }
251 1.4 christos /* continue; */
252 1.4 christos sc->sc_status = sr[NCR_STAT];
253 1.4 christos goto redo;
254 1.4 christos break;
255 1.1 dbj case SCSI_CLEANUP:
256 1.3 jdolecek if (sc->sc_intrstatus & NCRINTR_DIS)
257 1.1 dbj {
258 1.1 dbj sc->sc_state = SCSI_DONE;
259 1.1 dbj continue;
260 1.1 dbj }
261 1.1 dbj DPRINTF(("hmm ... no disconnect on cleanup?\n"));
262 1.1 dbj sc->sc_state = SCSI_DONE; /* maybe ... */
263 1.1 dbj break;
264 1.1 dbj }
265 1.1 dbj
266 1.1 dbj /* transfer information now */
267 1.3 jdolecek switch(sc->sc_status & NCRSTAT_PHASE)
268 1.1 dbj {
269 1.1 dbj case DATA_IN_PHASE:
270 1.4 christos sr[NCR_CMD] = NCRCMD_FLUSH;
271 1.4 christos if (dma_start(addr, *len) != 0)
272 1.1 dbj return EIO;
273 1.1 dbj break;
274 1.1 dbj case DATA_OUT_PHASE:
275 1.1 dbj scsierror("data out phase not implemented");
276 1.1 dbj return EIO;
277 1.1 dbj case STATUS_PHASE:
278 1.1 dbj DPRINTF(("status phase: "));
279 1.3 jdolecek sr[NCR_CMD] = NCRCMD_ICCS;
280 1.1 dbj sc->sc_result = scsi_getbyte(sr);
281 1.1 dbj DPRINTF(("status is 0x%x.\n", sc->sc_result));
282 1.1 dbj break;
283 1.1 dbj case MSG_IN_PHASE:
284 1.4 christos if ((sc->sc_intrstatus & NCRINTR_BS) != 0) {
285 1.4 christos sr[NCR_CMD] = NCRCMD_FLUSH;
286 1.4 christos sr[NCR_CMD] = NCRCMD_TRANS;
287 1.4 christos } else
288 1.4 christos if (scsi_msgin() != 0)
289 1.4 christos return EIO;
290 1.4 christos break;
291 1.1 dbj default:
292 1.1 dbj DPRINTF(("phase not implemented: 0x%x.\n",
293 1.3 jdolecek sc->sc_status & NCRSTAT_PHASE));
294 1.1 dbj scsierror("bad phase");
295 1.1 dbj return EIO;
296 1.1 dbj }
297 1.1 dbj }
298 1.1 dbj
299 1.1 dbj sc->sc_state = SCSI_IDLE;
300 1.1 dbj return -sc->sc_result;
301 1.1 dbj }
302 1.11 tsutsui
303 1.1 dbj int
304 1.1 dbj scsi_msgin(void)
305 1.1 dbj {
306 1.9 he volatile uint8_t *sr;
307 1.1 dbj u_char msg;
308 1.1 dbj
309 1.1 dbj sr = P_SCSI;
310 1.1 dbj
311 1.1 dbj msg = scsi_getbyte(sr);
312 1.1 dbj if (msg)
313 1.1 dbj {
314 1.1 dbj printf("unexpected msg: 0x%x.\n",msg);
315 1.1 dbj return -1;
316 1.1 dbj }
317 1.3 jdolecek if ((sc->sc_intrstatus & NCRINTR_FC) == 0)
318 1.1 dbj {
319 1.1 dbj printf("not function complete.\n");
320 1.1 dbj return -1;
321 1.1 dbj }
322 1.1 dbj sc->sc_state = SCSI_CLEANUP;
323 1.3 jdolecek sr[NCR_CMD] = NCRCMD_MSGOK;
324 1.1 dbj return 0;
325 1.1 dbj }
326 1.1 dbj
327 1.1 dbj int
328 1.1 dbj dma_start(char *addr, int len)
329 1.1 dbj {
330 1.9 he volatile uint8_t *sr;
331 1.1 dbj struct dma_dev *dma;
332 1.11 tsutsui
333 1.1 dbj sr = P_SCSI;
334 1.1 dbj dma = (struct dma_dev *)P_SCSI_CSR;
335 1.11 tsutsui
336 1.1 dbj if (len > MAX_DMASIZE)
337 1.1 dbj {
338 1.6 wiz scsierror("DMA too long");
339 1.1 dbj return -1;
340 1.1 dbj }
341 1.1 dbj
342 1.1 dbj if (addr == NULL || len == 0)
343 1.1 dbj {
344 1.1 dbj #if 0 /* I'd take that as an error in my code */
345 1.6 wiz DPRINTF(("hmm ... no DMA requested.\n"));
346 1.3 jdolecek sr[NCR_TCL] = 0;
347 1.3 jdolecek sr[NCR_TCM] = 1;
348 1.3 jdolecek sr[NCR_CMD] = NCRCMD_NOP;
349 1.3 jdolecek sr[NCR_CMD] = NCRCMD_DMA | NCRCMD_TRPAD;
350 1.1 dbj return 0;
351 1.1 dbj #else
352 1.6 wiz scsierror("unrequested DMA");
353 1.1 dbj return -1;
354 1.1 dbj #endif
355 1.1 dbj }
356 1.11 tsutsui
357 1.6 wiz PRINTF(("DMA start: %lx, %d byte.\n", (long)addr, len));
358 1.2 dbj
359 1.11 tsutsui DPRINTF(("dma_bufffer: start: 0x%lx end: 0x%lx \n",
360 1.2 dbj (long)dma_buffer,(long)DMA_ENDALIGN(char *, dma_buffer+len)));
361 1.2 dbj
362 1.1 dbj sc->dma_addr = addr;
363 1.1 dbj sc->dma_len = len;
364 1.11 tsutsui
365 1.3 jdolecek sr[NCR_TCL] = len & 0xff;
366 1.3 jdolecek sr[NCR_TCM] = len >> 8;
367 1.3 jdolecek sr[NCR_CMD] = NCRCMD_DMA | NCRCMD_NOP;
368 1.3 jdolecek sr[NCR_CMD] = NCRCMD_DMA | NCRCMD_TRANS;
369 1.2 dbj
370 1.2 dbj #if 0
371 1.1 dbj dma->dd_csr = DMACSR_READ | DMACSR_RESET;
372 1.1 dbj dma->dd_next_initbuf = dma_buffer;
373 1.1 dbj dma->dd_limit = DMA_ENDALIGN(char *, dma_buffer+len);
374 1.1 dbj dma->dd_csr = DMACSR_READ | DMACSR_SETENABLE;
375 1.2 dbj #else
376 1.2 dbj dma->dd_csr = 0;
377 1.2 dbj dma->dd_csr = DMACSR_INITBUF | DMACSR_READ | DMACSR_RESET;
378 1.4 christos dma->dd_next = dma_buffer;
379 1.2 dbj dma->dd_limit = DMA_ENDALIGN(char *, dma_buffer+len);
380 1.2 dbj dma->dd_csr = DMACSR_READ | DMACSR_SETENABLE;
381 1.2 dbj #endif
382 1.2 dbj
383 1.1 dbj sr[ESP_DCTL] = ESPDCTL_20MHZ|ESPDCTL_INTENB|ESPDCTL_DMAMOD|ESPDCTL_DMARD;
384 1.1 dbj
385 1.1 dbj sc->sc_state = SCSI_DMA;
386 1.1 dbj return 0;
387 1.1 dbj }
388 1.1 dbj
389 1.1 dbj int
390 1.1 dbj dma_done(void)
391 1.1 dbj {
392 1.9 he volatile uint8_t *sr;
393 1.1 dbj struct dma_dev *dma;
394 1.4 christos int resid, state;
395 1.4 christos int flushcount = 0;
396 1.11 tsutsui
397 1.1 dbj sr = P_SCSI;
398 1.1 dbj dma = (struct dma_dev *)P_SCSI_CSR;
399 1.1 dbj
400 1.1 dbj state = dma->dd_csr & (DMACSR_BUSEXC | DMACSR_COMPLETE
401 1.1 dbj | DMACSR_SUPDATE | DMACSR_ENABLE);
402 1.1 dbj
403 1.4 christos sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB | ESPDCTL_DMARD;
404 1.4 christos resid = sr[NCR_TCM]<<8 | sr[NCR_TCL];
405 1.6 wiz DPRINTF(("DMA state = 0x%x, remain = %d.\n", state, resid));
406 1.4 christos
407 1.4 christos if (!(sr[NCR_FFLAG] & NCRFIFO_FF)) {
408 1.4 christos sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD
409 1.4 christos | ESPDCTL_DMARD;
410 1.11 tsutsui while (!(state & DMACSR_COMPLETE) && (state & DMACSR_ENABLE) && flushcount < 16)
411 1.4 christos {
412 1.11 tsutsui
413 1.6 wiz DPRINTF(("DMA still enabled, flushing DCTL.\n"));
414 1.11 tsutsui
415 1.4 christos sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD
416 1.4 christos | ESPDCTL_DMARD | ESPDCTL_FLUSH;
417 1.4 christos sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD
418 1.4 christos | ESPDCTL_DMARD;
419 1.11 tsutsui
420 1.4 christos flushcount++;
421 1.4 christos state = dma->dd_csr & (DMACSR_BUSEXC | DMACSR_COMPLETE
422 1.4 christos | DMACSR_SUPDATE | DMACSR_ENABLE);
423 1.4 christos }
424 1.1 dbj }
425 1.4 christos sr[ESP_DCTL] = ESPDCTL_20MHZ | ESPDCTL_INTENB;
426 1.4 christos resid = (sr[NCR_TCM]<<8) + sr[NCR_TCL];
427 1.1 dbj
428 1.4 christos dma->dd_csr = DMACSR_CLRCOMPLETE | DMACSR_RESET;
429 1.1 dbj
430 1.6 wiz DPRINTF(("DMA done. remain = %d, state = 0x%x, fifo = 0x%x.\n", resid, state, sr[NCR_FFLAG] & NCRFIFO_FF));
431 1.1 dbj
432 1.4 christos if (resid != 0)
433 1.1 dbj {
434 1.5 mycroft #if 1
435 1.6 wiz printf("WARNING: unexpected %d characters remain in DMA\n",resid);
436 1.6 wiz scsierror("DMA transfer incomplete");
437 1.1 dbj return -1;
438 1.1 dbj #endif
439 1.1 dbj }
440 1.1 dbj
441 1.1 dbj if (state & DMACSR_BUSEXC)
442 1.1 dbj {
443 1.5 mycroft #if 0
444 1.6 wiz scsierror("DMA failed");
445 1.1 dbj return -1;
446 1.5 mycroft #endif
447 1.1 dbj }
448 1.4 christos
449 1.4 christos sc->dma_len -= resid;
450 1.4 christos if (sc->dma_len < 0)
451 1.4 christos sc->dma_len = 0;
452 1.10 he memcpy(sc->dma_addr, dma_buffer, sc->dma_len);
453 1.4 christos sc->sc_state = SCSI_HASBUS;
454 1.6 wiz DPRINTF(("DMA done. got %d.\n", sc->dma_len));
455 1.4 christos return sc->dma_len;
456 1.4 christos
457 1.6 wiz /* scsierror("DMA not completed\n"); */
458 1.11 tsutsui
459 1.4 christos return 0;
460 1.1 dbj }
461