siop.c revision 1.19 1 1.19 chopps /* $NetBSD: siop.c,v 1.19 1995/01/05 07:22:48 chopps Exp $ */
2 1.17 cgd
3 1.1 mw /*
4 1.8 chopps * Copyright (c) 1994 Michael L. Hitch
5 1.1 mw * Copyright (c) 1990 The Regents of the University of California.
6 1.1 mw * All rights reserved.
7 1.1 mw *
8 1.1 mw * This code is derived from software contributed to Berkeley by
9 1.1 mw * Van Jacobson of Lawrence Berkeley Laboratory.
10 1.1 mw *
11 1.1 mw * Redistribution and use in source and binary forms, with or without
12 1.1 mw * modification, are permitted provided that the following conditions
13 1.1 mw * are met:
14 1.1 mw * 1. Redistributions of source code must retain the above copyright
15 1.1 mw * notice, this list of conditions and the following disclaimer.
16 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 mw * notice, this list of conditions and the following disclaimer in the
18 1.1 mw * documentation and/or other materials provided with the distribution.
19 1.1 mw * 3. All advertising materials mentioning features or use of this software
20 1.1 mw * must display the following acknowledgement:
21 1.1 mw * This product includes software developed by the University of
22 1.1 mw * California, Berkeley and its contributors.
23 1.1 mw * 4. Neither the name of the University nor the names of its contributors
24 1.1 mw * may be used to endorse or promote products derived from this software
25 1.1 mw * without specific prior written permission.
26 1.1 mw *
27 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 mw * SUCH DAMAGE.
38 1.1 mw *
39 1.1 mw * @(#)siop.c 7.5 (Berkeley) 5/4/91
40 1.1 mw */
41 1.1 mw
42 1.1 mw /*
43 1.1 mw * AMIGA 53C710 scsi adaptor driver
44 1.1 mw */
45 1.2 chopps
46 1.2 chopps /* need to know if any tapes have been configured */
47 1.2 chopps #include "st.h"
48 1.2 chopps
49 1.4 chopps #include <sys/param.h>
50 1.4 chopps #include <sys/systm.h>
51 1.8 chopps #include <sys/device.h>
52 1.4 chopps #include <sys/buf.h>
53 1.8 chopps #include <scsi/scsi_all.h>
54 1.8 chopps #include <scsi/scsiconf.h>
55 1.8 chopps #include <machine/cpu.h>
56 1.8 chopps #include <amiga/amiga/custom.h>
57 1.8 chopps #include <amiga/dev/siopreg.h>
58 1.4 chopps #include <amiga/dev/siopvar.h>
59 1.1 mw
60 1.1 mw extern u_int kvtop();
61 1.1 mw
62 1.1 mw /*
63 1.1 mw * SCSI delays
64 1.1 mw * In u-seconds, primarily for state changes on the SPC.
65 1.1 mw */
66 1.11 chopps #define SCSI_CMD_WAIT 500000 /* wait per step of 'immediate' cmds */
67 1.11 chopps #define SCSI_DATA_WAIT 500000 /* wait per data in/out step */
68 1.11 chopps #define SCSI_INIT_WAIT 500000 /* wait per step (both) during init */
69 1.1 mw
70 1.18 chopps int siopicmd __P((struct siop_softc *, int, int, void *, int, void *, int));
71 1.8 chopps int siopgo __P((struct siop_softc *, struct scsi_xfer *));
72 1.8 chopps int siopgetsense __P((struct siop_softc *, struct scsi_xfer *));
73 1.8 chopps void siopabort __P((struct siop_softc *, siop_regmap_p, char *));
74 1.8 chopps void sioperror __P((struct siop_softc *, siop_regmap_p, u_char));
75 1.8 chopps void siopstart __P((struct siop_softc *));
76 1.8 chopps void siopreset __P((struct siop_softc *));
77 1.8 chopps void siopsetdelay __P((int));
78 1.8 chopps void siop_scsidone __P((struct siop_softc *, int));
79 1.8 chopps void siop_donextcmd __P((struct siop_softc *));
80 1.8 chopps int siopintr __P((struct siop_softc *));
81 1.1 mw
82 1.1 mw /* 53C710 script */
83 1.18 chopps #include <amiga/dev/siop_script.out>
84 1.1 mw
85 1.8 chopps /* default to not inhibit sync negotiation on any drive */
86 1.14 chopps u_char siop_inhibit_sync[8] = { 0, 0, 0, 0, 0, 0, 0 }; /* initialize, so patchable */
87 1.18 chopps u_char siop_allow_disc[8] = {0, 0, 0, 0, 0, 0, 0, 0};
88 1.8 chopps int siop_no_dma = 0;
89 1.8 chopps
90 1.18 chopps int siop_reset_delay = 250; /* delay after reset, in milleseconds */
91 1.8 chopps int siop_sync_period = 50; /* synchronous transfer period, in nanoseconds */
92 1.1 mw
93 1.1 mw int siop_cmd_wait = SCSI_CMD_WAIT;
94 1.1 mw int siop_data_wait = SCSI_DATA_WAIT;
95 1.1 mw int siop_init_wait = SCSI_INIT_WAIT;
96 1.1 mw
97 1.18 chopps /*
98 1.18 chopps * sync period transfer lookup - only valid for 66Mhz clock
99 1.18 chopps */
100 1.1 mw static struct {
101 1.1 mw unsigned char x; /* period from sync request message */
102 1.1 mw unsigned char y; /* siop_period << 4 | sbcl */
103 1.1 mw } xxx[] = {
104 1.18 chopps { 60/4, 0<<4 | 1},
105 1.18 chopps { 76/4, 1<<4 | 1},
106 1.18 chopps { 92/4, 2<<4 | 1},
107 1.18 chopps { 92/4, 0<<4 | 2},
108 1.18 chopps {108/4, 3<<4 | 1},
109 1.18 chopps {116/4, 1<<4 | 2},
110 1.18 chopps {120/4, 4<<4 | 1},
111 1.18 chopps {120/4, 0<<4 | 3},
112 1.18 chopps {136/4, 5<<4 | 1},
113 1.18 chopps {140/4, 2<<4 | 2},
114 1.18 chopps {152/4, 6<<4 | 1},
115 1.18 chopps {152/4, 1<<4 | 3},
116 1.18 chopps {164/4, 3<<4 | 2},
117 1.18 chopps {168/4, 7<<4 | 1},
118 1.18 chopps {180/4, 2<<4 | 3},
119 1.18 chopps {184/4, 4<<4 | 2},
120 1.18 chopps {208/4, 5<<4 | 2},
121 1.18 chopps {212/4, 3<<4 | 3},
122 1.18 chopps {232/4, 6<<4 | 2},
123 1.18 chopps {240/4, 4<<4 | 3},
124 1.18 chopps {256/4, 7<<4 | 2},
125 1.18 chopps {272/4, 5<<4 | 3},
126 1.18 chopps {300/4, 6<<4 | 3},
127 1.18 chopps {332/4, 7<<4 | 3}
128 1.1 mw };
129 1.1 mw
130 1.1 mw #ifdef DEBUG
131 1.8 chopps #define QPRINTF(a) if (siop_debug > 1) printf a
132 1.8 chopps /*
133 1.8 chopps * 0x01 - full debug
134 1.8 chopps * 0x02 - DMA chaining
135 1.8 chopps * 0x04 - siopintr
136 1.8 chopps * 0x08 - phase mismatch
137 1.8 chopps * 0x10 - panic on phase mismatch
138 1.15 chopps * 0x20 - panic on unhandled exceptions
139 1.18 chopps * 0x100 - disconnect/reconnect
140 1.8 chopps */
141 1.8 chopps int siop_debug = 0;
142 1.8 chopps int siopsync_debug = 0;
143 1.8 chopps int siopdma_hits = 0;
144 1.8 chopps int siopdma_misses = 0;
145 1.14 chopps int siopchain_ints = 0;
146 1.18 chopps int siopstarts = 0;
147 1.18 chopps int siopints = 0;
148 1.18 chopps int siopphmm = 0;
149 1.16 chopps #else
150 1.16 chopps #define QPRINTF(a)
151 1.1 mw #endif
152 1.8 chopps
153 1.8 chopps
154 1.8 chopps /*
155 1.8 chopps * default minphys routine for siop based controllers
156 1.8 chopps */
157 1.8 chopps void
158 1.8 chopps siop_minphys(bp)
159 1.8 chopps struct buf *bp;
160 1.8 chopps {
161 1.8 chopps /*
162 1.8 chopps * no max transfer at this level
163 1.8 chopps */
164 1.1 mw }
165 1.1 mw
166 1.8 chopps /*
167 1.8 chopps * used by specific siop controller
168 1.1 mw *
169 1.8 chopps */
170 1.8 chopps int
171 1.8 chopps siop_scsicmd(xs)
172 1.8 chopps struct scsi_xfer *xs;
173 1.8 chopps {
174 1.8 chopps struct siop_pending *pendp;
175 1.8 chopps struct siop_softc *dev;
176 1.8 chopps struct scsi_link *slp;
177 1.18 chopps int flags, s, i;
178 1.8 chopps
179 1.8 chopps slp = xs->sc_link;
180 1.8 chopps dev = slp->adapter_softc;
181 1.8 chopps flags = xs->flags;
182 1.8 chopps
183 1.8 chopps if (flags & SCSI_DATA_UIO)
184 1.8 chopps panic("siop: scsi data uio requested");
185 1.8 chopps
186 1.19 chopps if (dev->sc_xs && flags & SCSI_POLL)
187 1.8 chopps panic("siop_scsicmd: busy");
188 1.8 chopps
189 1.8 chopps s = splbio();
190 1.8 chopps pendp = &dev->sc_xsstore[slp->target][slp->lun];
191 1.8 chopps if (pendp->xs) {
192 1.8 chopps splx(s);
193 1.8 chopps return(TRY_AGAIN_LATER);
194 1.8 chopps }
195 1.8 chopps
196 1.8 chopps if (dev->sc_xs) {
197 1.8 chopps pendp->xs = xs;
198 1.8 chopps TAILQ_INSERT_TAIL(&dev->sc_xslist, pendp, link);
199 1.8 chopps splx(s);
200 1.8 chopps return(SUCCESSFULLY_QUEUED);
201 1.8 chopps }
202 1.8 chopps pendp->xs = NULL;
203 1.8 chopps dev->sc_xs = xs;
204 1.8 chopps splx(s);
205 1.8 chopps
206 1.8 chopps /*
207 1.8 chopps * nothing is pending do it now.
208 1.8 chopps */
209 1.8 chopps siop_donextcmd(dev);
210 1.8 chopps
211 1.19 chopps if (flags & SCSI_POLL)
212 1.8 chopps return(COMPLETE);
213 1.8 chopps return(SUCCESSFULLY_QUEUED);
214 1.8 chopps }
215 1.8 chopps
216 1.8 chopps /*
217 1.8 chopps * entered with dev->sc_xs pointing to the next xfer to perform
218 1.1 mw */
219 1.1 mw void
220 1.8 chopps siop_donextcmd(dev)
221 1.8 chopps struct siop_softc *dev;
222 1.8 chopps {
223 1.8 chopps struct scsi_xfer *xs;
224 1.8 chopps struct scsi_link *slp;
225 1.18 chopps int flags, stat, i;
226 1.8 chopps
227 1.8 chopps xs = dev->sc_xs;
228 1.8 chopps slp = xs->sc_link;
229 1.8 chopps flags = xs->flags;
230 1.8 chopps
231 1.8 chopps if (flags & SCSI_RESET)
232 1.8 chopps siopreset(dev);
233 1.8 chopps
234 1.18 chopps xs->cmd->bytes[0] |= slp->lun << 5;
235 1.18 chopps for (i = 0; i < 2; ++i) {
236 1.18 chopps if (dev->sc_iob[i].sc_xs == NULL) {
237 1.18 chopps dev->sc_iob[i].sc_xs = xs;
238 1.18 chopps dev->sc_cur = & dev->sc_iob[i];
239 1.18 chopps dev->sc_iob[i].sc_stat[0] = -1;
240 1.18 chopps break;
241 1.18 chopps }
242 1.18 chopps }
243 1.18 chopps if (dev->sc_cur == NULL)
244 1.18 chopps panic ("siop: too many I/O's");
245 1.18 chopps ++dev->sc_active;
246 1.8 chopps #if 0
247 1.18 chopps if (dev->sc_active > 1) {
248 1.18 chopps printf ("active count %d\n", dev->sc_active);
249 1.18 chopps }
250 1.18 chopps #endif
251 1.19 chopps if (flags & SCSI_POLL || siop_no_dma)
252 1.18 chopps stat = siopicmd(dev, slp->target, slp->lun, xs->cmd,
253 1.18 chopps xs->cmdlen, xs->data, xs->datalen);
254 1.8 chopps else if (siopgo(dev, xs) == 0)
255 1.8 chopps return;
256 1.8 chopps else
257 1.18 chopps stat = dev->sc_cur->sc_stat[0];
258 1.8 chopps
259 1.8 chopps siop_scsidone(dev, stat);
260 1.8 chopps }
261 1.8 chopps
262 1.8 chopps void
263 1.8 chopps siop_scsidone(dev, stat)
264 1.8 chopps struct siop_softc *dev;
265 1.8 chopps int stat;
266 1.1 mw {
267 1.8 chopps struct siop_pending *pendp;
268 1.8 chopps struct scsi_xfer *xs;
269 1.8 chopps int s, donext;
270 1.8 chopps
271 1.8 chopps xs = dev->sc_xs;
272 1.8 chopps #ifdef DIAGNOSTIC
273 1.8 chopps if (xs == NULL)
274 1.8 chopps panic("siop_scsidone");
275 1.8 chopps #endif
276 1.8 chopps /*
277 1.8 chopps * is this right?
278 1.8 chopps */
279 1.8 chopps xs->status = stat;
280 1.8 chopps
281 1.19 chopps if (stat == 0)
282 1.8 chopps xs->resid = 0;
283 1.8 chopps else {
284 1.8 chopps switch(stat) {
285 1.8 chopps case SCSI_CHECK:
286 1.8 chopps if (stat = siopgetsense(dev, xs))
287 1.8 chopps goto bad_sense;
288 1.8 chopps xs->error = XS_SENSE;
289 1.8 chopps break;
290 1.8 chopps case SCSI_BUSY:
291 1.8 chopps xs->error = XS_BUSY;
292 1.8 chopps break;
293 1.8 chopps bad_sense:
294 1.8 chopps default:
295 1.8 chopps xs->error = XS_DRIVER_STUFFUP;
296 1.8 chopps QPRINTF(("siop_scsicmd() bad %x\n", stat));
297 1.8 chopps break;
298 1.8 chopps }
299 1.8 chopps }
300 1.8 chopps xs->flags |= ITSDONE;
301 1.1 mw
302 1.18 chopps --dev->sc_active;
303 1.18 chopps dev->sc_cur->sc_xs = NULL;
304 1.18 chopps dev->sc_cur = NULL;
305 1.18 chopps /*
306 1.18 chopps * if another command is already pending (i.e. it was pre-empted
307 1.18 chopps * by a reconnecting device), make it the current command and
308 1.18 chopps * continue
309 1.18 chopps */
310 1.18 chopps
311 1.8 chopps /*
312 1.8 chopps * grab next command before scsi_done()
313 1.8 chopps * this way no single device can hog scsi resources.
314 1.8 chopps */
315 1.8 chopps s = splbio();
316 1.8 chopps pendp = dev->sc_xslist.tqh_first;
317 1.8 chopps if (pendp == NULL) {
318 1.8 chopps donext = 0;
319 1.8 chopps dev->sc_xs = NULL;
320 1.1 mw } else {
321 1.8 chopps donext = 1;
322 1.8 chopps TAILQ_REMOVE(&dev->sc_xslist, pendp, link);
323 1.8 chopps dev->sc_xs = pendp->xs;
324 1.8 chopps pendp->xs = NULL;
325 1.1 mw }
326 1.8 chopps splx(s);
327 1.8 chopps scsi_done(xs);
328 1.8 chopps
329 1.8 chopps if (donext)
330 1.8 chopps siop_donextcmd(dev);
331 1.18 chopps else if (dev->sc_active && dev->sc_xs == NULL) {
332 1.18 chopps /* printf ("siop_scsidone: still active %d\n", dev->sc_active);*/
333 1.18 chopps /* dev->sc_siopp->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;*/
334 1.18 chopps }
335 1.1 mw }
336 1.1 mw
337 1.8 chopps int
338 1.8 chopps siopgetsense(dev, xs)
339 1.8 chopps struct siop_softc *dev;
340 1.8 chopps struct scsi_xfer *xs;
341 1.8 chopps {
342 1.8 chopps struct scsi_sense rqs;
343 1.8 chopps struct scsi_link *slp;
344 1.8 chopps int stat;
345 1.1 mw
346 1.8 chopps slp = xs->sc_link;
347 1.8 chopps
348 1.19 chopps rqs.opcode = REQUEST_SENSE;
349 1.8 chopps rqs.byte2 = slp->lun << 5;
350 1.9 chopps #ifdef not_yet
351 1.8 chopps rqs.length = xs->req_sense_length ? xs->req_sense_length :
352 1.8 chopps sizeof(xs->sense);
353 1.9 chopps #else
354 1.9 chopps rqs.length = sizeof(xs->sense);
355 1.9 chopps #endif
356 1.8 chopps if (rqs.length > sizeof (xs->sense))
357 1.8 chopps rqs.length = sizeof (xs->sense);
358 1.8 chopps rqs.unused[0] = rqs.unused[1] = rqs.control = 0;
359 1.8 chopps
360 1.18 chopps return(siopicmd(dev, slp->target, slp->lun, &rqs, sizeof(rqs),
361 1.18 chopps &xs->sense, rqs.length));
362 1.8 chopps }
363 1.1 mw
364 1.8 chopps void
365 1.1 mw siopabort(dev, regs, where)
366 1.1 mw register struct siop_softc *dev;
367 1.8 chopps siop_regmap_p regs;
368 1.1 mw char *where;
369 1.1 mw {
370 1.18 chopps int i;
371 1.1 mw
372 1.8 chopps printf ("%s: abort %s: dstat %02x, sstat0 %02x sbcl %02x\n",
373 1.8 chopps dev->sc_dev.dv_xname,
374 1.1 mw where, regs->siop_dstat, regs->siop_sstat0, regs->siop_sbcl);
375 1.1 mw
376 1.18 chopps if (dev->sc_active > 0) {
377 1.1 mw #ifdef TODO
378 1.1 mw SET_SBIC_cmd (regs, SBIC_CMD_ABORT);
379 1.1 mw WAIT_CIP (regs);
380 1.1 mw
381 1.1 mw GET_SBIC_asr (regs, asr);
382 1.1 mw if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
383 1.1 mw {
384 1.1 mw /* ok, get more drastic.. */
385 1.1 mw
386 1.1 mw SET_SBIC_cmd (regs, SBIC_CMD_RESET);
387 1.11 chopps delay(25);
388 1.1 mw SBIC_WAIT(regs, SBIC_ASR_INT, 0);
389 1.1 mw GET_SBIC_csr (regs, csr); /* clears interrupt also */
390 1.1 mw
391 1.1 mw dev->sc_flags &= ~SIOP_SELECTED;
392 1.1 mw return;
393 1.1 mw }
394 1.1 mw
395 1.1 mw do
396 1.1 mw {
397 1.1 mw SBIC_WAIT (regs, SBIC_ASR_INT, 0);
398 1.1 mw GET_SBIC_csr (regs, csr);
399 1.1 mw }
400 1.1 mw while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
401 1.1 mw && (csr != SBIC_CSR_CMD_INVALID));
402 1.1 mw #endif
403 1.1 mw
404 1.1 mw /* lets just hope it worked.. */
405 1.1 mw dev->sc_flags &= ~SIOP_SELECTED;
406 1.18 chopps for (i = 0; i < 2; ++i) {
407 1.18 chopps if (dev->sc_iob[i].sc_xs && &dev->sc_iob[i] !=
408 1.18 chopps dev->sc_cur) {
409 1.18 chopps printf ("siopabort: cleanup!\n");
410 1.18 chopps dev->sc_iob[i].sc_xs = NULL;
411 1.18 chopps }
412 1.18 chopps }
413 1.18 chopps dev->sc_active = 0;
414 1.8 chopps }
415 1.1 mw }
416 1.1 mw
417 1.1 mw void
418 1.12 chopps siopinitialize(dev)
419 1.12 chopps struct siop_softc *dev;
420 1.12 chopps {
421 1.12 chopps /*
422 1.14 chopps * Need to check that scripts is on a long word boundary
423 1.14 chopps * and that DS is on a long word boundary.
424 1.18 chopps * Also need to verify that dev doesn't span non-contiguous
425 1.14 chopps * physical pages.
426 1.12 chopps */
427 1.12 chopps dev->sc_scriptspa = kvtop(scripts);
428 1.18 chopps #if 0
429 1.12 chopps dev->sc_dspa = kvtop(&dev->sc_ds);
430 1.18 chopps dev->sc_lunpa = kvtop(&dev->sc_msgout);
431 1.12 chopps dev->sc_statuspa = kvtop(&dev->sc_stat[0]);
432 1.12 chopps dev->sc_msgpa = kvtop(&dev->sc_msg[0]);
433 1.18 chopps #endif
434 1.12 chopps siopreset (dev);
435 1.12 chopps }
436 1.12 chopps
437 1.12 chopps void
438 1.8 chopps siopreset(dev)
439 1.8 chopps struct siop_softc *dev;
440 1.1 mw {
441 1.8 chopps siop_regmap_p regs;
442 1.1 mw u_int i, s;
443 1.18 chopps u_char my_id, dummy;
444 1.1 mw
445 1.8 chopps regs = dev->sc_siopp;
446 1.8 chopps
447 1.1 mw if (dev->sc_flags & SIOP_ALIVE)
448 1.1 mw siopabort(dev, regs, "reset");
449 1.1 mw
450 1.14 chopps printf("%s: ", dev->sc_dev.dv_xname); /* XXXX */
451 1.1 mw
452 1.1 mw s = splbio();
453 1.1 mw my_id = 7;
454 1.1 mw
455 1.1 mw /*
456 1.1 mw * Reset the chip
457 1.1 mw * XXX - is this really needed?
458 1.1 mw */
459 1.18 chopps regs->siop_istat |= SIOP_ISTAT_ABRT; /* abort current script */
460 1.18 chopps regs->siop_istat |= SIOP_ISTAT_RST; /* reset chip */
461 1.18 chopps regs->siop_istat &= ~SIOP_ISTAT_RST;
462 1.18 chopps /*
463 1.18 chopps * Reset SCSI bus (do we really want this?)
464 1.18 chopps */
465 1.1 mw regs->siop_sien &= ~SIOP_SIEN_RST;
466 1.1 mw regs->siop_scntl1 |= SIOP_SCNTL1_RST;
467 1.18 chopps delay(1);
468 1.1 mw regs->siop_scntl1 &= ~SIOP_SCNTL1_RST;
469 1.18 chopps /* regs->siop_sien |= SIOP_SIEN_RST;*/
470 1.1 mw
471 1.1 mw /*
472 1.1 mw * Set up various chip parameters
473 1.1 mw */
474 1.1 mw regs->siop_scntl0 = SIOP_ARB_FULL | SIOP_SCNTL0_EPC | SIOP_SCNTL0_EPG;
475 1.8 chopps regs->siop_dcntl = dev->sc_clock_freq & 0xff;
476 1.8 chopps regs->siop_dmode = 0x80; /* burst length = 4 */
477 1.1 mw regs->siop_sien = 0x00; /* don't enable interrupts yet */
478 1.1 mw regs->siop_dien = 0x00; /* don't enable interrupts yet */
479 1.1 mw regs->siop_scid = 1 << my_id;
480 1.1 mw regs->siop_dwt = 0x00;
481 1.18 chopps regs->siop_ctest0 |= SIOP_CTEST0_BTD | SIOP_CTEST0_EAN;
482 1.8 chopps regs->siop_ctest7 |= (dev->sc_clock_freq >> 8) & 0xff;
483 1.1 mw
484 1.1 mw /* will need to re-negotiate sync xfers */
485 1.1 mw bzero(&dev->sc_sync, sizeof (dev->sc_sync));
486 1.1 mw
487 1.18 chopps i = regs->siop_istat;
488 1.18 chopps if (i & SIOP_ISTAT_SIP)
489 1.18 chopps dummy = regs->siop_sstat0;
490 1.18 chopps if (i & SIOP_ISTAT_DIP)
491 1.18 chopps dummy = regs->siop_dstat;
492 1.18 chopps
493 1.1 mw splx (s);
494 1.1 mw
495 1.11 chopps delay (siop_reset_delay * 1000);
496 1.18 chopps printf("siop id %d reset V%d\n", my_id, regs->siop_ctest8 >> 4);
497 1.1 mw dev->sc_flags |= SIOP_ALIVE;
498 1.1 mw dev->sc_flags &= ~(SIOP_SELECTED | SIOP_DMA);
499 1.1 mw }
500 1.1 mw
501 1.1 mw /*
502 1.1 mw * Setup Data Storage for 53C710 and start SCRIPTS processing
503 1.1 mw */
504 1.1 mw
505 1.8 chopps void
506 1.18 chopps siop_setup (dev, target, lun, cbuf, clen, buf, len)
507 1.1 mw struct siop_softc *dev;
508 1.1 mw int target;
509 1.18 chopps int lun;
510 1.1 mw u_char *cbuf;
511 1.1 mw int clen;
512 1.1 mw u_char *buf;
513 1.1 mw int len;
514 1.1 mw {
515 1.8 chopps siop_regmap_p regs = dev->sc_siopp;
516 1.1 mw int i;
517 1.1 mw int nchain;
518 1.1 mw int count, tcount;
519 1.1 mw char *addr, *dmaend;
520 1.18 chopps struct siop_iob *iob = dev->sc_cur;
521 1.1 mw
522 1.18 chopps #ifdef DEBUG
523 1.18 chopps if (regs->siop_sbcl & SIOP_BSY) {
524 1.18 chopps printf ("ACK! siop was busy: regs %x script %x dsa %x\n",
525 1.18 chopps regs, &scripts, &iob->sc_ds);
526 1.18 chopps /*Debugger();*/
527 1.18 chopps }
528 1.18 chopps i = regs->siop_istat;
529 1.18 chopps if (i & SIOP_ISTAT_DIP) {
530 1.18 chopps int dstat;
531 1.18 chopps dstat = regs->siop_dstat;
532 1.18 chopps }
533 1.18 chopps if (i & SIOP_ISTAT_SIP) {
534 1.18 chopps int sstat;
535 1.18 chopps sstat = regs->siop_sstat0;
536 1.18 chopps }
537 1.18 chopps #endif
538 1.1 mw dev->sc_istat = 0;
539 1.18 chopps iob->sc_msgout[0] = MSG_IDENTIFY | lun;
540 1.18 chopps /*
541 1.18 chopps * HACK - if no data transfer, allow disconnects
542 1.18 chopps */
543 1.18 chopps if (/*len == 0 || */ siop_allow_disc[target]) {
544 1.18 chopps iob->sc_msgout[0] = MSG_IDENTIFY_DR | lun;
545 1.18 chopps regs->siop_scntl1 |= SIOP_SCNTL1_ESR;
546 1.18 chopps }
547 1.18 chopps iob->sc_status = 0;
548 1.18 chopps iob->sc_stat[0] = -1;
549 1.18 chopps iob->sc_msg[0] = -1;
550 1.18 chopps iob->sc_ds.scsi_addr = (0x10000 << target) | (dev->sc_sync[target].period << 8);
551 1.18 chopps iob->sc_ds.idlen = 1;
552 1.18 chopps iob->sc_ds.idbuf = (char *) kvtop(&iob->sc_msgout[0]);
553 1.18 chopps iob->sc_ds.cmdlen = clen;
554 1.18 chopps iob->sc_ds.cmdbuf = (char *) kvtop(cbuf);
555 1.18 chopps iob->sc_ds.stslen = 1;
556 1.18 chopps iob->sc_ds.stsbuf = (char *) kvtop(&iob->sc_stat[0]);
557 1.18 chopps iob->sc_ds.msglen = 1;
558 1.18 chopps iob->sc_ds.msgbuf = (char *) kvtop(&iob->sc_msg[0]);
559 1.18 chopps iob->sc_msg[1] = -1;
560 1.18 chopps iob->sc_ds.msginlen = 1;
561 1.18 chopps iob->sc_ds.extmsglen = 1;
562 1.18 chopps iob->sc_ds.synmsglen = 3;
563 1.18 chopps iob->sc_ds.msginbuf = (char *) kvtop(&iob->sc_msg[1]);
564 1.18 chopps iob->sc_ds.extmsgbuf = (char *) kvtop(&iob->sc_msg[2]);
565 1.18 chopps iob->sc_ds.synmsgbuf = (char *) kvtop(&iob->sc_msg[3]);
566 1.18 chopps bzero(&iob->sc_ds.chain, sizeof (iob->sc_ds.chain));
567 1.1 mw
568 1.1 mw if (dev->sc_sync[target].state == SYNC_START) {
569 1.8 chopps if (siop_inhibit_sync[target]) {
570 1.1 mw dev->sc_sync[target].state = SYNC_DONE;
571 1.1 mw dev->sc_sync[target].offset = 0;
572 1.1 mw dev->sc_sync[target].period = 0;
573 1.1 mw #ifdef DEBUG
574 1.1 mw if (siopsync_debug)
575 1.1 mw printf ("Forcing target %d asynchronous\n", target);
576 1.1 mw #endif
577 1.1 mw }
578 1.1 mw else {
579 1.18 chopps iob->sc_msg[2] = -1;
580 1.18 chopps iob->sc_msgout[1] = MSG_EXT_MESSAGE;
581 1.18 chopps iob->sc_msgout[2] = 3;
582 1.18 chopps iob->sc_msgout[3] = MSG_SYNC_REQ;
583 1.18 chopps iob->sc_msgout[4] = siop_sync_period / 4;
584 1.18 chopps iob->sc_msgout[5] = SIOP_MAX_OFFSET;
585 1.18 chopps iob->sc_ds.idlen = 6;
586 1.1 mw dev->sc_sync[target].state = SYNC_SENT;
587 1.1 mw #ifdef DEBUG
588 1.1 mw if (siopsync_debug)
589 1.1 mw printf ("Sending sync request to target %d\n", target);
590 1.1 mw #endif
591 1.1 mw }
592 1.1 mw }
593 1.1 mw
594 1.1 mw /*
595 1.1 mw * If length is > 1 page, check for consecutive physical pages
596 1.1 mw * Need to set up chaining if not
597 1.1 mw */
598 1.18 chopps iob->iob_buf = buf;
599 1.18 chopps iob->iob_len = len;
600 1.18 chopps iob->iob_curbuf = iob->iob_curlen = 0;
601 1.1 mw nchain = 0;
602 1.1 mw count = len;
603 1.1 mw addr = buf;
604 1.1 mw dmaend = NULL;
605 1.1 mw while (count > 0) {
606 1.18 chopps iob->sc_ds.chain[nchain].databuf = (char *) kvtop (addr);
607 1.1 mw if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
608 1.1 mw tcount = count;
609 1.18 chopps iob->sc_ds.chain[nchain].datalen = tcount;
610 1.1 mw addr += tcount;
611 1.1 mw count -= tcount;
612 1.18 chopps if (iob->sc_ds.chain[nchain].databuf == dmaend) {
613 1.18 chopps dmaend += iob->sc_ds.chain[nchain].datalen;
614 1.18 chopps iob->sc_ds.chain[--nchain].datalen += tcount;
615 1.1 mw #ifdef DEBUG
616 1.1 mw ++siopdma_hits;
617 1.1 mw #endif
618 1.1 mw }
619 1.1 mw else {
620 1.18 chopps dmaend = iob->sc_ds.chain[nchain].databuf +
621 1.18 chopps iob->sc_ds.chain[nchain].datalen;
622 1.18 chopps iob->sc_ds.chain[nchain].datalen = tcount;
623 1.1 mw #ifdef DEBUG
624 1.14 chopps if (nchain) /* Don't count miss on first one */
625 1.14 chopps ++siopdma_misses;
626 1.1 mw #endif
627 1.1 mw }
628 1.1 mw ++nchain;
629 1.1 mw }
630 1.1 mw #ifdef DEBUG
631 1.1 mw if (nchain != 1 && len != 0 && siop_debug & 3) {
632 1.1 mw printf ("DMA chaining set: %d\n", nchain);
633 1.1 mw for (i = 0; i < nchain; ++i) {
634 1.18 chopps printf (" [%d] %8x %4x\n", i, iob->sc_ds.chain[i].databuf,
635 1.18 chopps iob->sc_ds.chain[i].datalen);
636 1.1 mw }
637 1.1 mw }
638 1.18 chopps if (regs->siop_sbcl & SIOP_BSY) {
639 1.18 chopps printf ("ACK! siop was busy at start: regs %x script %x dsa %x\n",
640 1.18 chopps regs, &scripts, &iob->sc_ds);
641 1.18 chopps /*Debugger();*/
642 1.18 chopps }
643 1.1 mw #endif
644 1.1 mw
645 1.18 chopps /* push data case on data the 53c710 needs to access */
646 1.12 chopps dma_cachectl (dev, sizeof (struct siop_softc));
647 1.12 chopps dma_cachectl (cbuf, clen);
648 1.12 chopps if (buf != NULL && len != 0)
649 1.12 chopps dma_cachectl (buf, len);
650 1.18 chopps if (dev->sc_active <= 1) {
651 1.18 chopps regs->siop_sbcl = dev->sc_sync[target].offset;
652 1.18 chopps regs->siop_dsa = kvtop(&iob->sc_ds);
653 1.18 chopps /* XXX if disconnected devices pending, this may not work */
654 1.18 chopps regs->siop_dsp = dev->sc_scriptspa;
655 1.18 chopps } else {
656 1.18 chopps regs->siop_istat = SIOP_ISTAT_SIGP;
657 1.18 chopps }
658 1.18 chopps #ifdef DEBUG
659 1.18 chopps ++siopstarts;
660 1.18 chopps #endif
661 1.1 mw }
662 1.1 mw
663 1.1 mw /*
664 1.1 mw * Process a DMA or SCSI interrupt from the 53C710 SIOP
665 1.1 mw */
666 1.1 mw
667 1.8 chopps int
668 1.1 mw siop_checkintr(dev, istat, dstat, sstat0, status)
669 1.1 mw struct siop_softc *dev;
670 1.1 mw u_char istat;
671 1.1 mw u_char dstat;
672 1.1 mw u_char sstat0;
673 1.1 mw int *status;
674 1.1 mw {
675 1.8 chopps siop_regmap_p regs = dev->sc_siopp;
676 1.18 chopps struct siop_iob *iob = dev->sc_cur;
677 1.1 mw int target;
678 1.18 chopps int dfifo, dbc, sstat1;
679 1.1 mw
680 1.18 chopps dfifo = regs->siop_dfifo;
681 1.18 chopps dbc = regs->siop_dbc0;
682 1.18 chopps sstat1 = regs->siop_sstat1;
683 1.18 chopps regs->siop_ctest8 |= SIOP_CTEST8_CLF;
684 1.1 mw while ((regs->siop_ctest1 & SIOP_CTEST1_FMT) == 0)
685 1.1 mw ;
686 1.18 chopps regs->siop_ctest8 &= ~SIOP_CTEST8_CLF;
687 1.1 mw #ifdef DEBUG
688 1.18 chopps ++siopints;
689 1.18 chopps if (siop_debug & 0x100) {
690 1.18 chopps DCIAS(&iob->sc_stat[0]); /* XXX */
691 1.1 mw printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
692 1.18 chopps istat, dstat, sstat0, regs->siop_dsps, regs->siop_sbcl, iob->sc_stat[0], iob->sc_msg[0]);
693 1.18 chopps printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
694 1.18 chopps iob->sc_msg[0], iob->sc_msg[1], iob->sc_msg[2],
695 1.18 chopps iob->sc_msg[3], iob->sc_msg[4], iob->sc_msg[5]);
696 1.1 mw }
697 1.1 mw #endif
698 1.18 chopps if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff00) {
699 1.1 mw /* Normal completion status, or check condition */
700 1.18 chopps if (regs->siop_dsa != kvtop(&iob->sc_ds)) {
701 1.1 mw printf ("siop: invalid dsa: %x %x\n", regs->siop_dsa,
702 1.18 chopps kvtop(&iob->sc_ds));
703 1.1 mw panic("*** siop DSA invalid ***");
704 1.1 mw }
705 1.1 mw target = dev->sc_slave;
706 1.1 mw if (dev->sc_sync[target].state == SYNC_SENT) {
707 1.1 mw #ifdef DEBUG
708 1.1 mw if (siopsync_debug)
709 1.1 mw printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
710 1.18 chopps iob->sc_msg[0], iob->sc_msg[1], iob->sc_msg[2],
711 1.18 chopps iob->sc_msg[3], iob->sc_msg[4], iob->sc_msg[5]);
712 1.1 mw #endif
713 1.18 chopps if (iob->sc_msg[1] == 0xff)
714 1.18 chopps printf ("%s: target %d ignored sync request\n",
715 1.18 chopps dev->sc_dev.dv_xname, target);
716 1.18 chopps else if (iob->sc_msg[1] == MSG_REJECT)
717 1.18 chopps printf ("%s: target %d rejected sync request\n",
718 1.18 chopps dev->sc_dev.dv_xname, target);
719 1.1 mw dev->sc_sync[target].state = SYNC_DONE;
720 1.1 mw dev->sc_sync[target].period = 0;
721 1.1 mw dev->sc_sync[target].offset = 0;
722 1.18 chopps if (iob->sc_msg[2] == 3 &&
723 1.18 chopps iob->sc_msg[3] == MSG_SYNC_REQ &&
724 1.18 chopps iob->sc_msg[5] != 0) {
725 1.18 chopps if (iob->sc_msg[4] && iob->sc_msg[4] < 100 / 4) {
726 1.8 chopps #ifdef DEBUG
727 1.8 chopps printf ("%d: target %d wanted %dns period\n",
728 1.8 chopps dev->sc_dev.dv_xname, target,
729 1.18 chopps iob->sc_msg[4] * 4);
730 1.8 chopps #endif
731 1.8 chopps /*
732 1.8 chopps * Kludge for Maxtor XT8580S
733 1.8 chopps * It accepts whatever we request, even
734 1.8 chopps * though it won't work. So we ask for
735 1.8 chopps * a short period than we can handle. If
736 1.8 chopps * the device says it can do it, use 208ns.
737 1.8 chopps * If the device says it can do less than
738 1.8 chopps * 100ns, then we limit it to 100ns.
739 1.8 chopps */
740 1.18 chopps if (iob->sc_msg[4] == siop_sync_period / 4)
741 1.18 chopps iob->sc_msg[4] = 208 / 4;
742 1.8 chopps else
743 1.18 chopps iob->sc_msg[4] = 100 / 4;
744 1.8 chopps }
745 1.8 chopps printf ("%s: target %d now synchronous, period=%dns, offset=%d\n",
746 1.8 chopps dev->sc_dev.dv_xname, target,
747 1.18 chopps iob->sc_msg[4] * 4, iob->sc_msg[5]);
748 1.1 mw scsi_period_to_siop (dev, target);
749 1.1 mw }
750 1.1 mw }
751 1.12 chopps #if 0
752 1.14 chopps DCIAS(dev->sc_statuspa); /* XXX */
753 1.12 chopps #else
754 1.18 chopps dma_cachectl(&iob->sc_stat[0], 1);
755 1.18 chopps #endif
756 1.18 chopps *status = iob->sc_stat[0];
757 1.18 chopps #ifdef DEBUG
758 1.18 chopps if (regs->siop_sbcl & SIOP_BSY) {
759 1.18 chopps /*printf ("ACK! siop was busy at end: regs %x script %x dsa %x\n",
760 1.18 chopps regs, &scripts, &iob->sc_ds);*/
761 1.18 chopps /*Debugger();*/
762 1.18 chopps }
763 1.11 chopps #endif
764 1.18 chopps if (dev->sc_active > 1)
765 1.18 chopps regs->siop_dcntl |= SIOP_DCNTL_STD;
766 1.1 mw return 1;
767 1.1 mw }
768 1.1 mw if (sstat0 & SIOP_SSTAT0_M_A) { /* Phase mismatch */
769 1.1 mw #ifdef DEBUG
770 1.18 chopps ++siopphmm;
771 1.18 chopps if (iob->iob_len) {
772 1.18 chopps int adjust;
773 1.18 chopps adjust = ((dfifo - (dbc & 0x7f)) & 0x7f);
774 1.18 chopps if (sstat1 & SIOP_SSTAT1_ORF)
775 1.18 chopps ++adjust;
776 1.18 chopps if (sstat1 & SIOP_SSTAT1_OLF)
777 1.18 chopps ++adjust;
778 1.18 chopps iob->iob_curlen = *((long *)®s->siop_dcmd) & 0xffffff;
779 1.18 chopps iob->iob_curlen += adjust;
780 1.18 chopps iob->iob_curbuf = *((long *)®s->siop_dnad);
781 1.18 chopps #ifdef DEBUG
782 1.18 chopps if (siop_debug & 0x100)
783 1.18 chopps printf ("Phase mismatch: dnad %x dbc %x dfifo %x dbc %x sstat1 %x adjust %x sbcl %x\n",
784 1.18 chopps iob->iob_curbuf, iob->iob_curlen, dfifo, dbc, sstat1, adjust, regs->siop_sbcl);
785 1.18 chopps #endif
786 1.18 chopps }
787 1.1 mw if (siop_debug & 9)
788 1.18 chopps printf ("Phase mismatch: %x dsp +%x dcmd %x\n",
789 1.18 chopps regs->siop_sbcl,
790 1.18 chopps regs->siop_dsp - dev->sc_scriptspa,
791 1.18 chopps *((long *)®s->siop_dcmd));
792 1.8 chopps if (siop_debug & 0x10)
793 1.8 chopps panic ("53c710 phase mismatch");
794 1.1 mw #endif
795 1.1 mw if ((regs->siop_sbcl & SIOP_REQ) == 0)
796 1.1 mw printf ("Phase mismatch: REQ not asserted! %02x\n",
797 1.1 mw regs->siop_sbcl);
798 1.1 mw switch (regs->siop_sbcl & 7) {
799 1.1 mw /*
800 1.1 mw * For data out and data in phase, check for DMA chaining
801 1.1 mw */
802 1.18 chopps case 0: /* data out */
803 1.18 chopps case 1: /* data in */
804 1.18 chopps case 2: /* status */
805 1.18 chopps case 3: /* command */
806 1.18 chopps case 6: /* message in */
807 1.18 chopps case 7: /* message out */
808 1.18 chopps regs->siop_dsp = dev->sc_scriptspa + Ent_switch;
809 1.1 mw break;
810 1.1 mw default:
811 1.1 mw goto bad_phase;
812 1.1 mw }
813 1.1 mw return 0;
814 1.1 mw }
815 1.1 mw if (sstat0 & SIOP_SSTAT0_STO) { /* Select timed out */
816 1.1 mw #ifdef DEBUG
817 1.18 chopps if (regs->siop_sbcl & SIOP_BSY) {
818 1.18 chopps printf ("ACK! siop was busy at timeout: regs %x script %x dsa %x\n",
819 1.18 chopps regs, &scripts, &iob->sc_ds);
820 1.18 chopps printf(" sbcl %x sdid %x istat %x dstat %x sstat0 %x\n",
821 1.18 chopps regs->siop_sbcl, regs->siop_sdid, istat, dstat, sstat0);
822 1.18 chopps if (!(regs->siop_sbcl & SIOP_BSY)) {
823 1.18 chopps printf ("Yikes, it's not busy now!\n");
824 1.18 chopps #if 0
825 1.18 chopps *status = -1;
826 1.18 chopps if (dev->sc_active > 1)
827 1.18 chopps regs->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;
828 1.18 chopps return 1;
829 1.1 mw #endif
830 1.18 chopps }
831 1.18 chopps /* regs->siop_dcntl |= SIOP_DCNTL_STD;*/
832 1.1 mw return (0);
833 1.18 chopps Debugger();
834 1.1 mw }
835 1.18 chopps #endif
836 1.18 chopps *status = -1;
837 1.18 chopps if (dev->sc_active > 1)
838 1.18 chopps regs->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;
839 1.18 chopps return 1;
840 1.1 mw }
841 1.18 chopps target = dev->sc_slave;
842 1.18 chopps if (sstat0 & SIOP_SSTAT0_UDC) {
843 1.8 chopps #ifdef DEBUG
844 1.8 chopps printf ("%s: target %d disconnected unexpectedly\n",
845 1.8 chopps dev->sc_dev.dv_xname, target);
846 1.8 chopps #endif
847 1.8 chopps #if 0
848 1.8 chopps siopabort (dev, regs, "siopchkintr");
849 1.8 chopps #endif
850 1.8 chopps *status = STS_BUSY;
851 1.18 chopps if (dev->sc_active > 1)
852 1.18 chopps regs->siop_dsp = dev->sc_scriptspa + Ent_wait_reselect;
853 1.8 chopps return 1;
854 1.8 chopps }
855 1.18 chopps if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff0a) {
856 1.18 chopps #ifdef DEBUG
857 1.18 chopps if (siop_debug & 0x100)
858 1.18 chopps printf ("%s: ID %x disconnected TEMP %x (+%d) buf %x len %x buf %x len %x dfifo %x dbc %x sstat1 %x\n",
859 1.18 chopps dev->sc_dev.dv_xname, 1 << target, regs->siop_temp,
860 1.18 chopps regs->siop_temp - dev->sc_scriptspa,
861 1.18 chopps iob->iob_curbuf, iob->iob_curlen,
862 1.18 chopps iob->sc_ds.chain[0].databuf, iob->sc_ds.chain[0].datalen, dfifo, dbc, sstat1);
863 1.18 chopps #endif
864 1.18 chopps /*
865 1.18 chopps * HACK!
866 1.18 chopps * set current entry in disconnect state
867 1.18 chopps * clear current
868 1.18 chopps * if another iob available and another request pending,
869 1.18 chopps * start another
870 1.18 chopps */
871 1.18 chopps iob->sc_status = dev->sc_flags & (SIOP_SELECTED|SIOP_DMA);
872 1.18 chopps dev->sc_flags &= ~(SIOP_SELECTED|SIOP_DMA);
873 1.18 chopps dev->sc_cur = NULL; /* no current device */
874 1.18 chopps dev->sc_xs = NULL;
875 1.18 chopps /* continue script to wait for reconnect */
876 1.18 chopps regs->siop_dcntl |= SIOP_DCNTL_STD;
877 1.18 chopps if (dev->sc_active < 2) {
878 1.18 chopps struct siop_pending *pendp;
879 1.18 chopps int s = splbio();
880 1.18 chopps /*
881 1.18 chopps * can start another I/O, see if there are
882 1.18 chopps * any pending and start them
883 1.18 chopps */
884 1.18 chopps if (pendp = dev->sc_xslist.tqh_first) {
885 1.18 chopps TAILQ_REMOVE(&dev->sc_xslist, pendp, link);
886 1.18 chopps dev->sc_xs = pendp->xs;
887 1.18 chopps pendp->xs = NULL;
888 1.18 chopps splx(s);
889 1.18 chopps #ifdef DEBUG
890 1.18 chopps if (siop_debug & 0x100)
891 1.18 chopps printf ("starting a pending command %x\n", dev->sc_xs);
892 1.8 chopps #endif
893 1.18 chopps siop_donextcmd(dev);
894 1.18 chopps }
895 1.18 chopps splx(s);
896 1.18 chopps }
897 1.18 chopps return (0);
898 1.18 chopps }
899 1.18 chopps if (dstat & SIOP_DSTAT_SIR && (regs->siop_dsps == 0xff09 ||
900 1.18 chopps regs->siop_dsps == 0xff06)) {
901 1.18 chopps int i;
902 1.18 chopps #ifdef DEBUG
903 1.18 chopps if (siop_debug & 0x100)
904 1.18 chopps printf ("%s: target reselected %x %x\n",
905 1.18 chopps dev->sc_dev.dv_xname, regs->siop_lcrc,
906 1.18 chopps regs->siop_dsps);
907 1.18 chopps #endif
908 1.18 chopps if (dev->sc_cur) {
909 1.18 chopps printf ("siop: oops - reconnect before current done\n");
910 1.18 chopps /* panic ("siop: what now?");*/
911 1.18 chopps }
912 1.18 chopps /*
913 1.18 chopps * locate iob of reconnecting device
914 1.18 chopps * set dev->sc_cur to iob
915 1.18 chopps */
916 1.18 chopps for (i = 0, iob = NULL; i < 2; ++i) {
917 1.18 chopps if (dev->sc_iob[i].sc_xs == NULL)
918 1.18 chopps continue;
919 1.18 chopps if (!dev->sc_iob[i].sc_status)
920 1.18 chopps continue;
921 1.18 chopps if (!(regs->siop_lcrc & (dev->sc_iob[i].sc_ds.scsi_addr >> 16)))
922 1.18 chopps continue;
923 1.18 chopps iob = &dev->sc_iob[i];
924 1.18 chopps dev->sc_cur = iob;
925 1.18 chopps dev->sc_xs = iob->sc_xs;
926 1.18 chopps dev->sc_flags |= iob->sc_status;
927 1.18 chopps iob->sc_status = 0;
928 1.18 chopps DCIAS(kvtop(&iob->sc_stat[0]));
929 1.18 chopps regs->siop_dsa = kvtop(&iob->sc_ds);
930 1.18 chopps if (iob->iob_curlen) {
931 1.18 chopps if (iob->iob_curbuf <= (u_long) iob->sc_ds.chain[0].databuf ||
932 1.18 chopps iob->iob_curbuf >= (u_long)(iob->sc_ds.chain[0].databuf + iob->sc_ds.chain[0].datalen))
933 1.18 chopps printf ("%s: saved data pointer not in chain[0]\n");
934 1.18 chopps iob->sc_ds.chain[0].databuf = (char *) iob->iob_curbuf;
935 1.18 chopps iob->sc_ds.chain[0].datalen = iob->iob_curlen;
936 1.18 chopps #ifdef DEBUG
937 1.18 chopps if (siop_debug & 0x100)
938 1.18 chopps printf ("%s: reselect buf %x len %x\n",
939 1.18 chopps dev->sc_dev.dv_xname, iob->iob_curbuf,
940 1.18 chopps iob->iob_curlen);
941 1.8 chopps #endif
942 1.18 chopps DCIAS(kvtop(&iob->sc_ds.chain));
943 1.18 chopps }
944 1.18 chopps }
945 1.18 chopps if (iob == NULL)
946 1.18 chopps panic("unable to find reconnecting device");
947 1.18 chopps regs->siop_dcntl |= SIOP_DCNTL_STD;
948 1.18 chopps return (0);
949 1.18 chopps }
950 1.18 chopps if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff07) {
951 1.18 chopps /* reselect was interrupted */
952 1.18 chopps #ifdef DEBUG
953 1.18 chopps if (siop_debug & 0x100 &&
954 1.18 chopps (regs->siop_sfbr & SIOP_CTEST2_SIGP) == 0)
955 1.18 chopps printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x\n",
956 1.18 chopps dev->sc_dev.dv_xname, regs->siop_scntl1, regs->siop_ctest2, regs->siop_sfbr);
957 1.18 chopps #endif
958 1.18 chopps target = dev->sc_xs->sc_link->target;
959 1.18 chopps regs->siop_dsa = kvtop(&dev->sc_cur->sc_ds);
960 1.18 chopps regs->siop_sbcl = dev->sc_sync[target].offset;
961 1.18 chopps regs->siop_dcntl |= SIOP_DCNTL_STD;
962 1.18 chopps return (0);
963 1.8 chopps }
964 1.1 mw if (sstat0 == 0 && dstat & SIOP_DSTAT_SIR) {
965 1.12 chopps #if 0
966 1.12 chopps DCIAS(dev->sc_statuspa);
967 1.12 chopps #else
968 1.18 chopps dma_cachectl (&iob->sc_stat[0], 1);
969 1.12 chopps #endif
970 1.1 mw printf ("SIOP interrupt: %x sts %x msg %x sbcl %x\n",
971 1.18 chopps regs->siop_dsps, iob->sc_stat[0], iob->sc_msg[0],
972 1.1 mw regs->siop_sbcl);
973 1.8 chopps siopreset (dev);
974 1.1 mw *status = -1;
975 1.1 mw return 1;
976 1.1 mw }
977 1.15 chopps if (sstat0 & SIOP_SSTAT0_SGE)
978 1.15 chopps printf ("SIOP: SCSI Gross Error\n");
979 1.15 chopps if (sstat0 & SIOP_SSTAT0_PAR)
980 1.15 chopps printf ("SIOP: Parity Error\n");
981 1.18 chopps if (dstat & SIOP_DSTAT_IID)
982 1.18 chopps printf ("SIOP: Invalid instruction detected\n");
983 1.1 mw bad_phase:
984 1.15 chopps /*
985 1.15 chopps * temporary panic for unhandled conditions
986 1.15 chopps * displays various things about the 53C710 status and registers
987 1.15 chopps * then panics.
988 1.15 chopps * XXXX need to clean this up to print out the info, reset, and continue
989 1.15 chopps */
990 1.18 chopps printf ("siopchkintr: target %x ds %x\n", target, &iob->sc_ds);
991 1.15 chopps printf ("scripts %x ds %x regs %x dsp %x dcmd %x\n", dev->sc_scriptspa,
992 1.18 chopps kvtop(&dev->sc_iob), kvtop(regs), regs->siop_dsp,
993 1.15 chopps *((long *)®s->siop_dcmd));
994 1.15 chopps printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x dsa %x sbcl %x sts %x msg %x\n",
995 1.15 chopps istat, dstat, sstat0, regs->siop_dsps, regs->siop_dsa,
996 1.18 chopps regs->siop_sbcl, iob->sc_stat[0], iob->sc_msg[0]);
997 1.15 chopps #ifdef DEBUG
998 1.15 chopps if (siop_debug & 0x20)
999 1.15 chopps panic("siopchkintr: **** temp ****");
1000 1.15 chopps #endif
1001 1.15 chopps siopreset (dev); /* hard reset */
1002 1.15 chopps *status = -1;
1003 1.15 chopps return 1;
1004 1.1 mw }
1005 1.1 mw
1006 1.1 mw /*
1007 1.1 mw * SCSI 'immediate' command: issue a command to some SCSI device
1008 1.1 mw * and get back an 'immediate' response (i.e., do programmed xfer
1009 1.1 mw * to get the response data). 'cbuf' is a buffer containing a scsi
1010 1.1 mw * command of length clen bytes. 'buf' is a buffer of length 'len'
1011 1.1 mw * bytes for data. The transfer direction is determined by the device
1012 1.1 mw * (i.e., by the scsi bus data xfer phase). If 'len' is zero, the
1013 1.1 mw * command must supply no data. 'xferphase' is the bus phase the
1014 1.1 mw * caller expects to happen after the command is issued. It should
1015 1.1 mw * be one of DATA_IN_PHASE, DATA_OUT_PHASE or STATUS_PHASE.
1016 1.1 mw *
1017 1.1 mw * XXX - 53C710 will use DMA, but no interrupts (it's a heck of a
1018 1.1 mw * lot easier to do than to use programmed I/O).
1019 1.1 mw *
1020 1.1 mw */
1021 1.8 chopps int
1022 1.18 chopps siopicmd(dev, target, lun, cbuf, clen, buf, len)
1023 1.1 mw struct siop_softc *dev;
1024 1.1 mw int target;
1025 1.18 chopps int lun;
1026 1.8 chopps void *cbuf;
1027 1.1 mw int clen;
1028 1.8 chopps void *buf;
1029 1.1 mw int len;
1030 1.1 mw {
1031 1.8 chopps siop_regmap_p regs = dev->sc_siopp;
1032 1.18 chopps struct siop_iob *iob = dev->sc_cur;
1033 1.1 mw int i;
1034 1.1 mw int status;
1035 1.1 mw u_char istat;
1036 1.1 mw u_char dstat;
1037 1.1 mw u_char sstat0;
1038 1.1 mw
1039 1.1 mw if (dev->sc_flags & SIOP_SELECTED) {
1040 1.1 mw printf ("siopicmd%d: bus busy\n", target);
1041 1.1 mw return -1;
1042 1.1 mw }
1043 1.1 mw regs->siop_sien = 0x00; /* disable SCSI and DMA interrupts */
1044 1.1 mw regs->siop_dien = 0x00;
1045 1.1 mw dev->sc_flags |= SIOP_SELECTED;
1046 1.1 mw dev->sc_slave = target;
1047 1.1 mw #ifdef DEBUG
1048 1.1 mw if (siop_debug & 1)
1049 1.18 chopps printf ("siopicmd: target %x/%x cmd %02x ds %x\n", target,
1050 1.18 chopps lun, *((char *)cbuf), &iob->sc_ds);
1051 1.1 mw #endif
1052 1.18 chopps siop_setup (dev, target, lun, cbuf, clen, buf, len);
1053 1.1 mw
1054 1.1 mw for (;;) {
1055 1.1 mw /* use cmd_wait values? */
1056 1.1 mw i = siop_cmd_wait << 1;
1057 1.1 mw while (((istat = regs->siop_istat) &
1058 1.1 mw (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
1059 1.1 mw if (--i <= 0) {
1060 1.1 mw printf ("waiting: tgt %d cmd %02x sbcl %02x dsp %x (+%x) dcmd %x ds %x\n",
1061 1.8 chopps target, *((char *)cbuf),
1062 1.14 chopps regs->siop_sbcl, regs->siop_dsp,
1063 1.12 chopps regs->siop_dsp - dev->sc_scriptspa,
1064 1.18 chopps *((long *)®s->siop_dcmd), &iob->sc_ds);
1065 1.1 mw i = siop_cmd_wait << 2;
1066 1.8 chopps /* XXXX need an upper limit and reset */
1067 1.1 mw }
1068 1.18 chopps delay(10);
1069 1.1 mw }
1070 1.1 mw dstat = regs->siop_dstat;
1071 1.1 mw sstat0 = regs->siop_sstat0;
1072 1.1 mw #ifdef DEBUG
1073 1.1 mw if (siop_debug & 1) {
1074 1.18 chopps DCIAS(kvtop(iob->sc_stat[0])); /* XXX should just invalidate dev->sc_stat */
1075 1.1 mw printf ("siopicmd: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
1076 1.1 mw istat, dstat, sstat0, regs->siop_dsps, regs->siop_sbcl,
1077 1.18 chopps iob->sc_stat[0], iob->sc_msg[0]);
1078 1.1 mw }
1079 1.1 mw #endif
1080 1.1 mw if (siop_checkintr(dev, istat, dstat, sstat0, &status)) {
1081 1.1 mw dev->sc_flags &= ~SIOP_SELECTED;
1082 1.1 mw return (status);
1083 1.1 mw }
1084 1.1 mw }
1085 1.1 mw }
1086 1.1 mw
1087 1.1 mw int
1088 1.8 chopps siopgo(dev, xs)
1089 1.8 chopps struct siop_softc *dev;
1090 1.8 chopps struct scsi_xfer *xs;
1091 1.1 mw {
1092 1.8 chopps siop_regmap_p regs;
1093 1.1 mw int i;
1094 1.1 mw int nchain;
1095 1.1 mw int count, tcount;
1096 1.1 mw char *addr, *dmaend;
1097 1.1 mw
1098 1.1 mw #ifdef DEBUG
1099 1.1 mw if (siop_debug & 1)
1100 1.8 chopps printf ("%s: go ", dev->sc_dev.dv_xname);
1101 1.8 chopps #if 0
1102 1.1 mw if ((cdb->cdb[1] & 1) == 0 &&
1103 1.1 mw ((cdb->cdb[0] == CMD_WRITE && cdb->cdb[2] == 0 && cdb->cdb[3] == 0) ||
1104 1.1 mw (cdb->cdb[0] == CMD_WRITE_EXT && cdb->cdb[2] == 0 && cdb->cdb[3] == 0
1105 1.1 mw && cdb->cdb[4] == 0)))
1106 1.1 mw panic ("siopgo: attempted write to block < 0x100");
1107 1.1 mw #endif
1108 1.8 chopps #endif
1109 1.8 chopps #if 0
1110 1.1 mw cdb->cdb[1] |= unit << 5;
1111 1.8 chopps #endif
1112 1.1 mw
1113 1.1 mw if (dev->sc_flags & SIOP_SELECTED) {
1114 1.8 chopps printf ("%s: bus busy\n", dev->sc_dev.dv_xname);
1115 1.1 mw return 1;
1116 1.1 mw }
1117 1.1 mw
1118 1.1 mw dev->sc_flags |= SIOP_SELECTED | SIOP_DMA;
1119 1.8 chopps dev->sc_slave = xs->sc_link->target;
1120 1.8 chopps regs = dev->sc_siopp;
1121 1.1 mw /* enable SCSI and DMA interrupts */
1122 1.18 chopps regs->siop_sien = SIOP_SIEN_M_A | SIOP_SIEN_STO | /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE |
1123 1.1 mw SIOP_SIEN_UDC | SIOP_SIEN_RST | SIOP_SIEN_PAR;
1124 1.18 chopps regs->siop_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR |
1125 1.18 chopps /*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID;
1126 1.1 mw #ifdef DEBUG
1127 1.1 mw if (siop_debug & 1)
1128 1.18 chopps printf ("siopgo: target %x cmd %02x ds %x\n", dev->sc_slave, xs->cmd->opcode, &dev->sc_cur->sc_ds);
1129 1.1 mw #endif
1130 1.1 mw
1131 1.18 chopps siop_setup(dev, dev->sc_slave, xs->sc_link->lun, xs->cmd, xs->cmdlen, xs->data, xs->datalen);
1132 1.1 mw
1133 1.1 mw return (0);
1134 1.1 mw }
1135 1.1 mw
1136 1.1 mw /*
1137 1.8 chopps * Check for 53C710 interrupts
1138 1.1 mw */
1139 1.1 mw
1140 1.1 mw int
1141 1.8 chopps siopintr (dev)
1142 1.1 mw register struct siop_softc *dev;
1143 1.1 mw {
1144 1.8 chopps siop_regmap_p regs;
1145 1.1 mw register u_char istat, dstat, sstat0;
1146 1.1 mw int unit;
1147 1.1 mw int status;
1148 1.1 mw int found = 0;
1149 1.1 mw
1150 1.8 chopps regs = dev->sc_siopp;
1151 1.8 chopps istat = dev->sc_istat;
1152 1.8 chopps if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
1153 1.8 chopps return;
1154 1.8 chopps if ((dev->sc_flags & (SIOP_DMA | SIOP_SELECTED)) == SIOP_SELECTED)
1155 1.8 chopps return; /* doing non-interrupt I/O */
1156 1.18 chopps /* Got a valid interrupt on this device */
1157 1.8 chopps dstat = dev->sc_dstat;
1158 1.8 chopps sstat0 = dev->sc_sstat0;
1159 1.8 chopps dev->sc_istat = 0;
1160 1.1 mw #ifdef DEBUG
1161 1.8 chopps if (siop_debug & 1)
1162 1.8 chopps printf ("%s: intr istat %x dstat %x sstat0 %x\n",
1163 1.8 chopps dev->sc_dev.dv_xname, istat, dstat, sstat0);
1164 1.18 chopps if (!dev->sc_active) {
1165 1.18 chopps printf ("%s: spurious interrupt? istat %x dstat %x sstat0 %x status %x\n",
1166 1.18 chopps dev->sc_dev.dv_xname, istat, dstat, sstat0, dev->sc_cur->sc_stat[0]);
1167 1.8 chopps }
1168 1.1 mw #endif
1169 1.1 mw
1170 1.1 mw #ifdef DEBUG
1171 1.8 chopps if (siop_debug & 5) {
1172 1.18 chopps DCIAS(kvtop(&dev->sc_cur->sc_stat[0]));
1173 1.8 chopps printf ("siopintr%d: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
1174 1.8 chopps unit, istat, dstat, sstat0, regs->siop_dsps,
1175 1.18 chopps regs->siop_sbcl, dev->sc_cur->sc_stat[0], dev->sc_cur->sc_msg[0]);
1176 1.8 chopps }
1177 1.1 mw #endif
1178 1.8 chopps if (siop_checkintr (dev, istat, dstat, sstat0, &status)) {
1179 1.1 mw #if 1
1180 1.18 chopps if (dev->sc_active <= 1) { /* more HACK */
1181 1.18 chopps regs->siop_sien = 0;
1182 1.18 chopps regs->siop_dien = 0;
1183 1.18 chopps }
1184 1.8 chopps if (status == 0xff)
1185 1.8 chopps printf ("siopintr: status == 0xff\n");
1186 1.8 chopps #endif
1187 1.18 chopps if (dev->sc_flags & SIOP_DMA) {
1188 1.18 chopps dev->sc_flags &= ~(SIOP_DMA | SIOP_SELECTED);
1189 1.18 chopps if (regs->siop_sbcl & SIOP_BSY)
1190 1.18 chopps printf ("siopintr: SCSI bus busy at I/O completion\n");
1191 1.18 chopps siop_scsidone(dev, dev->sc_cur->sc_stat[0]);
1192 1.18 chopps }
1193 1.1 mw }
1194 1.1 mw }
1195 1.1 mw
1196 1.18 chopps /*
1197 1.18 chopps * This is based on the Progressive Peripherals Zeus driver and may
1198 1.18 chopps * not be correct for other 53c710 boards.
1199 1.18 chopps *
1200 1.18 chopps */
1201 1.8 chopps scsi_period_to_siop (dev, target)
1202 1.8 chopps struct siop_softc *dev;
1203 1.1 mw {
1204 1.8 chopps int period, offset, i, sxfer;
1205 1.1 mw
1206 1.18 chopps period = dev->sc_cur->sc_msg[4];
1207 1.18 chopps offset = dev->sc_cur->sc_msg[5];
1208 1.8 chopps sxfer = 0;
1209 1.8 chopps if (offset <= SIOP_MAX_OFFSET)
1210 1.8 chopps sxfer = offset;
1211 1.8 chopps for (i = 0; i < sizeof (xxx) / 2; ++i) {
1212 1.8 chopps if (period <= xxx[i].x) {
1213 1.8 chopps sxfer |= xxx[i].y & 0x70;
1214 1.8 chopps offset = xxx[i].y & 0x03;
1215 1.8 chopps break;
1216 1.8 chopps }
1217 1.8 chopps }
1218 1.8 chopps dev->sc_sync[target].period = sxfer;
1219 1.8 chopps dev->sc_sync[target].offset = offset;
1220 1.1 mw #ifdef DEBUG
1221 1.8 chopps printf ("sync: siop_sxfr %02x, siop_sbcl %02x\n", sxfer, offset);
1222 1.1 mw #endif
1223 1.1 mw }
1224