siop.c revision 1.23 1 1.23 chopps /* $NetBSD: siop.c,v 1.23 1995/08/18 15:28:08 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.4 chopps #include <sys/param.h>
47 1.4 chopps #include <sys/systm.h>
48 1.8 chopps #include <sys/device.h>
49 1.20 chopps #include <sys/disklabel.h>
50 1.20 chopps #include <sys/dkstat.h>
51 1.4 chopps #include <sys/buf.h>
52 1.8 chopps #include <scsi/scsi_all.h>
53 1.8 chopps #include <scsi/scsiconf.h>
54 1.8 chopps #include <machine/cpu.h>
55 1.8 chopps #include <amiga/amiga/custom.h>
56 1.20 chopps #include <amiga/amiga/isr.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.23 chopps void siop_select __P((struct siop_softc *));
71 1.8 chopps void siopabort __P((struct siop_softc *, siop_regmap_p, char *));
72 1.8 chopps void sioperror __P((struct siop_softc *, siop_regmap_p, u_char));
73 1.8 chopps void siopstart __P((struct siop_softc *));
74 1.8 chopps void siopreset __P((struct siop_softc *));
75 1.8 chopps void siopsetdelay __P((int));
76 1.23 chopps void siop_scsidone __P((struct siop_acb *, int));
77 1.23 chopps void siop_sched __P((struct siop_softc *));
78 1.23 chopps int siop_poll __P((struct siop_softc *, struct siop_acb *));
79 1.8 chopps int siopintr __P((struct siop_softc *));
80 1.1 mw
81 1.1 mw /* 53C710 script */
82 1.23 chopps const
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.23 chopps u_char siop_allow_disc[8] = {3, 3, 3, 3, 3, 3, 3, 3};
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.1 mw
92 1.1 mw int siop_cmd_wait = SCSI_CMD_WAIT;
93 1.1 mw int siop_data_wait = SCSI_DATA_WAIT;
94 1.1 mw int siop_init_wait = SCSI_INIT_WAIT;
95 1.1 mw
96 1.18 chopps /*
97 1.18 chopps * sync period transfer lookup - only valid for 66Mhz clock
98 1.18 chopps */
99 1.1 mw static struct {
100 1.1 mw unsigned char x; /* period from sync request message */
101 1.1 mw unsigned char y; /* siop_period << 4 | sbcl */
102 1.1 mw } xxx[] = {
103 1.18 chopps { 60/4, 0<<4 | 1},
104 1.18 chopps { 76/4, 1<<4 | 1},
105 1.18 chopps { 92/4, 2<<4 | 1},
106 1.18 chopps { 92/4, 0<<4 | 2},
107 1.18 chopps {108/4, 3<<4 | 1},
108 1.18 chopps {116/4, 1<<4 | 2},
109 1.18 chopps {120/4, 4<<4 | 1},
110 1.18 chopps {120/4, 0<<4 | 3},
111 1.18 chopps {136/4, 5<<4 | 1},
112 1.18 chopps {140/4, 2<<4 | 2},
113 1.18 chopps {152/4, 6<<4 | 1},
114 1.18 chopps {152/4, 1<<4 | 3},
115 1.18 chopps {164/4, 3<<4 | 2},
116 1.18 chopps {168/4, 7<<4 | 1},
117 1.18 chopps {180/4, 2<<4 | 3},
118 1.18 chopps {184/4, 4<<4 | 2},
119 1.18 chopps {208/4, 5<<4 | 2},
120 1.18 chopps {212/4, 3<<4 | 3},
121 1.18 chopps {232/4, 6<<4 | 2},
122 1.18 chopps {240/4, 4<<4 | 3},
123 1.18 chopps {256/4, 7<<4 | 2},
124 1.18 chopps {272/4, 5<<4 | 3},
125 1.18 chopps {300/4, 6<<4 | 3},
126 1.18 chopps {332/4, 7<<4 | 3}
127 1.1 mw };
128 1.1 mw
129 1.1 mw #ifdef DEBUG
130 1.8 chopps /*
131 1.8 chopps * 0x01 - full debug
132 1.8 chopps * 0x02 - DMA chaining
133 1.8 chopps * 0x04 - siopintr
134 1.8 chopps * 0x08 - phase mismatch
135 1.23 chopps * 0x10 - <not used>
136 1.15 chopps * 0x20 - panic on unhandled exceptions
137 1.23 chopps * 0x100 - disconnect/reselect
138 1.8 chopps */
139 1.8 chopps int siop_debug = 0;
140 1.8 chopps int siopsync_debug = 0;
141 1.8 chopps int siopdma_hits = 0;
142 1.8 chopps int siopdma_misses = 0;
143 1.14 chopps int siopchain_ints = 0;
144 1.18 chopps int siopstarts = 0;
145 1.18 chopps int siopints = 0;
146 1.18 chopps int siopphmm = 0;
147 1.23 chopps #define SIOP_TRACE_SIZE 128
148 1.23 chopps #define SIOP_TRACE(a,b,c,d) \
149 1.23 chopps siop_trbuf[siop_trix] = (a); \
150 1.23 chopps siop_trbuf[siop_trix+1] = (b); \
151 1.23 chopps siop_trbuf[siop_trix+2] = (c); \
152 1.23 chopps siop_trbuf[siop_trix+3] = (d); \
153 1.23 chopps siop_trix = (siop_trix + 4) & (SIOP_TRACE_SIZE - 1);
154 1.23 chopps u_char siop_trbuf[SIOP_TRACE_SIZE];
155 1.23 chopps int siop_trix;
156 1.16 chopps #else
157 1.23 chopps #define SIOP_TRACE(a,b,c,d)
158 1.1 mw #endif
159 1.8 chopps
160 1.8 chopps
161 1.8 chopps /*
162 1.8 chopps * default minphys routine for siop based controllers
163 1.8 chopps */
164 1.22 mycroft void
165 1.8 chopps siop_minphys(bp)
166 1.8 chopps struct buf *bp;
167 1.8 chopps {
168 1.22 mycroft
169 1.8 chopps /*
170 1.22 mycroft * No max transfer at this level.
171 1.8 chopps */
172 1.22 mycroft minphys(bp);
173 1.1 mw }
174 1.1 mw
175 1.8 chopps /*
176 1.8 chopps * used by specific siop controller
177 1.1 mw *
178 1.8 chopps */
179 1.8 chopps int
180 1.8 chopps siop_scsicmd(xs)
181 1.8 chopps struct scsi_xfer *xs;
182 1.8 chopps {
183 1.23 chopps struct siop_acb *acb;
184 1.20 chopps struct siop_softc *sc;
185 1.8 chopps struct scsi_link *slp;
186 1.18 chopps int flags, s, i;
187 1.8 chopps
188 1.8 chopps slp = xs->sc_link;
189 1.20 chopps sc = slp->adapter_softc;
190 1.8 chopps flags = xs->flags;
191 1.8 chopps
192 1.23 chopps /* XXXX ?? */
193 1.8 chopps if (flags & SCSI_DATA_UIO)
194 1.8 chopps panic("siop: scsi data uio requested");
195 1.22 mycroft
196 1.23 chopps /* XXXX ?? */
197 1.23 chopps if (sc->sc_nexus && flags & SCSI_POLL)
198 1.8 chopps panic("siop_scsicmd: busy");
199 1.8 chopps
200 1.8 chopps s = splbio();
201 1.23 chopps acb = sc->free_list.tqh_first;
202 1.23 chopps if (acb) {
203 1.23 chopps TAILQ_REMOVE(&sc->free_list, acb, chain);
204 1.23 chopps }
205 1.23 chopps splx(s);
206 1.23 chopps
207 1.23 chopps if (acb == NULL) {
208 1.23 chopps xs->error = XS_DRIVER_STUFFUP;
209 1.8 chopps return(TRY_AGAIN_LATER);
210 1.8 chopps }
211 1.8 chopps
212 1.23 chopps acb->flags = ACB_ACTIVE;
213 1.23 chopps acb->xs = xs;
214 1.23 chopps bcopy(xs->cmd, &acb->cmd, xs->cmdlen);
215 1.23 chopps acb->clen = xs->cmdlen;
216 1.23 chopps acb->daddr = xs->data;
217 1.23 chopps acb->dleft = xs->datalen;
218 1.23 chopps
219 1.23 chopps s = splbio();
220 1.23 chopps TAILQ_INSERT_TAIL(&sc->ready_list, acb, chain);
221 1.23 chopps
222 1.23 chopps if (sc->sc_nexus == NULL)
223 1.23 chopps siop_sched(sc);
224 1.23 chopps
225 1.8 chopps splx(s);
226 1.8 chopps
227 1.23 chopps if (flags & SCSI_POLL || siop_no_dma)
228 1.23 chopps return(siop_poll(sc, acb));
229 1.23 chopps return(SUCCESSFULLY_QUEUED);
230 1.23 chopps }
231 1.23 chopps
232 1.23 chopps int
233 1.23 chopps siop_poll(sc, acb)
234 1.23 chopps struct siop_softc *sc;
235 1.23 chopps struct siop_acb *acb;
236 1.23 chopps {
237 1.23 chopps siop_regmap_p rp = sc->sc_siopp;
238 1.23 chopps struct scsi_xfer *xs = acb->xs;
239 1.23 chopps int i;
240 1.23 chopps int status;
241 1.23 chopps u_char istat;
242 1.23 chopps u_char dstat;
243 1.23 chopps u_char sstat0;
244 1.23 chopps int s;
245 1.23 chopps int to;
246 1.8 chopps
247 1.23 chopps s = splbio();
248 1.23 chopps to = xs->timeout / 1000;
249 1.23 chopps if (sc->nexus_list.tqh_first)
250 1.23 chopps printf("%s: siop_poll called with disconnected device\n",
251 1.23 chopps sc->sc_dev.dv_xname);
252 1.23 chopps for (;;) {
253 1.23 chopps /* use cmd_wait values? */
254 1.23 chopps i = 50000;
255 1.23 chopps spl0();
256 1.23 chopps while (((istat = rp->siop_istat) &
257 1.23 chopps (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
258 1.23 chopps if (--i <= 0) {
259 1.23 chopps #ifdef DEBUG
260 1.23 chopps printf ("waiting: tgt %d cmd %02x sbcl %02x dsp %x (+%x) dcmd %x ds %x timeout %d\n",
261 1.23 chopps xs->sc_link->target, acb->cmd.opcode,
262 1.23 chopps rp->siop_sbcl, rp->siop_dsp,
263 1.23 chopps rp->siop_dsp - sc->sc_scriptspa,
264 1.23 chopps *((long *)&rp->siop_dcmd), &acb->ds, acb->xs->timeout);
265 1.23 chopps #endif
266 1.23 chopps i = 50000;
267 1.23 chopps --to;
268 1.23 chopps if (to <= 0) {
269 1.23 chopps siopreset(sc);
270 1.23 chopps return(COMPLETE);
271 1.23 chopps }
272 1.23 chopps }
273 1.23 chopps delay(10);
274 1.23 chopps }
275 1.23 chopps sstat0 = rp->siop_sstat0;
276 1.23 chopps dstat = rp->siop_dstat;
277 1.23 chopps if (siop_checkintr(sc, istat, dstat, sstat0, &status)) {
278 1.23 chopps if (acb != sc->sc_nexus)
279 1.23 chopps printf("%s: siop_poll disconnected device completed\n",
280 1.23 chopps sc->sc_dev.dv_xname);
281 1.23 chopps else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
282 1.23 chopps sc->sc_flags &= ~SIOP_INTSOFF;
283 1.23 chopps rp->siop_sien = sc->sc_sien;
284 1.23 chopps rp->siop_dien = sc->sc_dien;
285 1.23 chopps }
286 1.23 chopps siop_scsidone(sc->sc_nexus, status);
287 1.23 chopps }
288 1.23 chopps if (xs->flags & ITSDONE)
289 1.23 chopps break;
290 1.23 chopps }
291 1.23 chopps splx(s);
292 1.23 chopps return (COMPLETE);
293 1.8 chopps }
294 1.8 chopps
295 1.8 chopps /*
296 1.23 chopps * start next command that's ready
297 1.1 mw */
298 1.1 mw void
299 1.23 chopps siop_sched(sc)
300 1.20 chopps struct siop_softc *sc;
301 1.8 chopps {
302 1.8 chopps struct scsi_link *slp;
303 1.23 chopps struct siop_acb *acb;
304 1.23 chopps int stat, i;
305 1.8 chopps
306 1.23 chopps #ifdef DEBUG
307 1.23 chopps if (sc->sc_nexus) {
308 1.23 chopps printf("%s: siop_sched- nexus %x/%d ready %x/%d\n",
309 1.23 chopps sc->sc_dev.dv_xname, sc->sc_nexus,
310 1.23 chopps sc->sc_nexus->xs->sc_link->target,
311 1.23 chopps sc->ready_list.tqh_first,
312 1.23 chopps sc->ready_list.tqh_first->xs->sc_link->target);
313 1.23 chopps return;
314 1.23 chopps }
315 1.23 chopps #endif
316 1.23 chopps for (acb = sc->ready_list.tqh_first; acb; acb = acb->chain.tqe_next) {
317 1.23 chopps slp = acb->xs->sc_link;
318 1.23 chopps i = slp->target;
319 1.23 chopps if(!(sc->sc_tinfo[i].lubusy & (1 << slp->lun))) {
320 1.23 chopps struct siop_tinfo *ti = &sc->sc_tinfo[i];
321 1.23 chopps
322 1.23 chopps TAILQ_REMOVE(&sc->ready_list, acb, chain);
323 1.23 chopps sc->sc_nexus = acb;
324 1.23 chopps slp = acb->xs->sc_link;
325 1.23 chopps ti = &sc->sc_tinfo[slp->target];
326 1.23 chopps ti->lubusy |= (1 << slp->lun);
327 1.18 chopps break;
328 1.18 chopps }
329 1.18 chopps }
330 1.23 chopps
331 1.23 chopps if (acb == NULL) {
332 1.23 chopps #ifdef DEBUGXXX
333 1.23 chopps printf("%s: siop_sched didn't find ready command\n",
334 1.23 chopps sc->sc_dev.dv_xname);
335 1.18 chopps #endif
336 1.8 chopps return;
337 1.23 chopps }
338 1.23 chopps
339 1.23 chopps if (acb->xs->flags & SCSI_RESET)
340 1.23 chopps siopreset(sc);
341 1.22 mycroft
342 1.23 chopps #if 0
343 1.23 chopps acb->cmd.bytes[0] |= slp->lun << 5; /* XXXX */
344 1.23 chopps #endif
345 1.23 chopps ++sc->sc_active;
346 1.23 chopps siop_select(sc);
347 1.8 chopps }
348 1.8 chopps
349 1.8 chopps void
350 1.23 chopps siop_scsidone(acb, stat)
351 1.23 chopps struct siop_acb *acb;
352 1.8 chopps int stat;
353 1.1 mw {
354 1.23 chopps struct scsi_xfer *xs = acb->xs;
355 1.23 chopps struct scsi_link *slp = xs->sc_link;
356 1.23 chopps struct siop_softc *sc = slp->adapter_softc;
357 1.23 chopps int s, dosched = 0;
358 1.8 chopps
359 1.8 chopps #ifdef DIAGNOSTIC
360 1.23 chopps if (acb == NULL || xs == NULL)
361 1.8 chopps panic("siop_scsidone");
362 1.8 chopps #endif
363 1.23 chopps if (((struct device *)(slp->device_softc))->dv_unit < dk_ndrive)
364 1.23 chopps ++dk_xfer[((struct device *)(slp->device_softc))->dv_unit];
365 1.8 chopps /*
366 1.8 chopps * is this right?
367 1.8 chopps */
368 1.8 chopps xs->status = stat;
369 1.8 chopps
370 1.23 chopps if (xs->error == XS_NOERROR && !(acb->flags & ACB_CHKSENSE)) {
371 1.23 chopps if (stat == SCSI_CHECK) {
372 1.23 chopps struct scsi_sense *ss = (void *)&acb->cmd;
373 1.23 chopps bzero(ss, sizeof(*ss));
374 1.23 chopps ss->opcode = REQUEST_SENSE;
375 1.23 chopps ss->byte2 = slp->lun << 5;
376 1.23 chopps ss->length = sizeof(struct scsi_sense_data);
377 1.23 chopps acb->clen = sizeof(*ss);
378 1.23 chopps acb->daddr = (char *)&xs->sense;
379 1.23 chopps acb->dleft = sizeof(struct scsi_sense_data);
380 1.23 chopps acb->flags = ACB_ACTIVE | ACB_CHKSENSE;
381 1.23 chopps TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain);
382 1.23 chopps --sc->sc_active;
383 1.23 chopps sc->sc_tinfo[slp->target].lubusy &=
384 1.23 chopps ~(1 << slp->lun);
385 1.23 chopps sc->sc_tinfo[slp->target].senses++;
386 1.23 chopps if (sc->sc_nexus == acb) {
387 1.23 chopps sc->sc_nexus = NULL;
388 1.23 chopps siop_sched(sc);
389 1.23 chopps }
390 1.23 chopps SIOP_TRACE('d','s',0,0)
391 1.23 chopps return;
392 1.23 chopps }
393 1.23 chopps }
394 1.23 chopps if (xs->error == XS_NOERROR && (acb->flags & ACB_CHKSENSE)) {
395 1.23 chopps xs->error = XS_SENSE;
396 1.23 chopps } else {
397 1.23 chopps xs->resid = 0; /* XXXX */
398 1.23 chopps }
399 1.23 chopps #if whataboutthisone
400 1.8 chopps case SCSI_BUSY:
401 1.8 chopps xs->error = XS_BUSY;
402 1.8 chopps break;
403 1.23 chopps #endif
404 1.8 chopps xs->flags |= ITSDONE;
405 1.1 mw
406 1.8 chopps /*
407 1.23 chopps * Remove the ACB from whatever queue it's on. We have to do a bit of
408 1.23 chopps * a hack to figure out which queue it's on. Note that it is *not*
409 1.23 chopps * necessary to cdr down the ready queue, but we must cdr down the
410 1.23 chopps * nexus queue and see if it's there, so we can mark the unit as no
411 1.23 chopps * longer busy. This code is sickening, but it works.
412 1.8 chopps */
413 1.23 chopps if (acb == sc->sc_nexus) {
414 1.23 chopps sc->sc_nexus = NULL;
415 1.23 chopps sc->sc_tinfo[slp->target].lubusy &= ~(1<<slp->lun);
416 1.23 chopps if (sc->ready_list.tqh_first)
417 1.23 chopps dosched = 1; /* start next command */
418 1.23 chopps --sc->sc_active;
419 1.23 chopps SIOP_TRACE('d','a',stat,0)
420 1.23 chopps } else if (sc->ready_list.tqh_last == &acb->chain.tqe_next) {
421 1.23 chopps TAILQ_REMOVE(&sc->ready_list, acb, chain);
422 1.23 chopps SIOP_TRACE('d','r',stat,0)
423 1.1 mw } else {
424 1.23 chopps register struct siop_acb *acb2;
425 1.23 chopps for (acb2 = sc->nexus_list.tqh_first; acb2;
426 1.23 chopps acb2 = acb2->chain.tqe_next)
427 1.23 chopps if (acb2 == acb) {
428 1.23 chopps TAILQ_REMOVE(&sc->nexus_list, acb, chain);
429 1.23 chopps sc->sc_tinfo[slp->target].lubusy
430 1.23 chopps &= ~(1<<slp->lun);
431 1.23 chopps --sc->sc_active;
432 1.23 chopps break;
433 1.23 chopps }
434 1.23 chopps if (acb2)
435 1.23 chopps ;
436 1.23 chopps else if (acb->chain.tqe_next) {
437 1.23 chopps TAILQ_REMOVE(&sc->ready_list, acb, chain);
438 1.23 chopps --sc->sc_active;
439 1.23 chopps } else {
440 1.23 chopps printf("%s: can't find matching acb\n",
441 1.23 chopps sc->sc_dev.dv_xname);
442 1.23 chopps #ifdef DDB
443 1.23 chopps /* Debugger(); */
444 1.23 chopps #endif
445 1.23 chopps }
446 1.23 chopps SIOP_TRACE('d','n',stat,0);
447 1.23 chopps }
448 1.23 chopps /* Put it on the free list. */
449 1.23 chopps acb->flags = ACB_FREE;
450 1.23 chopps TAILQ_INSERT_HEAD(&sc->free_list, acb, chain);
451 1.8 chopps
452 1.23 chopps sc->sc_tinfo[slp->target].cmds++;
453 1.1 mw
454 1.23 chopps scsi_done(xs);
455 1.1 mw
456 1.23 chopps if (dosched && sc->sc_nexus == NULL)
457 1.23 chopps siop_sched(sc);
458 1.8 chopps }
459 1.1 mw
460 1.8 chopps void
461 1.20 chopps siopabort(sc, rp, where)
462 1.20 chopps register struct siop_softc *sc;
463 1.20 chopps siop_regmap_p rp;
464 1.1 mw char *where;
465 1.1 mw {
466 1.18 chopps int i;
467 1.1 mw
468 1.22 mycroft printf ("%s: abort %s: dstat %02x, sstat0 %02x sbcl %02x\n",
469 1.20 chopps sc->sc_dev.dv_xname,
470 1.20 chopps where, rp->siop_dstat, rp->siop_sstat0, rp->siop_sbcl);
471 1.1 mw
472 1.20 chopps if (sc->sc_active > 0) {
473 1.1 mw #ifdef TODO
474 1.20 chopps SET_SBIC_cmd (rp, SBIC_CMD_ABORT);
475 1.20 chopps WAIT_CIP (rp);
476 1.1 mw
477 1.20 chopps GET_SBIC_asr (rp, asr);
478 1.1 mw if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
479 1.1 mw {
480 1.1 mw /* ok, get more drastic.. */
481 1.22 mycroft
482 1.20 chopps SET_SBIC_cmd (rp, SBIC_CMD_RESET);
483 1.11 chopps delay(25);
484 1.20 chopps SBIC_WAIT(rp, SBIC_ASR_INT, 0);
485 1.20 chopps GET_SBIC_csr (rp, csr); /* clears interrupt also */
486 1.1 mw
487 1.1 mw return;
488 1.1 mw }
489 1.1 mw
490 1.1 mw do
491 1.1 mw {
492 1.20 chopps SBIC_WAIT (rp, SBIC_ASR_INT, 0);
493 1.20 chopps GET_SBIC_csr (rp, csr);
494 1.1 mw }
495 1.1 mw while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
496 1.1 mw && (csr != SBIC_CSR_CMD_INVALID));
497 1.1 mw #endif
498 1.1 mw
499 1.1 mw /* lets just hope it worked.. */
500 1.23 chopps #ifdef fix_this
501 1.18 chopps for (i = 0; i < 2; ++i) {
502 1.20 chopps if (sc->sc_iob[i].sc_xs && &sc->sc_iob[i] !=
503 1.20 chopps sc->sc_cur) {
504 1.18 chopps printf ("siopabort: cleanup!\n");
505 1.20 chopps sc->sc_iob[i].sc_xs = NULL;
506 1.18 chopps }
507 1.18 chopps }
508 1.23 chopps #endif /* fix_this */
509 1.23 chopps /* sc->sc_active = 0; */
510 1.8 chopps }
511 1.1 mw }
512 1.1 mw
513 1.1 mw void
514 1.20 chopps siopinitialize(sc)
515 1.20 chopps struct siop_softc *sc;
516 1.12 chopps {
517 1.12 chopps /*
518 1.14 chopps * Need to check that scripts is on a long word boundary
519 1.14 chopps * and that DS is on a long word boundary.
520 1.23 chopps * Also should verify that dev doesn't span non-contiguous
521 1.14 chopps * physical pages.
522 1.12 chopps */
523 1.20 chopps sc->sc_scriptspa = kvtop(scripts);
524 1.23 chopps
525 1.20 chopps siopreset (sc);
526 1.12 chopps }
527 1.12 chopps
528 1.12 chopps void
529 1.20 chopps siopreset(sc)
530 1.20 chopps struct siop_softc *sc;
531 1.1 mw {
532 1.20 chopps siop_regmap_p rp;
533 1.1 mw u_int i, s;
534 1.23 chopps u_char dummy;
535 1.23 chopps struct siop_acb *acb;
536 1.1 mw
537 1.20 chopps rp = sc->sc_siopp;
538 1.8 chopps
539 1.20 chopps if (sc->sc_flags & SIOP_ALIVE)
540 1.20 chopps siopabort(sc, rp, "reset");
541 1.22 mycroft
542 1.20 chopps printf("%s: ", sc->sc_dev.dv_xname); /* XXXX */
543 1.1 mw
544 1.1 mw s = splbio();
545 1.1 mw
546 1.1 mw /*
547 1.1 mw * Reset the chip
548 1.1 mw * XXX - is this really needed?
549 1.1 mw */
550 1.20 chopps rp->siop_istat |= SIOP_ISTAT_ABRT; /* abort current script */
551 1.20 chopps rp->siop_istat |= SIOP_ISTAT_RST; /* reset chip */
552 1.20 chopps rp->siop_istat &= ~SIOP_ISTAT_RST;
553 1.18 chopps /*
554 1.18 chopps * Reset SCSI bus (do we really want this?)
555 1.18 chopps */
556 1.23 chopps rp->siop_sien = 0;
557 1.20 chopps rp->siop_scntl1 |= SIOP_SCNTL1_RST;
558 1.18 chopps delay(1);
559 1.20 chopps rp->siop_scntl1 &= ~SIOP_SCNTL1_RST;
560 1.1 mw
561 1.1 mw /*
562 1.1 mw * Set up various chip parameters
563 1.1 mw */
564 1.20 chopps rp->siop_scntl0 = SIOP_ARB_FULL | SIOP_SCNTL0_EPC | SIOP_SCNTL0_EPG;
565 1.23 chopps rp->siop_scntl1 = SIOP_SCNTL1_ESR;
566 1.20 chopps rp->siop_dcntl = sc->sc_clock_freq & 0xff;
567 1.20 chopps rp->siop_dmode = 0x80; /* burst length = 4 */
568 1.20 chopps rp->siop_sien = 0x00; /* don't enable interrupts yet */
569 1.20 chopps rp->siop_dien = 0x00; /* don't enable interrupts yet */
570 1.23 chopps rp->siop_scid = 1 << sc->sc_link.adapter_target;
571 1.20 chopps rp->siop_dwt = 0x00;
572 1.20 chopps rp->siop_ctest0 |= SIOP_CTEST0_BTD | SIOP_CTEST0_EAN;
573 1.20 chopps rp->siop_ctest7 |= (sc->sc_clock_freq >> 8) & 0xff;
574 1.1 mw
575 1.1 mw /* will need to re-negotiate sync xfers */
576 1.20 chopps bzero(&sc->sc_sync, sizeof (sc->sc_sync));
577 1.1 mw
578 1.20 chopps i = rp->siop_istat;
579 1.18 chopps if (i & SIOP_ISTAT_SIP)
580 1.20 chopps dummy = rp->siop_sstat0;
581 1.18 chopps if (i & SIOP_ISTAT_DIP)
582 1.20 chopps dummy = rp->siop_dstat;
583 1.18 chopps
584 1.1 mw splx (s);
585 1.1 mw
586 1.23 chopps delay (siop_reset_delay * 1000);
587 1.23 chopps printf("siop id %d reset V%d\n", sc->sc_link.adapter_target,
588 1.23 chopps rp->siop_ctest8 >> 4);
589 1.23 chopps
590 1.23 chopps if ((sc->sc_flags & SIOP_ALIVE) == 0) {
591 1.23 chopps TAILQ_INIT(&sc->ready_list);
592 1.23 chopps TAILQ_INIT(&sc->nexus_list);
593 1.23 chopps TAILQ_INIT(&sc->free_list);
594 1.23 chopps sc->sc_nexus = NULL;
595 1.23 chopps acb = sc->sc_acb;
596 1.23 chopps bzero(acb, sizeof(sc->sc_acb));
597 1.23 chopps for (i = 0; i < sizeof(sc->sc_acb) / sizeof(*acb); i++) {
598 1.23 chopps TAILQ_INSERT_TAIL(&sc->free_list, acb, chain);
599 1.23 chopps acb++;
600 1.23 chopps }
601 1.23 chopps bzero(sc->sc_tinfo, sizeof(sc->sc_tinfo));
602 1.23 chopps } else {
603 1.23 chopps if (sc->sc_nexus != NULL) {
604 1.23 chopps sc->sc_nexus->xs->error = XS_DRIVER_STUFFUP;
605 1.23 chopps siop_scsidone(sc->sc_nexus, sc->sc_nexus->stat[0]);
606 1.23 chopps }
607 1.23 chopps while (acb = sc->nexus_list.tqh_first) {
608 1.23 chopps acb->xs->error = XS_DRIVER_STUFFUP;
609 1.23 chopps siop_scsidone(acb, acb->stat[0]);
610 1.23 chopps }
611 1.23 chopps }
612 1.23 chopps
613 1.20 chopps sc->sc_flags |= SIOP_ALIVE;
614 1.23 chopps sc->sc_flags &= ~(SIOP_INTDEFER|SIOP_INTSOFF);
615 1.23 chopps /* enable SCSI and DMA interrupts */
616 1.23 chopps sc->sc_sien = SIOP_SIEN_M_A | SIOP_SIEN_STO | /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE |
617 1.23 chopps SIOP_SIEN_UDC | SIOP_SIEN_RST | SIOP_SIEN_PAR;
618 1.23 chopps sc->sc_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR |
619 1.23 chopps /*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID;
620 1.23 chopps rp->siop_sien = sc->sc_sien;
621 1.23 chopps rp->siop_dien = sc->sc_dien;
622 1.1 mw }
623 1.1 mw
624 1.1 mw /*
625 1.1 mw * Setup Data Storage for 53C710 and start SCRIPTS processing
626 1.1 mw */
627 1.1 mw
628 1.8 chopps void
629 1.23 chopps siop_start (sc, target, lun, cbuf, clen, buf, len)
630 1.20 chopps struct siop_softc *sc;
631 1.1 mw int target;
632 1.18 chopps int lun;
633 1.1 mw u_char *cbuf;
634 1.1 mw int clen;
635 1.1 mw u_char *buf;
636 1.1 mw int len;
637 1.1 mw {
638 1.20 chopps siop_regmap_p rp = sc->sc_siopp;
639 1.1 mw int i;
640 1.1 mw int nchain;
641 1.1 mw int count, tcount;
642 1.1 mw char *addr, *dmaend;
643 1.23 chopps struct siop_acb *acb = sc->sc_nexus;
644 1.1 mw
645 1.18 chopps #ifdef DEBUG
646 1.23 chopps if (siop_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
647 1.23 chopps printf ("ACK! siop was busy: rp %x script %x dsa %x active %d\n",
648 1.23 chopps rp, &scripts, &acb->ds, sc->sc_active);
649 1.23 chopps printf ("istat %02x sfbr %02x lcrc %02x sien %02x dien %02x\n",
650 1.23 chopps rp->siop_istat, rp->siop_sfbr, rp->siop_lcrc,
651 1.23 chopps rp->siop_sien, rp->siop_dien);
652 1.23 chopps #ifdef DDB
653 1.18 chopps /*Debugger();*/
654 1.23 chopps #endif
655 1.18 chopps }
656 1.18 chopps #endif
657 1.23 chopps acb->msgout[0] = MSG_IDENTIFY | lun;
658 1.23 chopps if (siop_allow_disc[target] & 2 ||
659 1.23 chopps (siop_allow_disc[target] && len == 0))
660 1.23 chopps acb->msgout[0] = MSG_IDENTIFY_DR | lun;
661 1.23 chopps acb->status = 0;
662 1.23 chopps acb->stat[0] = -1;
663 1.23 chopps acb->msg[0] = -1;
664 1.23 chopps acb->ds.scsi_addr = (0x10000 << target) | (sc->sc_sync[target].period << 8);
665 1.23 chopps acb->ds.idlen = 1;
666 1.23 chopps acb->ds.idbuf = (char *) kvtop(&acb->msgout[0]);
667 1.23 chopps acb->ds.cmdlen = clen;
668 1.23 chopps acb->ds.cmdbuf = (char *) kvtop(cbuf);
669 1.23 chopps acb->ds.stslen = 1;
670 1.23 chopps acb->ds.stsbuf = (char *) kvtop(&acb->stat[0]);
671 1.23 chopps acb->ds.msglen = 1;
672 1.23 chopps acb->ds.msgbuf = (char *) kvtop(&acb->msg[0]);
673 1.23 chopps acb->msg[1] = -1;
674 1.23 chopps acb->ds.msginlen = 1;
675 1.23 chopps acb->ds.extmsglen = 1;
676 1.23 chopps acb->ds.synmsglen = 3;
677 1.23 chopps acb->ds.msginbuf = (char *) kvtop(&acb->msg[1]);
678 1.23 chopps acb->ds.extmsgbuf = (char *) kvtop(&acb->msg[2]);
679 1.23 chopps acb->ds.synmsgbuf = (char *) kvtop(&acb->msg[3]);
680 1.23 chopps bzero(&acb->ds.chain, sizeof (acb->ds.chain));
681 1.1 mw
682 1.20 chopps if (sc->sc_sync[target].state == SYNC_START) {
683 1.8 chopps if (siop_inhibit_sync[target]) {
684 1.20 chopps sc->sc_sync[target].state = SYNC_DONE;
685 1.20 chopps sc->sc_sync[target].offset = 0;
686 1.20 chopps sc->sc_sync[target].period = 0;
687 1.1 mw #ifdef DEBUG
688 1.1 mw if (siopsync_debug)
689 1.1 mw printf ("Forcing target %d asynchronous\n", target);
690 1.1 mw #endif
691 1.1 mw }
692 1.1 mw else {
693 1.23 chopps acb->msg[2] = -1;
694 1.23 chopps acb->msgout[1] = MSG_EXT_MESSAGE;
695 1.23 chopps acb->msgout[2] = 3;
696 1.23 chopps acb->msgout[3] = MSG_SYNC_REQ;
697 1.23 chopps #ifdef MAXTOR_SYNC_KLUDGE
698 1.23 chopps acb->msgout[4] = 50 / 4; /* ask for ridiculous period */
699 1.23 chopps #else
700 1.23 chopps acb->msgout[4] = 100 / 4;
701 1.23 chopps #endif
702 1.23 chopps acb->msgout[5] = SIOP_MAX_OFFSET;
703 1.23 chopps acb->ds.idlen = 6;
704 1.20 chopps sc->sc_sync[target].state = SYNC_SENT;
705 1.1 mw #ifdef DEBUG
706 1.1 mw if (siopsync_debug)
707 1.1 mw printf ("Sending sync request to target %d\n", target);
708 1.1 mw #endif
709 1.1 mw }
710 1.1 mw }
711 1.1 mw
712 1.1 mw /*
713 1.23 chopps * Build physical DMA addresses for scatter/gather I/O
714 1.1 mw */
715 1.23 chopps acb->iob_buf = buf;
716 1.23 chopps acb->iob_len = len;
717 1.23 chopps acb->iob_curbuf = acb->iob_curlen = 0;
718 1.1 mw nchain = 0;
719 1.1 mw count = len;
720 1.1 mw addr = buf;
721 1.1 mw dmaend = NULL;
722 1.1 mw while (count > 0) {
723 1.23 chopps acb->ds.chain[nchain].databuf = (char *) kvtop (addr);
724 1.1 mw if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
725 1.1 mw tcount = count;
726 1.23 chopps acb->ds.chain[nchain].datalen = tcount;
727 1.1 mw addr += tcount;
728 1.1 mw count -= tcount;
729 1.23 chopps if (acb->ds.chain[nchain].databuf == dmaend) {
730 1.23 chopps dmaend += acb->ds.chain[nchain].datalen;
731 1.23 chopps acb->ds.chain[nchain].datalen = 0;
732 1.23 chopps acb->ds.chain[--nchain].datalen += tcount;
733 1.1 mw #ifdef DEBUG
734 1.1 mw ++siopdma_hits;
735 1.1 mw #endif
736 1.1 mw }
737 1.1 mw else {
738 1.23 chopps dmaend = acb->ds.chain[nchain].databuf +
739 1.23 chopps acb->ds.chain[nchain].datalen;
740 1.23 chopps acb->ds.chain[nchain].datalen = tcount;
741 1.1 mw #ifdef DEBUG
742 1.14 chopps if (nchain) /* Don't count miss on first one */
743 1.14 chopps ++siopdma_misses;
744 1.1 mw #endif
745 1.1 mw }
746 1.1 mw ++nchain;
747 1.1 mw }
748 1.1 mw #ifdef DEBUG
749 1.1 mw if (nchain != 1 && len != 0 && siop_debug & 3) {
750 1.1 mw printf ("DMA chaining set: %d\n", nchain);
751 1.1 mw for (i = 0; i < nchain; ++i) {
752 1.23 chopps printf (" [%d] %8x %4x\n", i, acb->ds.chain[i].databuf,
753 1.23 chopps acb->ds.chain[i].datalen);
754 1.1 mw }
755 1.1 mw }
756 1.1 mw #endif
757 1.1 mw
758 1.23 chopps /* push data cache for all data the 53c710 needs to access */
759 1.20 chopps dma_cachectl (sc, sizeof (struct siop_softc));
760 1.12 chopps dma_cachectl (cbuf, clen);
761 1.12 chopps if (buf != NULL && len != 0)
762 1.12 chopps dma_cachectl (buf, len);
763 1.23 chopps #ifdef DEBUG
764 1.23 chopps if (siop_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
765 1.23 chopps printf ("ACK! siop was busy at start: rp %x script %x dsa %x active %d\n",
766 1.23 chopps rp, &scripts, &acb->ds, sc->sc_active);
767 1.23 chopps #ifdef DDB
768 1.23 chopps /*Debugger();*/
769 1.23 chopps #endif
770 1.23 chopps }
771 1.23 chopps #endif
772 1.23 chopps if (sc->nexus_list.tqh_first == NULL) {
773 1.23 chopps if (rp->siop_istat & SIOP_ISTAT_CON)
774 1.23 chopps printf("%s: siop_select while connected?\n",
775 1.23 chopps sc->sc_dev.dv_xname);
776 1.23 chopps rp->siop_temp = 0;
777 1.20 chopps rp->siop_sbcl = sc->sc_sync[target].offset;
778 1.23 chopps rp->siop_dsa = kvtop(&acb->ds);
779 1.20 chopps rp->siop_dsp = sc->sc_scriptspa;
780 1.23 chopps SIOP_TRACE('s',1,0,0)
781 1.18 chopps } else {
782 1.23 chopps if ((rp->siop_istat & SIOP_ISTAT_CON) == 0) {
783 1.23 chopps rp->siop_istat = SIOP_ISTAT_SIGP;
784 1.23 chopps SIOP_TRACE('s',2,0,0);
785 1.23 chopps }
786 1.23 chopps else {
787 1.23 chopps SIOP_TRACE('s',3,rp->siop_istat,0);
788 1.23 chopps }
789 1.18 chopps }
790 1.18 chopps #ifdef DEBUG
791 1.18 chopps ++siopstarts;
792 1.18 chopps #endif
793 1.1 mw }
794 1.1 mw
795 1.1 mw /*
796 1.1 mw * Process a DMA or SCSI interrupt from the 53C710 SIOP
797 1.1 mw */
798 1.1 mw
799 1.8 chopps int
800 1.20 chopps siop_checkintr(sc, istat, dstat, sstat0, status)
801 1.20 chopps struct siop_softc *sc;
802 1.1 mw u_char istat;
803 1.1 mw u_char dstat;
804 1.1 mw u_char sstat0;
805 1.1 mw int *status;
806 1.1 mw {
807 1.20 chopps siop_regmap_p rp = sc->sc_siopp;
808 1.23 chopps struct siop_acb *acb = sc->sc_nexus;
809 1.1 mw int target;
810 1.18 chopps int dfifo, dbc, sstat1;
811 1.1 mw
812 1.20 chopps dfifo = rp->siop_dfifo;
813 1.20 chopps dbc = rp->siop_dbc0;
814 1.20 chopps sstat1 = rp->siop_sstat1;
815 1.20 chopps rp->siop_ctest8 |= SIOP_CTEST8_CLF;
816 1.23 chopps while ((rp->siop_ctest1 & SIOP_CTEST1_FMT) != SIOP_CTEST1_FMT)
817 1.1 mw ;
818 1.20 chopps rp->siop_ctest8 &= ~SIOP_CTEST8_CLF;
819 1.1 mw #ifdef DEBUG
820 1.18 chopps ++siopints;
821 1.23 chopps #if 0
822 1.18 chopps if (siop_debug & 0x100) {
823 1.23 chopps DCIAS(&acb->stat[0]); /* XXX */
824 1.1 mw printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
825 1.23 chopps istat, dstat, sstat0, rp->siop_dsps, rp->siop_sbcl, acb->stat[0], acb->msg[0]);
826 1.18 chopps printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
827 1.23 chopps acb->msg[0], acb->msg[1], acb->msg[2],
828 1.23 chopps acb->msg[3], acb->msg[4], acb->msg[5]);
829 1.23 chopps }
830 1.23 chopps #endif
831 1.23 chopps if (rp->siop_dsp && (rp->siop_dsp < sc->sc_scriptspa ||
832 1.23 chopps rp->siop_dsp >= sc->sc_scriptspa + sizeof(scripts))) {
833 1.23 chopps printf ("%s: dsp not within script dsp %x scripts %x:%x",
834 1.23 chopps sc->sc_dev.dv_xname, rp->siop_dsp, sc->sc_scriptspa,
835 1.23 chopps sc->sc_scriptspa + sizeof(scripts));
836 1.23 chopps printf(" istat %x dstat %x sstat0 %x\n",
837 1.23 chopps istat, dstat, sstat0);
838 1.23 chopps Debugger();
839 1.1 mw }
840 1.1 mw #endif
841 1.23 chopps SIOP_TRACE('i',dstat,istat,(istat&SIOP_ISTAT_DIP)?rp->siop_dsps&0xff:sstat0);
842 1.20 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff00) {
843 1.1 mw /* Normal completion status, or check condition */
844 1.23 chopps #ifdef DEBUG
845 1.23 chopps if (rp->siop_dsa != kvtop(&acb->ds)) {
846 1.20 chopps printf ("siop: invalid dsa: %x %x\n", rp->siop_dsa,
847 1.23 chopps kvtop(&acb->ds));
848 1.1 mw panic("*** siop DSA invalid ***");
849 1.1 mw }
850 1.23 chopps #endif
851 1.23 chopps target = acb->xs->sc_link->target;
852 1.20 chopps if (sc->sc_sync[target].state == SYNC_SENT) {
853 1.1 mw #ifdef DEBUG
854 1.1 mw if (siopsync_debug)
855 1.1 mw printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
856 1.23 chopps acb->msg[0], acb->msg[1], acb->msg[2],
857 1.23 chopps acb->msg[3], acb->msg[4], acb->msg[5]);
858 1.1 mw #endif
859 1.23 chopps if (acb->msg[1] == 0xff)
860 1.18 chopps printf ("%s: target %d ignored sync request\n",
861 1.20 chopps sc->sc_dev.dv_xname, target);
862 1.23 chopps else if (acb->msg[1] == MSG_REJECT)
863 1.18 chopps printf ("%s: target %d rejected sync request\n",
864 1.20 chopps sc->sc_dev.dv_xname, target);
865 1.20 chopps sc->sc_sync[target].state = SYNC_DONE;
866 1.20 chopps sc->sc_sync[target].period = 0;
867 1.20 chopps sc->sc_sync[target].offset = 0;
868 1.23 chopps if (acb->msg[2] == 3 &&
869 1.23 chopps acb->msg[3] == MSG_SYNC_REQ &&
870 1.23 chopps acb->msg[5] != 0) {
871 1.23 chopps #ifdef MAXTOR_KLUDGE
872 1.23 chopps /*
873 1.23 chopps * Kludge for my Maxtor XT8580S
874 1.23 chopps * It accepts whatever we request, even
875 1.23 chopps * though it won't work. So we ask for
876 1.23 chopps * a short period than we can handle. If
877 1.23 chopps * the device says it can do it, use 208ns.
878 1.23 chopps * If the device says it can do less than
879 1.23 chopps * 100ns, then we limit it to 100ns.
880 1.23 chopps */
881 1.23 chopps if (acb->msg[4] && acb->msg[4] < 100 / 4) {
882 1.8 chopps #ifdef DEBUG
883 1.8 chopps printf ("%d: target %d wanted %dns period\n",
884 1.20 chopps sc->sc_dev.dv_xname, target,
885 1.23 chopps acb->msg[4] * 4);
886 1.8 chopps #endif
887 1.23 chopps if (acb->msg[4] == 50 / 4)
888 1.23 chopps acb->msg[4] = 208 / 4;
889 1.8 chopps else
890 1.23 chopps acb->msg[4] = 100 / 4;
891 1.8 chopps }
892 1.23 chopps #endif /* MAXTOR_KLUDGE */
893 1.8 chopps printf ("%s: target %d now synchronous, period=%dns, offset=%d\n",
894 1.20 chopps sc->sc_dev.dv_xname, target,
895 1.23 chopps acb->msg[4] * 4, acb->msg[5]);
896 1.20 chopps scsi_period_to_siop (sc, target);
897 1.1 mw }
898 1.1 mw }
899 1.23 chopps dma_cachectl(&acb->stat[0], 1);
900 1.23 chopps *status = acb->stat[0];
901 1.18 chopps #ifdef DEBUG
902 1.20 chopps if (rp->siop_sbcl & SIOP_BSY) {
903 1.20 chopps /*printf ("ACK! siop was busy at end: rp %x script %x dsa %x\n",
904 1.23 chopps rp, &scripts, &acb->ds);*/
905 1.23 chopps #ifdef DDB
906 1.18 chopps /*Debugger();*/
907 1.23 chopps #endif
908 1.18 chopps }
909 1.23 chopps if (acb->msg[0] != 0x00)
910 1.23 chopps printf("%s: message was not COMMAND COMPLETE: %x\n",
911 1.23 chopps sc->sc_dev.dv_xname, acb->msg[0]);
912 1.11 chopps #endif
913 1.23 chopps if (sc->nexus_list.tqh_first)
914 1.20 chopps rp->siop_dcntl |= SIOP_DCNTL_STD;
915 1.1 mw return 1;
916 1.1 mw }
917 1.1 mw if (sstat0 & SIOP_SSTAT0_M_A) { /* Phase mismatch */
918 1.1 mw #ifdef DEBUG
919 1.18 chopps ++siopphmm;
920 1.23 chopps if (acb == NULL)
921 1.23 chopps printf("%s: Phase mismatch with no active command?\n",
922 1.23 chopps sc->sc_dev.dv_xname);
923 1.23 chopps #endif
924 1.23 chopps if (acb->iob_len) {
925 1.18 chopps int adjust;
926 1.18 chopps adjust = ((dfifo - (dbc & 0x7f)) & 0x7f);
927 1.18 chopps if (sstat1 & SIOP_SSTAT1_ORF)
928 1.18 chopps ++adjust;
929 1.18 chopps if (sstat1 & SIOP_SSTAT1_OLF)
930 1.18 chopps ++adjust;
931 1.23 chopps acb->iob_curlen = *((long *)&rp->siop_dcmd) & 0xffffff;
932 1.23 chopps acb->iob_curlen += adjust;
933 1.23 chopps acb->iob_curbuf = *((long *)&rp->siop_dnad) - adjust;
934 1.23 chopps #ifdef DEBUG
935 1.23 chopps if (siop_debug & 0x100) {
936 1.23 chopps int i;
937 1.23 chopps printf ("Phase mismatch: curbuf %x curlen %x dfifo %x dbc %x sstat1 %x adjust %x sbcl %x starts %d acb %x\n",
938 1.23 chopps acb->iob_curbuf, acb->iob_curlen, dfifo,
939 1.23 chopps dbc, sstat1, adjust, rp->siop_sbcl, siopstarts, acb);
940 1.23 chopps if (acb->ds.chain[1].datalen) {
941 1.23 chopps for (i = 0; acb->ds.chain[i].datalen; ++i)
942 1.23 chopps printf("chain[%d] addr %x len %x\n",
943 1.23 chopps i, acb->ds.chain[i].databuf,
944 1.23 chopps acb->ds.chain[i].datalen);
945 1.23 chopps }
946 1.23 chopps }
947 1.18 chopps #endif
948 1.23 chopps dma_cachectl (acb, sizeof(*acb));
949 1.18 chopps }
950 1.23 chopps #ifdef DEBUG
951 1.23 chopps SIOP_TRACE('m',rp->siop_sbcl,(rp->siop_dsp>>8),rp->siop_dsp);
952 1.1 mw if (siop_debug & 9)
953 1.18 chopps printf ("Phase mismatch: %x dsp +%x dcmd %x\n",
954 1.20 chopps rp->siop_sbcl,
955 1.20 chopps rp->siop_dsp - sc->sc_scriptspa,
956 1.20 chopps *((long *)&rp->siop_dcmd));
957 1.1 mw #endif
958 1.23 chopps if ((rp->siop_sbcl & SIOP_REQ) == 0) {
959 1.23 chopps printf ("Phase mismatch: REQ not asserted! %02x dsp %x\n",
960 1.23 chopps rp->siop_sbcl, rp->siop_dsp);
961 1.23 chopps #ifdef DEBUG
962 1.23 chopps Debugger();
963 1.23 chopps #endif
964 1.23 chopps }
965 1.20 chopps switch (rp->siop_sbcl & 7) {
966 1.18 chopps case 0: /* data out */
967 1.18 chopps case 1: /* data in */
968 1.18 chopps case 2: /* status */
969 1.18 chopps case 3: /* command */
970 1.18 chopps case 6: /* message in */
971 1.18 chopps case 7: /* message out */
972 1.20 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
973 1.1 mw break;
974 1.1 mw default:
975 1.1 mw goto bad_phase;
976 1.1 mw }
977 1.1 mw return 0;
978 1.1 mw }
979 1.1 mw if (sstat0 & SIOP_SSTAT0_STO) { /* Select timed out */
980 1.1 mw #ifdef DEBUG
981 1.23 chopps if (acb == NULL)
982 1.23 chopps printf("%s: Select timeout with no active command?\n",
983 1.23 chopps sc->sc_dev.dv_xname);
984 1.20 chopps if (rp->siop_sbcl & SIOP_BSY) {
985 1.20 chopps printf ("ACK! siop was busy at timeout: rp %x script %x dsa %x\n",
986 1.23 chopps rp, &scripts, &acb->ds);
987 1.18 chopps printf(" sbcl %x sdid %x istat %x dstat %x sstat0 %x\n",
988 1.20 chopps rp->siop_sbcl, rp->siop_sdid, istat, dstat, sstat0);
989 1.23 chopps if (!(rp->siop_sbcl & SIOP_BSY)) {
990 1.23 chopps printf ("Yikes, it's not busy now!\n");
991 1.18 chopps #if 0
992 1.23 chopps *status = -1;
993 1.23 chopps if (sc->nexus_list.tqh_first)
994 1.23 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
995 1.23 chopps return 1;
996 1.1 mw #endif
997 1.23 chopps }
998 1.20 chopps /* rp->siop_dcntl |= SIOP_DCNTL_STD;*/
999 1.1 mw return (0);
1000 1.23 chopps #ifdef DDB
1001 1.18 chopps Debugger();
1002 1.23 chopps #endif
1003 1.1 mw }
1004 1.18 chopps #endif
1005 1.18 chopps *status = -1;
1006 1.23 chopps acb->xs->error = XS_SELTIMEOUT;
1007 1.23 chopps if (sc->nexus_list.tqh_first)
1008 1.20 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1009 1.18 chopps return 1;
1010 1.1 mw }
1011 1.23 chopps if (acb)
1012 1.23 chopps target = acb->xs->sc_link->target;
1013 1.23 chopps else
1014 1.23 chopps target = 7;
1015 1.18 chopps if (sstat0 & SIOP_SSTAT0_UDC) {
1016 1.8 chopps #ifdef DEBUG
1017 1.23 chopps if (acb == NULL)
1018 1.23 chopps printf("%s: Unexpected disconnect with no active command?\n",
1019 1.23 chopps sc->sc_dev.dv_xname);
1020 1.8 chopps printf ("%s: target %d disconnected unexpectedly\n",
1021 1.20 chopps sc->sc_dev.dv_xname, target);
1022 1.8 chopps #endif
1023 1.8 chopps #if 0
1024 1.20 chopps siopabort (sc, rp, "siopchkintr");
1025 1.8 chopps #endif
1026 1.8 chopps *status = STS_BUSY;
1027 1.23 chopps if (sc->nexus_list.tqh_first)
1028 1.20 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1029 1.8 chopps return 1;
1030 1.8 chopps }
1031 1.23 chopps if (dstat & SIOP_DSTAT_SIR && (rp->siop_dsps == 0xff01 ||
1032 1.23 chopps rp->siop_dsps == 0xff02)) {
1033 1.18 chopps #ifdef DEBUG
1034 1.18 chopps if (siop_debug & 0x100)
1035 1.23 chopps printf ("%s: ID %02x disconnected TEMP %x (+%x) curbuf %x curlen %x buf %x len %x dfifo %x dbc %x sstat1 %x starts %d acb %x\n",
1036 1.20 chopps sc->sc_dev.dv_xname, 1 << target, rp->siop_temp,
1037 1.23 chopps rp->siop_temp ? rp->siop_temp - sc->sc_scriptspa : 0,
1038 1.23 chopps acb->iob_curbuf, acb->iob_curlen,
1039 1.23 chopps acb->ds.chain[0].databuf, acb->ds.chain[0].datalen, dfifo, dbc, sstat1, siopstarts, acb);
1040 1.23 chopps #endif
1041 1.23 chopps if (acb == NULL) {
1042 1.23 chopps printf("%s: Disconnect with no active command?\n",
1043 1.23 chopps sc->sc_dev.dv_xname);
1044 1.23 chopps return (0);
1045 1.23 chopps }
1046 1.23 chopps /*
1047 1.23 chopps * XXXX need to update iob_curbuf/iob_curlen to reflect
1048 1.23 chopps * current data transferred. If device disconnected in
1049 1.23 chopps * the middle of a DMA block, they should already be set
1050 1.23 chopps * by the phase change interrupt. If the disconnect
1051 1.23 chopps * occurs on a DMA block boundary, we have to figure out
1052 1.23 chopps * which DMA block it was.
1053 1.23 chopps */
1054 1.23 chopps if (acb->iob_len && rp->siop_temp) {
1055 1.23 chopps int n = rp->siop_temp - sc->sc_scriptspa;
1056 1.23 chopps
1057 1.23 chopps if (acb->iob_curlen && acb->iob_curlen != acb->ds.chain[0].datalen)
1058 1.23 chopps printf("%s: iob_curbuf/len already set? n %x iob %x/%x chain[0] %x/%x\n",
1059 1.23 chopps sc->sc_dev.dv_xname, n, acb->iob_curbuf, acb->iob_curlen,
1060 1.23 chopps acb->ds.chain[0].databuf, acb->ds.chain[0].datalen);
1061 1.23 chopps if (n < Ent_datain)
1062 1.23 chopps n = (n - Ent_dataout) / 16;
1063 1.23 chopps else
1064 1.23 chopps n = (n - Ent_datain) / 16;
1065 1.23 chopps if (n <= 0 && n > DMAMAXIO)
1066 1.23 chopps printf("TEMP invalid %d\n", n);
1067 1.23 chopps else {
1068 1.23 chopps acb->iob_curbuf = (u_long)acb->ds.chain[n].databuf;
1069 1.23 chopps acb->iob_curlen = acb->ds.chain[n].datalen;
1070 1.23 chopps }
1071 1.23 chopps #ifdef DEBUG
1072 1.23 chopps if (siop_debug & 0x100) {
1073 1.23 chopps printf("%s: TEMP offset %d", sc->sc_dev.dv_xname, n);
1074 1.23 chopps printf(" curbuf %x curlen %x\n", acb->iob_curbuf,
1075 1.23 chopps acb->iob_curlen);
1076 1.23 chopps }
1077 1.18 chopps #endif
1078 1.23 chopps }
1079 1.18 chopps /*
1080 1.23 chopps * If data transfer was interrupted by disconnect, iob_curbuf
1081 1.23 chopps * and iob_curlen should reflect the point of interruption.
1082 1.23 chopps * Adjust the DMA chain so that the data transfer begins
1083 1.23 chopps * at the appropriate place upon reselection.
1084 1.23 chopps * XXX This should only be done on save data pointer message?
1085 1.18 chopps */
1086 1.23 chopps if (acb->iob_curlen) {
1087 1.23 chopps int i, j;
1088 1.23 chopps
1089 1.23 chopps #ifdef DEBUG
1090 1.23 chopps if (siop_debug & 0x100)
1091 1.23 chopps printf ("%s: adjusting DMA chain\n",
1092 1.23 chopps sc->sc_dev.dv_xname);
1093 1.23 chopps if (rp->siop_dsps == 0xff02)
1094 1.23 chopps printf ("%s: ID %02x disconnected without Save Data Pointers\n",
1095 1.23 chopps sc->sc_dev.dv_xname, 1 << target);
1096 1.23 chopps #endif
1097 1.23 chopps for (i = 0; i < DMAMAXIO; ++i) {
1098 1.23 chopps if (acb->ds.chain[i].datalen == 0)
1099 1.23 chopps break;
1100 1.23 chopps if (acb->iob_curbuf >= (long)acb->ds.chain[i].databuf &&
1101 1.23 chopps acb->iob_curbuf < (long)(acb->ds.chain[i].databuf +
1102 1.23 chopps acb->ds.chain[i].datalen))
1103 1.23 chopps break;
1104 1.23 chopps }
1105 1.23 chopps if (i >= DMAMAXIO || acb->ds.chain[i].datalen == 0)
1106 1.23 chopps printf("couldn't find saved data pointer\n");
1107 1.23 chopps #ifdef DEBUG
1108 1.23 chopps if (siop_debug & 0x100)
1109 1.23 chopps printf(" chain[0]: %x/%x -> %x/%x\n",
1110 1.23 chopps acb->ds.chain[0].databuf,
1111 1.23 chopps acb->ds.chain[0].datalen,
1112 1.23 chopps acb->iob_curbuf,
1113 1.23 chopps acb->iob_curlen);
1114 1.23 chopps #endif
1115 1.23 chopps acb->ds.chain[0].databuf = (char *)acb->iob_curbuf;
1116 1.23 chopps acb->ds.chain[0].datalen = acb->iob_curlen;
1117 1.23 chopps for (j = 1, ++i; i < DMAMAXIO && acb->ds.chain[i].datalen; ++i, ++j) {
1118 1.18 chopps #ifdef DEBUG
1119 1.23 chopps if (siop_debug & 0x100)
1120 1.23 chopps printf(" chain[%d]: %x/%x -> %x/%x\n", j,
1121 1.23 chopps acb->ds.chain[j].databuf,
1122 1.23 chopps acb->ds.chain[j].datalen,
1123 1.23 chopps acb->ds.chain[i].databuf,
1124 1.23 chopps acb->ds.chain[i].datalen);
1125 1.8 chopps #endif
1126 1.23 chopps acb->ds.chain[j].databuf = acb->ds.chain[i].databuf;
1127 1.23 chopps acb->ds.chain[j].datalen = acb->ds.chain[i].datalen;
1128 1.18 chopps }
1129 1.23 chopps if (j < DMAMAXIO)
1130 1.23 chopps acb->ds.chain[j].datalen = 0;
1131 1.23 chopps DCIAS(kvtop(&acb->ds.chain));
1132 1.18 chopps }
1133 1.23 chopps ++sc->sc_tinfo[target].dconns;
1134 1.23 chopps /*
1135 1.23 chopps * add nexus to waiting list
1136 1.23 chopps * clear nexus
1137 1.23 chopps * try to start another command for another target/lun
1138 1.23 chopps */
1139 1.23 chopps acb->status = sc->sc_flags & SIOP_INTSOFF;
1140 1.23 chopps TAILQ_INSERT_HEAD(&sc->nexus_list, acb, chain);
1141 1.23 chopps sc->sc_nexus = NULL; /* no current device */
1142 1.23 chopps /* start script to wait for reselect */
1143 1.23 chopps if (sc->sc_nexus == NULL)
1144 1.23 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1145 1.23 chopps /* XXXX start another command ? */
1146 1.23 chopps if (sc->ready_list.tqh_first)
1147 1.23 chopps siop_sched(sc);
1148 1.18 chopps return (0);
1149 1.18 chopps }
1150 1.23 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff03) {
1151 1.23 chopps int reselid = rp->siop_scratch & 0x7f;
1152 1.23 chopps int reselun = rp->siop_sfbr & 0x07;
1153 1.23 chopps
1154 1.23 chopps sc->sc_sstat1 = rp->siop_sbcl; /* XXXX save current SBCL */
1155 1.18 chopps #ifdef DEBUG
1156 1.18 chopps if (siop_debug & 0x100)
1157 1.23 chopps printf ("%s: target ID %02x reselected dsps %x\n",
1158 1.23 chopps sc->sc_dev.dv_xname, reselid,
1159 1.20 chopps rp->siop_dsps);
1160 1.23 chopps if ((rp->siop_sfbr & 0x80) == 0)
1161 1.23 chopps printf("%s: Reselect message in was not identify: %x\n",
1162 1.23 chopps sc->sc_dev.dv_xname, rp->siop_sfbr);
1163 1.18 chopps #endif
1164 1.23 chopps if (sc->sc_nexus) {
1165 1.23 chopps #ifdef DEBUG
1166 1.23 chopps if (siop_debug & 0x100)
1167 1.23 chopps printf ("%s: reselect ID %02x w/active\n",
1168 1.23 chopps sc->sc_dev.dv_xname, reselid);
1169 1.23 chopps #endif
1170 1.23 chopps TAILQ_INSERT_HEAD(&sc->ready_list, sc->sc_nexus, chain);
1171 1.23 chopps sc->sc_tinfo[sc->sc_nexus->xs->sc_link->target].lubusy
1172 1.23 chopps &= ~(1 << sc->sc_nexus->xs->sc_link->lun);
1173 1.23 chopps --sc->sc_active;
1174 1.18 chopps }
1175 1.18 chopps /*
1176 1.23 chopps * locate acb of reselecting device
1177 1.23 chopps * set sc->sc_nexus to acb
1178 1.18 chopps */
1179 1.23 chopps for (acb = sc->nexus_list.tqh_first; acb;
1180 1.23 chopps acb = acb->chain.tqe_next) {
1181 1.23 chopps if (reselid != (acb->ds.scsi_addr >> 16) ||
1182 1.23 chopps reselun != (acb->msgout[0] & 0x07))
1183 1.18 chopps continue;
1184 1.23 chopps TAILQ_REMOVE(&sc->nexus_list, acb, chain);
1185 1.23 chopps sc->sc_nexus = acb;
1186 1.23 chopps sc->sc_flags |= acb->status;
1187 1.23 chopps acb->status = 0;
1188 1.23 chopps DCIAS(kvtop(&acb->stat[0]));
1189 1.23 chopps rp->siop_dsa = kvtop(&acb->ds);
1190 1.23 chopps rp->siop_sxfer = sc->sc_sync[acb->xs->sc_link->target].period;
1191 1.23 chopps rp->siop_sbcl = sc->sc_sync[acb->xs->sc_link->target].offset;
1192 1.23 chopps break;
1193 1.23 chopps }
1194 1.23 chopps if (acb == NULL) {
1195 1.23 chopps printf("%s: target ID %02x reselect nexus_list %x\n",
1196 1.23 chopps sc->sc_dev.dv_xname, reselid,
1197 1.23 chopps sc->nexus_list.tqh_first);
1198 1.23 chopps panic("unable to find reselecting device");
1199 1.18 chopps }
1200 1.23 chopps dma_cachectl (acb, sizeof(*acb));
1201 1.23 chopps rp->siop_temp = 0;
1202 1.20 chopps rp->siop_dcntl |= SIOP_DCNTL_STD;
1203 1.18 chopps return (0);
1204 1.18 chopps }
1205 1.23 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff04) {
1206 1.23 chopps /* reselect was interrupted (by Sig_P or select) */
1207 1.18 chopps #ifdef DEBUG
1208 1.23 chopps if (siop_debug & 0x100 ||
1209 1.23 chopps (rp->siop_ctest2 & SIOP_CTEST2_SIGP) == 0)
1210 1.18 chopps printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x\n",
1211 1.20 chopps sc->sc_dev.dv_xname, rp->siop_scntl1, rp->siop_ctest2, rp->siop_sfbr);
1212 1.18 chopps #endif
1213 1.23 chopps /* XXX assume it was not select */
1214 1.23 chopps target = sc->sc_nexus->xs->sc_link->target;
1215 1.23 chopps rp->siop_temp = 0;
1216 1.23 chopps rp->siop_dsa = kvtop(&sc->sc_nexus->ds);
1217 1.23 chopps rp->siop_sxfer = sc->sc_sync[target].period;
1218 1.20 chopps rp->siop_sbcl = sc->sc_sync[target].offset;
1219 1.23 chopps rp->siop_dsp = sc->sc_scriptspa;
1220 1.23 chopps return (0);
1221 1.23 chopps }
1222 1.23 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff06) {
1223 1.23 chopps if (acb == NULL)
1224 1.23 chopps printf("%s: Bad message-in with no active command?\n",
1225 1.23 chopps sc->sc_dev.dv_xname);
1226 1.23 chopps /* Unrecognized message in byte */
1227 1.23 chopps dma_cachectl (&acb->msg[1],1);
1228 1.23 chopps printf ("%s: Unrecognized message in data sfbr %x msg %x sbcl %x\n",
1229 1.23 chopps sc->sc_dev.dv_xname, rp->siop_sfbr, acb->msg[1], rp->siop_sbcl);
1230 1.23 chopps /* what should be done here? */
1231 1.23 chopps DCIAS(kvtop(&acb->msg[1]));
1232 1.23 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
1233 1.18 chopps return (0);
1234 1.8 chopps }
1235 1.23 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0a) {
1236 1.23 chopps /* Status phase wasn't followed by message in phase? */
1237 1.23 chopps printf ("%s: Status phase not followed by message in phase? sbcl %x sbdl %x\n",
1238 1.23 chopps sc->sc_dev.dv_xname, rp->siop_sbcl, rp->siop_sbdl);
1239 1.23 chopps if (rp->siop_sbcl == 0xa7) {
1240 1.23 chopps /* It is now, just continue the script? */
1241 1.23 chopps rp->siop_dcntl |= SIOP_DCNTL_STD;
1242 1.23 chopps return (0);
1243 1.23 chopps }
1244 1.23 chopps }
1245 1.1 mw if (sstat0 == 0 && dstat & SIOP_DSTAT_SIR) {
1246 1.23 chopps dma_cachectl (&acb->stat[0], 1);
1247 1.23 chopps dma_cachectl (&acb->msg[0], 1);
1248 1.23 chopps printf ("SIOP interrupt: %x sts %x msg %x %x sbcl %x\n",
1249 1.23 chopps rp->siop_dsps, acb->stat[0], acb->msg[0], acb->msg[1],
1250 1.20 chopps rp->siop_sbcl);
1251 1.20 chopps siopreset (sc);
1252 1.1 mw *status = -1;
1253 1.23 chopps return 0; /* siopreset has cleaned up */
1254 1.1 mw }
1255 1.15 chopps if (sstat0 & SIOP_SSTAT0_SGE)
1256 1.15 chopps printf ("SIOP: SCSI Gross Error\n");
1257 1.15 chopps if (sstat0 & SIOP_SSTAT0_PAR)
1258 1.15 chopps printf ("SIOP: Parity Error\n");
1259 1.18 chopps if (dstat & SIOP_DSTAT_IID)
1260 1.18 chopps printf ("SIOP: Invalid instruction detected\n");
1261 1.1 mw bad_phase:
1262 1.15 chopps /*
1263 1.15 chopps * temporary panic for unhandled conditions
1264 1.15 chopps * displays various things about the 53C710 status and registers
1265 1.15 chopps * then panics.
1266 1.15 chopps * XXXX need to clean this up to print out the info, reset, and continue
1267 1.15 chopps */
1268 1.23 chopps printf ("siopchkintr: target %x ds %x\n", target, &acb->ds);
1269 1.20 chopps printf ("scripts %x ds %x rp %x dsp %x dcmd %x\n", sc->sc_scriptspa,
1270 1.23 chopps kvtop(&acb->ds), kvtop(rp), rp->siop_dsp,
1271 1.20 chopps *((long *)&rp->siop_dcmd));
1272 1.23 chopps printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x dsa %x sbcl %x sts %x msg %x %x sfbr %x\n",
1273 1.20 chopps istat, dstat, sstat0, rp->siop_dsps, rp->siop_dsa,
1274 1.23 chopps rp->siop_sbcl, acb->stat[0], acb->msg[0], acb->msg[1], rp->siop_sfbr);
1275 1.15 chopps #ifdef DEBUG
1276 1.15 chopps if (siop_debug & 0x20)
1277 1.15 chopps panic("siopchkintr: **** temp ****");
1278 1.15 chopps #endif
1279 1.23 chopps #ifdef DDB
1280 1.23 chopps Debugger ();
1281 1.23 chopps #endif
1282 1.20 chopps siopreset (sc); /* hard reset */
1283 1.15 chopps *status = -1;
1284 1.23 chopps return 0; /* siopreset cleaned up */
1285 1.1 mw }
1286 1.1 mw
1287 1.23 chopps void
1288 1.23 chopps siop_select(sc)
1289 1.20 chopps struct siop_softc *sc;
1290 1.1 mw {
1291 1.23 chopps siop_regmap_p rp;
1292 1.23 chopps struct siop_acb *acb = sc->sc_nexus;
1293 1.1 mw
1294 1.1 mw #ifdef DEBUG
1295 1.1 mw if (siop_debug & 1)
1296 1.23 chopps printf ("%s: select ", sc->sc_dev.dv_xname);
1297 1.1 mw #endif
1298 1.1 mw
1299 1.23 chopps rp = sc->sc_siopp;
1300 1.23 chopps if (acb->xs->flags & SCSI_POLL || siop_no_dma) {
1301 1.23 chopps sc->sc_flags |= SIOP_INTSOFF;
1302 1.23 chopps sc->sc_flags &= ~SIOP_INTDEFER;
1303 1.23 chopps if ((rp->siop_istat & 0x08) == 0) {
1304 1.23 chopps rp->siop_sien = 0;
1305 1.23 chopps rp->siop_dien = 0;
1306 1.1 mw }
1307 1.23 chopps #if 0
1308 1.23 chopps } else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
1309 1.23 chopps sc->sc_flags &= ~SIOP_INTSOFF;
1310 1.23 chopps if ((rp->siop_istat & 0x08) == 0) {
1311 1.23 chopps rp->siop_sien = sc->sc_sien;
1312 1.23 chopps rp->siop_dien = sc->sc_dien;
1313 1.1 mw }
1314 1.1 mw #endif
1315 1.1 mw }
1316 1.1 mw #ifdef DEBUG
1317 1.1 mw if (siop_debug & 1)
1318 1.23 chopps printf ("siop_select: target %x cmd %02x ds %x\n",
1319 1.23 chopps acb->xs->sc_link->target, acb->cmd.opcode,
1320 1.23 chopps &sc->sc_nexus->ds);
1321 1.8 chopps #endif
1322 1.1 mw
1323 1.23 chopps siop_start(sc, acb->xs->sc_link->target, acb->xs->sc_link->lun,
1324 1.23 chopps &acb->cmd, acb->clen, acb->daddr, acb->dleft);
1325 1.1 mw
1326 1.23 chopps return;
1327 1.1 mw }
1328 1.1 mw
1329 1.1 mw /*
1330 1.23 chopps * 53C710 interrupt handler
1331 1.1 mw */
1332 1.1 mw
1333 1.1 mw int
1334 1.20 chopps siopintr (sc)
1335 1.20 chopps register struct siop_softc *sc;
1336 1.1 mw {
1337 1.20 chopps siop_regmap_p rp;
1338 1.1 mw register u_char istat, dstat, sstat0;
1339 1.1 mw int status;
1340 1.23 chopps int s = splbio();
1341 1.1 mw
1342 1.20 chopps istat = sc->sc_istat;
1343 1.23 chopps if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
1344 1.23 chopps splx(s);
1345 1.8 chopps return;
1346 1.23 chopps }
1347 1.23 chopps
1348 1.18 chopps /* Got a valid interrupt on this device */
1349 1.23 chopps rp = sc->sc_siopp;
1350 1.20 chopps dstat = sc->sc_dstat;
1351 1.20 chopps sstat0 = sc->sc_sstat0;
1352 1.23 chopps if (dstat & SIOP_DSTAT_SIR)
1353 1.23 chopps sc->sc_intcode = rp->siop_dsps;
1354 1.20 chopps sc->sc_istat = 0;
1355 1.1 mw #ifdef DEBUG
1356 1.8 chopps if (siop_debug & 1)
1357 1.8 chopps printf ("%s: intr istat %x dstat %x sstat0 %x\n",
1358 1.20 chopps sc->sc_dev.dv_xname, istat, dstat, sstat0);
1359 1.20 chopps if (!sc->sc_active) {
1360 1.18 chopps printf ("%s: spurious interrupt? istat %x dstat %x sstat0 %x status %x\n",
1361 1.23 chopps sc->sc_dev.dv_xname, istat, dstat, sstat0, sc->sc_nexus->stat[0]);
1362 1.8 chopps }
1363 1.1 mw #endif
1364 1.1 mw
1365 1.1 mw #ifdef DEBUG
1366 1.8 chopps if (siop_debug & 5) {
1367 1.23 chopps DCIAS(kvtop(&sc->sc_nexus->stat[0]));
1368 1.20 chopps printf ("%s: intr istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
1369 1.20 chopps sc->sc_dev.dv_xname, istat, dstat, sstat0,
1370 1.20 chopps rp->siop_dsps, rp->siop_sbcl,
1371 1.23 chopps sc->sc_nexus->stat[0], sc->sc_nexus->msg[0]);
1372 1.8 chopps }
1373 1.1 mw #endif
1374 1.23 chopps if (sc->sc_flags & SIOP_INTDEFER) {
1375 1.23 chopps sc->sc_flags &= ~(SIOP_INTDEFER | SIOP_INTSOFF);
1376 1.23 chopps rp->siop_sien = sc->sc_sien;
1377 1.23 chopps rp->siop_dien = sc->sc_dien;
1378 1.23 chopps }
1379 1.20 chopps if (siop_checkintr (sc, istat, dstat, sstat0, &status)) {
1380 1.1 mw #if 1
1381 1.8 chopps if (status == 0xff)
1382 1.8 chopps printf ("siopintr: status == 0xff\n");
1383 1.8 chopps #endif
1384 1.23 chopps if ((sc->sc_flags & (SIOP_INTSOFF | SIOP_INTDEFER)) != SIOP_INTSOFF) {
1385 1.23 chopps #if 0
1386 1.23 chopps if (rp->siop_sbcl & SIOP_BSY) {
1387 1.23 chopps printf ("%s: SCSI bus busy at completion",
1388 1.20 chopps sc->sc_dev.dv_xname);
1389 1.23 chopps printf(" targ %d sbcl %02x sfbr %x lcrc %02x dsp +%x\n",
1390 1.23 chopps sc->sc_nexus->xs->sc_link->target,
1391 1.23 chopps rp->siop_sbcl, rp->siop_sfbr, rp->siop_lcrc,
1392 1.23 chopps rp->siop_dsp - sc->sc_scriptspa);
1393 1.23 chopps }
1394 1.23 chopps #endif
1395 1.23 chopps siop_scsidone(sc->sc_nexus, sc->sc_nexus->stat[0]);
1396 1.18 chopps }
1397 1.1 mw }
1398 1.23 chopps splx(s);
1399 1.1 mw }
1400 1.1 mw
1401 1.18 chopps /*
1402 1.23 chopps * This is based on the Progressive Peripherals 33Mhz Zeus driver and will
1403 1.18 chopps * not be correct for other 53c710 boards.
1404 1.18 chopps *
1405 1.18 chopps */
1406 1.20 chopps scsi_period_to_siop (sc, target)
1407 1.20 chopps struct siop_softc *sc;
1408 1.1 mw {
1409 1.8 chopps int period, offset, i, sxfer;
1410 1.1 mw
1411 1.23 chopps period = sc->sc_nexus->msg[4];
1412 1.23 chopps offset = sc->sc_nexus->msg[5];
1413 1.8 chopps sxfer = 0;
1414 1.8 chopps if (offset <= SIOP_MAX_OFFSET)
1415 1.8 chopps sxfer = offset;
1416 1.8 chopps for (i = 0; i < sizeof (xxx) / 2; ++i) {
1417 1.8 chopps if (period <= xxx[i].x) {
1418 1.8 chopps sxfer |= xxx[i].y & 0x70;
1419 1.8 chopps offset = xxx[i].y & 0x03;
1420 1.8 chopps break;
1421 1.8 chopps }
1422 1.8 chopps }
1423 1.20 chopps sc->sc_sync[target].period = sxfer;
1424 1.20 chopps sc->sc_sync[target].offset = offset;
1425 1.1 mw #ifdef DEBUG
1426 1.8 chopps printf ("sync: siop_sxfr %02x, siop_sbcl %02x\n", sxfer, offset);
1427 1.1 mw #endif
1428 1.1 mw }
1429