siop2.c revision 1.4 1 1.4 is /* $NetBSD: siop2.c,v 1.4 1999/03/13 22:43:30 is Exp $ */
2 1.1 is
3 1.1 is /*
4 1.1 is * Copyright (c) 1994,1998 Michael L. Hitch
5 1.1 is * Copyright (c) 1990 The Regents of the University of California.
6 1.1 is * All rights reserved.
7 1.1 is *
8 1.1 is * This code is derived from software contributed to Berkeley by
9 1.1 is * Van Jacobson of Lawrence Berkeley Laboratory.
10 1.1 is *
11 1.1 is * Redistribution and use in source and binary forms, with or without
12 1.1 is * modification, are permitted provided that the following conditions
13 1.1 is * are met:
14 1.1 is * 1. Redistributions of source code must retain the above copyright
15 1.1 is * notice, this list of conditions and the following disclaimer.
16 1.1 is * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 is * notice, this list of conditions and the following disclaimer in the
18 1.1 is * documentation and/or other materials provided with the distribution.
19 1.1 is * 3. All advertising materials mentioning features or use of this software
20 1.1 is * must display the following acknowledgement:
21 1.1 is * This product includes software developed by the University of
22 1.1 is * California, Berkeley and its contributors.
23 1.1 is * 4. Neither the name of the University nor the names of its contributors
24 1.1 is * may be used to endorse or promote products derived from this software
25 1.1 is * without specific prior written permission.
26 1.1 is *
27 1.1 is * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 is * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 is * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 is * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 is * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 is * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 is * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 is * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 is * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 is * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 is * SUCH DAMAGE.
38 1.1 is *
39 1.1 is * @(#)siop.c 7.5 (Berkeley) 5/4/91
40 1.1 is */
41 1.1 is
42 1.1 is /*
43 1.1 is * AMIGA 53C720/770 scsi adaptor driver
44 1.1 is */
45 1.1 is
46 1.1 is #include "opt_ddb.h"
47 1.1 is
48 1.1 is #include <sys/param.h>
49 1.1 is #include <sys/systm.h>
50 1.1 is #include <sys/device.h>
51 1.1 is #include <sys/disklabel.h>
52 1.1 is #include <sys/dkstat.h>
53 1.1 is #include <sys/buf.h>
54 1.1 is #include <sys/malloc.h>
55 1.1 is #include <dev/scsipi/scsi_all.h>
56 1.1 is #include <dev/scsipi/scsipi_all.h>
57 1.1 is #include <dev/scsipi/scsiconf.h>
58 1.1 is #include <machine/cpu.h>
59 1.1 is #include <amiga/amiga/custom.h>
60 1.1 is #include <amiga/amiga/isr.h>
61 1.1 is
62 1.1 is #define ARCH_720
63 1.1 is
64 1.1 is #include <amiga/dev/siopreg.h>
65 1.1 is #include <amiga/dev/siopvar.h>
66 1.1 is
67 1.1 is /*
68 1.1 is * SCSI delays
69 1.1 is * In u-seconds, primarily for state changes on the SPC.
70 1.1 is */
71 1.1 is #define SCSI_CMD_WAIT 500000 /* wait per step of 'immediate' cmds */
72 1.1 is #define SCSI_DATA_WAIT 500000 /* wait per data in/out step */
73 1.1 is #define SCSI_INIT_WAIT 500000 /* wait per step (both) during init */
74 1.1 is
75 1.1 is void siopng_select __P((struct siop_softc *));
76 1.1 is void siopngabort __P((struct siop_softc *, siop_regmap_p, char *));
77 1.1 is void siopngerror __P((struct siop_softc *, siop_regmap_p, u_char));
78 1.1 is void siopngstart __P((struct siop_softc *));
79 1.1 is int siopng_checkintr __P((struct siop_softc *, u_char, u_char, u_short, int *));
80 1.1 is void siopngreset __P((struct siop_softc *));
81 1.1 is void siopngsetdelay __P((int));
82 1.1 is void siopng_scsidone __P((struct siop_acb *, int));
83 1.1 is void siopng_sched __P((struct siop_softc *));
84 1.1 is int siopng_poll __P((struct siop_softc *, struct siop_acb *));
85 1.1 is void siopngintr __P((struct siop_softc *));
86 1.1 is void scsi_period_to_siopng __P((struct siop_softc *, int));
87 1.1 is void siopng_start __P((struct siop_softc *, int, int, u_char *, int, u_char *, int));
88 1.1 is void siopng_dump_acb __P((struct siop_acb *));
89 1.1 is
90 1.1 is /* 53C720/770 script */
91 1.1 is const
92 1.1 is #include <amiga/dev/siop2_script.out>
93 1.1 is
94 1.1 is /* default to not inhibit sync negotiation on any drive */
95 1.1 is u_char siopng_inhibit_sync[16] = { 0, 0, 0, 0, 0, 0, 0 }; /* initialize, so patchable */
96 1.1 is u_char siopng_allow_disc[16] = {3, 3, 3, 3, 3, 3, 3, 3};
97 1.1 is int siopng_no_dma = 0;
98 1.1 is
99 1.1 is int siopng_reset_delay = 250; /* delay after reset, in milleseconds */
100 1.1 is
101 1.1 is int siopng_cmd_wait = SCSI_CMD_WAIT;
102 1.1 is int siopng_data_wait = SCSI_DATA_WAIT;
103 1.1 is int siopng_init_wait = SCSI_INIT_WAIT;
104 1.1 is
105 1.1 is #define DEBUG_SYNC
106 1.1 is
107 1.1 is #ifdef DEBUG_SYNC
108 1.1 is /*
109 1.1 is * sync period transfer lookup - only valid for 66Mhz clock
110 1.1 is */
111 1.1 is #ifdef FIXME
112 1.1 is static struct {
113 1.1 is unsigned char p; /* period from sync request message */
114 1.1 is unsigned char r; /* siop_period << 4 | sbcl */
115 1.1 is } sync_tab[] = {
116 1.1 is { 60/4, 0<<4 | 1},
117 1.1 is { 76/4, 1<<4 | 1},
118 1.1 is { 92/4, 2<<4 | 1},
119 1.1 is { 92/4, 0<<4 | 2},
120 1.1 is {108/4, 3<<4 | 1},
121 1.1 is {116/4, 1<<4 | 2},
122 1.1 is {120/4, 4<<4 | 1},
123 1.1 is {120/4, 0<<4 | 3},
124 1.1 is {136/4, 5<<4 | 1},
125 1.1 is {140/4, 2<<4 | 2},
126 1.1 is {152/4, 6<<4 | 1},
127 1.1 is {152/4, 1<<4 | 3},
128 1.1 is {164/4, 3<<4 | 2},
129 1.1 is {168/4, 7<<4 | 1},
130 1.1 is {180/4, 2<<4 | 3},
131 1.1 is {184/4, 4<<4 | 2},
132 1.1 is {208/4, 5<<4 | 2},
133 1.1 is {212/4, 3<<4 | 3},
134 1.1 is {232/4, 6<<4 | 2},
135 1.1 is {240/4, 4<<4 | 3},
136 1.1 is {256/4, 7<<4 | 2},
137 1.1 is {272/4, 5<<4 | 3},
138 1.1 is {300/4, 6<<4 | 3},
139 1.1 is {332/4, 7<<4 | 3}
140 1.1 is };
141 1.1 is #endif
142 1.1 is #endif
143 1.1 is
144 1.1 is #ifdef DEBUG
145 1.1 is /*
146 1.1 is * 0x01 - full debug
147 1.1 is * 0x02 - DMA chaining
148 1.1 is * 0x04 - siopngintr
149 1.1 is * 0x08 - phase mismatch
150 1.1 is * 0x10 - <not used>
151 1.1 is * 0x20 - panic on unhandled exceptions
152 1.1 is * 0x100 - disconnect/reselect
153 1.1 is */
154 1.1 is int siopng_debug = 0;
155 1.1 is int siopngsync_debug = 0;
156 1.1 is int siopngdma_hits = 0;
157 1.1 is int siopngdma_misses = 0;
158 1.1 is int siopngchain_ints = 0;
159 1.1 is int siopngstarts = 0;
160 1.1 is int siopngints = 0;
161 1.1 is int siopngphmm = 0;
162 1.1 is #define SIOP_TRACE_SIZE 128
163 1.1 is #define SIOP_TRACE(a,b,c,d) \
164 1.1 is siopng_trbuf[siopng_trix] = (a); \
165 1.1 is siopng_trbuf[siopng_trix+1] = (b); \
166 1.1 is siopng_trbuf[siopng_trix+2] = (c); \
167 1.1 is siopng_trbuf[siopng_trix+3] = (d); \
168 1.1 is siopng_trix = (siopng_trix + 4) & (SIOP_TRACE_SIZE - 1);
169 1.1 is u_char siopng_trbuf[SIOP_TRACE_SIZE];
170 1.1 is int siopng_trix;
171 1.1 is void siopng_dump __P((struct siop_softc *));
172 1.1 is void siopng_dump_trace __P((void));
173 1.1 is #else
174 1.1 is #define SIOP_TRACE(a,b,c,d)
175 1.1 is #endif
176 1.1 is
177 1.1 is
178 1.4 is static char *siopng_chips[] = {
179 1.4 is "720", "720SE", "770", "0x3",
180 1.4 is "0x4", "0x5", "0x6", "0x7",
181 1.4 is "0x8", "0x9", "0xA", "0xB",
182 1.4 is "0xC", "0xD", "0xE", "0xF",
183 1.4 is };
184 1.4 is
185 1.1 is /*
186 1.1 is * default minphys routine for siopng based controllers
187 1.1 is */
188 1.1 is void
189 1.1 is siopng_minphys(bp)
190 1.1 is struct buf *bp;
191 1.1 is {
192 1.1 is
193 1.1 is /*
194 1.1 is * No max transfer at this level.
195 1.1 is */
196 1.1 is minphys(bp);
197 1.1 is }
198 1.1 is
199 1.1 is /*
200 1.1 is * used by specific siopng controller
201 1.1 is *
202 1.1 is */
203 1.1 is int
204 1.1 is siopng_scsicmd(xs)
205 1.1 is struct scsipi_xfer *xs;
206 1.1 is {
207 1.1 is struct siop_acb *acb;
208 1.1 is struct siop_softc *sc;
209 1.1 is struct scsipi_link *slp;
210 1.1 is int flags, s;
211 1.1 is
212 1.1 is slp = xs->sc_link;
213 1.1 is sc = slp->adapter_softc;
214 1.1 is flags = xs->flags;
215 1.1 is
216 1.1 is /* XXXX ?? */
217 1.1 is if (flags & SCSI_DATA_UIO)
218 1.1 is panic("siopng: scsi data uio requested");
219 1.1 is
220 1.1 is /* XXXX ?? */
221 1.1 is if (sc->sc_nexus && flags & SCSI_POLL)
222 1.1 is /* panic("siopng_scsicmd: busy");*/
223 1.1 is printf("siopng_scsicmd: busy\n");
224 1.1 is
225 1.1 is s = splbio();
226 1.1 is acb = sc->free_list.tqh_first;
227 1.1 is if (acb) {
228 1.1 is TAILQ_REMOVE(&sc->free_list, acb, chain);
229 1.1 is }
230 1.1 is splx(s);
231 1.1 is
232 1.1 is if (acb == NULL) {
233 1.1 is xs->error = XS_DRIVER_STUFFUP;
234 1.1 is return(TRY_AGAIN_LATER);
235 1.1 is }
236 1.1 is
237 1.1 is acb->flags = ACB_ACTIVE;
238 1.1 is acb->xs = xs;
239 1.1 is bcopy(xs->cmd, &acb->cmd, xs->cmdlen);
240 1.1 is acb->clen = xs->cmdlen;
241 1.1 is acb->daddr = xs->data;
242 1.1 is acb->dleft = xs->datalen;
243 1.1 is
244 1.1 is s = splbio();
245 1.1 is TAILQ_INSERT_TAIL(&sc->ready_list, acb, chain);
246 1.1 is
247 1.1 is if (sc->sc_nexus == NULL)
248 1.1 is siopng_sched(sc);
249 1.1 is
250 1.1 is splx(s);
251 1.1 is
252 1.1 is if (flags & SCSI_POLL || siopng_no_dma)
253 1.1 is return(siopng_poll(sc, acb));
254 1.1 is return(SUCCESSFULLY_QUEUED);
255 1.1 is }
256 1.1 is
257 1.1 is int
258 1.1 is siopng_poll(sc, acb)
259 1.1 is struct siop_softc *sc;
260 1.1 is struct siop_acb *acb;
261 1.1 is {
262 1.1 is siop_regmap_p rp = sc->sc_siopp;
263 1.1 is struct scsipi_xfer *xs = acb->xs;
264 1.1 is int i;
265 1.1 is int status;
266 1.1 is u_char istat;
267 1.1 is u_char dstat;
268 1.1 is u_short sist;
269 1.1 is int s;
270 1.1 is int to;
271 1.1 is
272 1.1 is s = splbio();
273 1.1 is to = xs->timeout / 1000;
274 1.1 is if (sc->nexus_list.tqh_first)
275 1.1 is printf("%s: siopng_poll called with disconnected device\n",
276 1.1 is sc->sc_dev.dv_xname);
277 1.1 is for (;;) {
278 1.1 is /* use cmd_wait values? */
279 1.1 is i = 50000;
280 1.1 is /* XXX spl0(); */
281 1.1 is while (((istat = rp->siop_istat) &
282 1.1 is (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
283 1.1 is if (--i <= 0) {
284 1.1 is #ifdef DEBUG
285 1.1 is printf ("waiting: tgt %d cmd %02x sbcl %02x istat %02x sbdl %04x\n dsp %lx (+%lx) dcmd %lx ds %p timeout %d\n",
286 1.1 is xs->sc_link->scsipi_scsi.target, acb->cmd.opcode,
287 1.1 is rp->siop_sbcl, istat, rp->siop_sbdl, rp->siop_dsp,
288 1.1 is rp->siop_dsp - sc->sc_scriptspa,
289 1.1 is *((long *)&rp->siop_dcmd), &acb->ds, acb->xs->timeout);
290 1.1 is #endif
291 1.1 is i = 50000;
292 1.1 is --to;
293 1.1 is if (to <= 0) {
294 1.1 is siopngreset(sc);
295 1.1 is return(COMPLETE);
296 1.1 is }
297 1.1 is }
298 1.1 is delay(20);
299 1.1 is }
300 1.1 is sist = rp->siop_sist;
301 1.1 is dstat = rp->siop_dstat;
302 1.1 is if (siopng_checkintr(sc, istat, dstat, sist, &status)) {
303 1.1 is if (acb != sc->sc_nexus)
304 1.1 is printf("%s: siopng_poll disconnected device completed\n",
305 1.1 is sc->sc_dev.dv_xname);
306 1.1 is else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
307 1.1 is sc->sc_flags &= ~SIOP_INTSOFF;
308 1.1 is rp->siop_sien = sc->sc_sien;
309 1.1 is rp->siop_dien = sc->sc_dien;
310 1.1 is }
311 1.1 is siopng_scsidone(sc->sc_nexus, status);
312 1.1 is }
313 1.1 is if (xs->flags & ITSDONE)
314 1.1 is break;
315 1.1 is }
316 1.1 is splx(s);
317 1.1 is return (COMPLETE);
318 1.1 is }
319 1.1 is
320 1.1 is /*
321 1.1 is * start next command that's ready
322 1.1 is */
323 1.1 is void
324 1.1 is siopng_sched(sc)
325 1.1 is struct siop_softc *sc;
326 1.1 is {
327 1.1 is struct scsipi_link *slp;
328 1.1 is struct siop_acb *acb;
329 1.1 is int i;
330 1.1 is
331 1.1 is #ifdef DEBUG
332 1.1 is if (sc->sc_nexus) {
333 1.1 is printf("%s: siopng_sched- nexus %p/%d ready %p/%d\n",
334 1.1 is sc->sc_dev.dv_xname, sc->sc_nexus,
335 1.1 is sc->sc_nexus->xs->sc_link->scsipi_scsi.target,
336 1.1 is sc->ready_list.tqh_first,
337 1.1 is sc->ready_list.tqh_first->xs->sc_link->scsipi_scsi.target);
338 1.1 is return;
339 1.1 is }
340 1.1 is #endif
341 1.1 is for (acb = sc->ready_list.tqh_first; acb; acb = acb->chain.tqe_next) {
342 1.1 is slp = acb->xs->sc_link;
343 1.1 is i = slp->scsipi_scsi.target;
344 1.1 is if(!(sc->sc_tinfo[i].lubusy & (1 << slp->scsipi_scsi.lun))) {
345 1.1 is struct siop_tinfo *ti = &sc->sc_tinfo[i];
346 1.1 is
347 1.1 is TAILQ_REMOVE(&sc->ready_list, acb, chain);
348 1.1 is sc->sc_nexus = acb;
349 1.1 is slp = acb->xs->sc_link;
350 1.1 is ti = &sc->sc_tinfo[slp->scsipi_scsi.target];
351 1.1 is ti->lubusy |= (1 << slp->scsipi_scsi.lun);
352 1.1 is break;
353 1.1 is }
354 1.1 is }
355 1.1 is
356 1.1 is if (acb == NULL) {
357 1.1 is #ifdef DEBUGXXX
358 1.1 is printf("%s: siopng_sched didn't find ready command\n",
359 1.1 is sc->sc_dev.dv_xname);
360 1.1 is #endif
361 1.1 is return;
362 1.1 is }
363 1.1 is
364 1.1 is if (acb->xs->flags & SCSI_RESET)
365 1.1 is siopngreset(sc);
366 1.1 is
367 1.1 is #if 0
368 1.1 is acb->cmd.bytes[0] |= slp->scsipi_scsi.lun << 5; /* XXXX */
369 1.1 is #endif
370 1.1 is ++sc->sc_active;
371 1.1 is siopng_select(sc);
372 1.1 is }
373 1.1 is
374 1.1 is void
375 1.1 is siopng_scsidone(acb, stat)
376 1.1 is struct siop_acb *acb;
377 1.1 is int stat;
378 1.1 is {
379 1.1 is struct scsipi_xfer *xs;
380 1.1 is struct scsipi_link *slp;
381 1.1 is struct siop_softc *sc;
382 1.1 is int dosched = 0;
383 1.1 is
384 1.1 is if (acb == NULL || (xs = acb->xs) == NULL) {
385 1.1 is #ifdef DIAGNOSTIC
386 1.1 is printf("siopng_scsidone: NULL acb or scsipi_xfer\n");
387 1.1 is #if defined(DEBUG) && defined(DDB)
388 1.1 is Debugger();
389 1.1 is #endif
390 1.1 is #endif
391 1.1 is return;
392 1.1 is }
393 1.1 is slp = xs->sc_link;
394 1.1 is sc = slp->adapter_softc;
395 1.1 is /*
396 1.1 is * is this right?
397 1.1 is */
398 1.1 is xs->status = stat;
399 1.1 is
400 1.1 is if (xs->error == XS_NOERROR && !(acb->flags & ACB_CHKSENSE)) {
401 1.1 is if (stat == SCSI_CHECK) {
402 1.1 is struct scsipi_sense *ss = (void *)&acb->cmd;
403 1.1 is bzero(ss, sizeof(*ss));
404 1.1 is ss->opcode = REQUEST_SENSE;
405 1.1 is ss->byte2 = slp->scsipi_scsi.lun << 5;
406 1.1 is ss->length = sizeof(struct scsipi_sense_data);
407 1.1 is acb->clen = sizeof(*ss);
408 1.1 is acb->daddr = (char *)&xs->sense.scsi_sense;
409 1.1 is acb->dleft = sizeof(struct scsipi_sense_data);
410 1.1 is acb->flags = ACB_ACTIVE | ACB_CHKSENSE;
411 1.1 is TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain);
412 1.1 is --sc->sc_active;
413 1.1 is sc->sc_tinfo[slp->scsipi_scsi.target].lubusy &=
414 1.1 is ~(1 << slp->scsipi_scsi.lun);
415 1.1 is sc->sc_tinfo[slp->scsipi_scsi.target].senses++;
416 1.1 is if (sc->sc_nexus == acb) {
417 1.1 is sc->sc_nexus = NULL;
418 1.1 is siopng_sched(sc);
419 1.1 is }
420 1.1 is SIOP_TRACE('d','s',0,0)
421 1.1 is return;
422 1.1 is }
423 1.1 is }
424 1.1 is if (xs->error == XS_NOERROR && (acb->flags & ACB_CHKSENSE)) {
425 1.1 is xs->error = XS_SENSE;
426 1.1 is } else {
427 1.1 is xs->resid = 0; /* XXXX */
428 1.1 is }
429 1.1 is #if whataboutthisone
430 1.1 is case SCSI_BUSY:
431 1.1 is xs->error = XS_BUSY;
432 1.1 is break;
433 1.1 is #endif
434 1.1 is xs->flags |= ITSDONE;
435 1.1 is
436 1.1 is /*
437 1.1 is * Remove the ACB from whatever queue it's on. We have to do a bit of
438 1.1 is * a hack to figure out which queue it's on. Note that it is *not*
439 1.1 is * necessary to cdr down the ready queue, but we must cdr down the
440 1.1 is * nexus queue and see if it's there, so we can mark the unit as no
441 1.1 is * longer busy. This code is sickening, but it works.
442 1.1 is */
443 1.1 is if (acb == sc->sc_nexus) {
444 1.1 is sc->sc_nexus = NULL;
445 1.1 is sc->sc_tinfo[slp->scsipi_scsi.target].lubusy &=
446 1.1 is ~(1<<slp->scsipi_scsi.lun);
447 1.1 is if (sc->ready_list.tqh_first)
448 1.1 is dosched = 1; /* start next command */
449 1.1 is --sc->sc_active;
450 1.1 is SIOP_TRACE('d','a',stat,0)
451 1.1 is } else if (sc->ready_list.tqh_last == &acb->chain.tqe_next) {
452 1.1 is TAILQ_REMOVE(&sc->ready_list, acb, chain);
453 1.1 is SIOP_TRACE('d','r',stat,0)
454 1.1 is } else {
455 1.1 is register struct siop_acb *acb2;
456 1.1 is for (acb2 = sc->nexus_list.tqh_first; acb2;
457 1.1 is acb2 = acb2->chain.tqe_next)
458 1.1 is if (acb2 == acb) {
459 1.1 is TAILQ_REMOVE(&sc->nexus_list, acb, chain);
460 1.1 is sc->sc_tinfo[slp->scsipi_scsi.target].lubusy
461 1.1 is &= ~(1<<slp->scsipi_scsi.lun);
462 1.1 is --sc->sc_active;
463 1.1 is break;
464 1.1 is }
465 1.1 is if (acb2)
466 1.1 is ;
467 1.1 is else if (acb->chain.tqe_next) {
468 1.1 is TAILQ_REMOVE(&sc->ready_list, acb, chain);
469 1.1 is --sc->sc_active;
470 1.1 is } else {
471 1.1 is printf("%s: can't find matching acb\n",
472 1.1 is sc->sc_dev.dv_xname);
473 1.1 is #ifdef DDB
474 1.1 is /* Debugger(); */
475 1.1 is #endif
476 1.1 is }
477 1.1 is SIOP_TRACE('d','n',stat,0);
478 1.1 is }
479 1.1 is /* Put it on the free list. */
480 1.1 is acb->flags = ACB_FREE;
481 1.1 is TAILQ_INSERT_HEAD(&sc->free_list, acb, chain);
482 1.1 is
483 1.1 is sc->sc_tinfo[slp->scsipi_scsi.target].cmds++;
484 1.1 is
485 1.1 is scsipi_done(xs);
486 1.1 is
487 1.1 is if (dosched && sc->sc_nexus == NULL)
488 1.1 is siopng_sched(sc);
489 1.1 is }
490 1.1 is
491 1.1 is void
492 1.1 is siopngabort(sc, rp, where)
493 1.1 is register struct siop_softc *sc;
494 1.1 is siop_regmap_p rp;
495 1.1 is char *where;
496 1.1 is {
497 1.1 is #ifdef fix_this
498 1.1 is int i;
499 1.1 is #endif
500 1.1 is
501 1.1 is printf ("%s: abort %s: dstat %02x, istat %02x sist %04x sien %04x sbcl %02x\n",
502 1.1 is sc->sc_dev.dv_xname,
503 1.1 is where, rp->siop_dstat, rp->siop_istat, rp->siop_sist,
504 1.1 is rp->siop_sien, rp->siop_sbcl);
505 1.1 is siopng_dump_registers(sc);
506 1.1 is
507 1.1 is if (sc->sc_active > 0) {
508 1.1 is #ifdef TODO
509 1.1 is SET_SBIC_cmd (rp, SBIC_CMD_ABORT);
510 1.1 is WAIT_CIP (rp);
511 1.1 is
512 1.1 is GET_SBIC_asr (rp, asr);
513 1.1 is if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
514 1.1 is {
515 1.1 is /* ok, get more drastic.. */
516 1.1 is
517 1.1 is SET_SBIC_cmd (rp, SBIC_CMD_RESET);
518 1.1 is delay(25);
519 1.1 is SBIC_WAIT(rp, SBIC_ASR_INT, 0);
520 1.1 is GET_SBIC_csr (rp, csr); /* clears interrupt also */
521 1.1 is
522 1.1 is return;
523 1.1 is }
524 1.1 is
525 1.1 is do
526 1.1 is {
527 1.1 is SBIC_WAIT (rp, SBIC_ASR_INT, 0);
528 1.1 is GET_SBIC_csr (rp, csr);
529 1.1 is }
530 1.1 is while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
531 1.1 is && (csr != SBIC_CSR_CMD_INVALID));
532 1.1 is #endif
533 1.1 is
534 1.1 is /* lets just hope it worked.. */
535 1.1 is #ifdef fix_this
536 1.1 is for (i = 0; i < 2; ++i) {
537 1.1 is if (sc->sc_iob[i].sc_xs && &sc->sc_iob[i] !=
538 1.1 is sc->sc_cur) {
539 1.1 is printf ("siopngabort: cleanup!\n");
540 1.1 is sc->sc_iob[i].sc_xs = NULL;
541 1.1 is }
542 1.1 is }
543 1.1 is #endif /* fix_this */
544 1.1 is /* sc->sc_active = 0; */
545 1.1 is }
546 1.1 is }
547 1.1 is
548 1.1 is void
549 1.1 is siopnginitialize(sc)
550 1.1 is struct siop_softc *sc;
551 1.1 is {
552 1.1 is int i;
553 1.1 is u_int inhibit_sync;
554 1.1 is extern u_long scsi_nosync;
555 1.1 is extern int shift_nosync;
556 1.1 is
557 1.1 is /*
558 1.1 is * Need to check that scripts is on a long word boundary
559 1.1 is * Also should verify that dev doesn't span non-contiguous
560 1.1 is * physical pages.
561 1.1 is */
562 1.1 is sc->sc_scriptspa = kvtop((caddr_t)siopng_scripts);
563 1.1 is
564 1.1 is /*
565 1.1 is * malloc sc_acb to ensure that DS is on a long word boundary.
566 1.1 is */
567 1.1 is
568 1.1 is MALLOC(sc->sc_acb, struct siop_acb *,
569 1.1 is sizeof(struct siop_acb) * SIOP_NACB, M_DEVBUF, M_NOWAIT);
570 1.1 is if (sc->sc_acb == NULL)
571 1.1 is panic("siopnginitialize: ACB malloc failed!");
572 1.1 is
573 1.1 is sc->sc_tcp[1] = 1000 / sc->sc_clock_freq;
574 1.1 is sc->sc_tcp[2] = 1500 / sc->sc_clock_freq;
575 1.1 is sc->sc_tcp[3] = 2000 / sc->sc_clock_freq;
576 1.1 is sc->sc_minsync = sc->sc_tcp[1]; /* in 4ns units */
577 1.1 is if (sc->sc_minsync < 25)
578 1.1 is sc->sc_minsync = 25;
579 1.1 is if (sc->sc_clock_freq <= 25) {
580 1.1 is sc->sc_dcntl |= 0x80; /* SCLK/1 */
581 1.1 is sc->sc_tcp[0] = sc->sc_tcp[1];
582 1.1 is } else if (sc->sc_clock_freq <= 37) {
583 1.1 is sc->sc_dcntl |= 0x40; /* SCLK/1.5 */
584 1.1 is sc->sc_tcp[0] = sc->sc_tcp[2];
585 1.1 is } else if (sc->sc_clock_freq <= 50) {
586 1.1 is sc->sc_dcntl |= 0x00; /* SCLK/2 */
587 1.1 is sc->sc_tcp[0] = sc->sc_tcp[3];
588 1.1 is } else {
589 1.1 is sc->sc_dcntl |= 0xc0; /* SCLK/3 */
590 1.1 is sc->sc_tcp[0] = 3000 / sc->sc_clock_freq;
591 1.1 is }
592 1.1 is
593 1.1 is if (scsi_nosync) {
594 1.1 is inhibit_sync = (scsi_nosync >> shift_nosync) & 0xff;
595 1.1 is shift_nosync += 8;
596 1.1 is #ifdef DEBUG
597 1.1 is if (inhibit_sync)
598 1.1 is printf("%s: Inhibiting synchronous transfer %02x\n",
599 1.1 is sc->sc_dev.dv_xname, inhibit_sync);
600 1.1 is #endif
601 1.1 is for (i = 0; i < 8; ++i)
602 1.1 is if (inhibit_sync & (1 << i))
603 1.1 is siopng_inhibit_sync[i] = 1;
604 1.1 is }
605 1.1 is
606 1.1 is siopngreset (sc);
607 1.1 is }
608 1.1 is
609 1.1 is void
610 1.1 is siopngreset(sc)
611 1.1 is struct siop_softc *sc;
612 1.1 is {
613 1.1 is siop_regmap_p rp;
614 1.1 is u_int i, s;
615 1.1 is u_short dummy;
616 1.1 is struct siop_acb *acb;
617 1.1 is
618 1.1 is rp = sc->sc_siopp;
619 1.1 is
620 1.1 is if (sc->sc_flags & SIOP_ALIVE)
621 1.1 is siopngabort(sc, rp, "reset");
622 1.1 is
623 1.1 is printf("%s: ", sc->sc_dev.dv_xname); /* XXXX */
624 1.1 is
625 1.1 is s = splbio();
626 1.1 is
627 1.1 is /*
628 1.1 is * Reset the chip
629 1.1 is * XXX - is this really needed?
630 1.1 is */
631 1.1 is rp->siop_istat |= SIOP_ISTAT_ABRT; /* abort current script */
632 1.1 is rp->siop_istat |= SIOP_ISTAT_RST; /* reset chip */
633 1.1 is rp->siop_istat &= ~SIOP_ISTAT_RST;
634 1.1 is /*
635 1.1 is * Reset SCSI bus (do we really want this?)
636 1.1 is */
637 1.1 is rp->siop_sien = 0;
638 1.1 is rp->siop_scntl1 |= SIOP_SCNTL1_RST;
639 1.1 is delay(1);
640 1.1 is rp->siop_scntl1 &= ~SIOP_SCNTL1_RST;
641 1.1 is
642 1.1 is /*
643 1.1 is * Set up various chip parameters
644 1.1 is */
645 1.1 is rp->siop_stest1 |= 0x08; /* SCLK doubler enable */
646 1.1 is delay(20);
647 1.1 is rp->siop_stest3 |= 0x20; /* Halt SCSI clock */
648 1.1 is rp->siop_scntl3 = 0x15; /* SCF/CCF*/
649 1.1 is rp->siop_stest1 |= 0x04; /* SCLK doubler select */
650 1.1 is rp->siop_stest3 &= ~0x20; /* Clear Halt SCSI clock */
651 1.1 is rp->siop_scntl0 = SIOP_ARB_FULL | /*SIOP_SCNTL0_EPC |*/ SIOP_SCNTL0_EPG;
652 1.1 is rp->siop_dcntl = sc->sc_dcntl;
653 1.1 is rp->siop_dmode = 0xc0; /* XXX burst length */
654 1.1 is rp->siop_sien = 0x00; /* don't enable interrupts yet */
655 1.1 is rp->siop_dien = 0x00; /* don't enable interrupts yet */
656 1.1 is rp->siop_scid = sc->sc_link.scsipi_scsi.adapter_target | 0x60;
657 1.1 is rp->siop_respid = 1 << sc->sc_link.scsipi_scsi.adapter_target;
658 1.1 is rp->siop_dwt = 0x00;
659 1.1 is rp->siop_stime0 = 0x0c; /* XXXXX check */
660 1.1 is
661 1.1 is /* will need to re-negotiate sync xfers */
662 1.1 is bzero(&sc->sc_sync, sizeof (sc->sc_sync));
663 1.1 is
664 1.1 is i = rp->siop_istat;
665 1.1 is if (i & SIOP_ISTAT_SIP)
666 1.1 is dummy = rp->siop_sist;
667 1.1 is if (i & SIOP_ISTAT_DIP)
668 1.1 is dummy = rp->siop_dstat;
669 1.1 is
670 1.1 is splx (s);
671 1.1 is
672 1.1 is delay (siopng_reset_delay * 1000);
673 1.1 is /*
674 1.1 is * Check if upper half of SCSI bus is unterminated, and disallow
675 1.1 is * disconnections if it appears to be unterminated.
676 1.1 is */
677 1.1 is if ((rp->siop_sbdl & 0xff00) == 0xff00) {
678 1.1 is printf(" NO WIDE TERM");
679 1.1 is for (i = 0; i < 16; ++i)
680 1.1 is siopng_allow_disc[i] = 0;
681 1.1 is }
682 1.4 is
683 1.4 is printf("siopng type %s id %d reset V%d\n",
684 1.4 is siopng_chips[rp->siop_macntl>>4],
685 1.4 is sc->sc_link.scsipi_scsi.adapter_target,
686 1.1 is rp->siop_ctest3 >> 4);
687 1.1 is
688 1.1 is if ((sc->sc_flags & SIOP_ALIVE) == 0) {
689 1.1 is TAILQ_INIT(&sc->ready_list);
690 1.1 is TAILQ_INIT(&sc->nexus_list);
691 1.1 is TAILQ_INIT(&sc->free_list);
692 1.1 is sc->sc_nexus = NULL;
693 1.1 is acb = sc->sc_acb;
694 1.1 is bzero(acb, sizeof(struct siop_acb) * SIOP_NACB);
695 1.1 is for (i = 0; i < SIOP_NACB; i++) {
696 1.1 is TAILQ_INSERT_TAIL(&sc->free_list, acb, chain);
697 1.1 is acb++;
698 1.1 is }
699 1.1 is bzero(sc->sc_tinfo, sizeof(sc->sc_tinfo));
700 1.1 is } else {
701 1.1 is if (sc->sc_nexus != NULL) {
702 1.1 is sc->sc_nexus->xs->error = XS_DRIVER_STUFFUP;
703 1.1 is siopng_scsidone(sc->sc_nexus, sc->sc_nexus->stat[0]);
704 1.1 is }
705 1.1 is while ((acb = sc->nexus_list.tqh_first) > 0) {
706 1.1 is acb->xs->error = XS_DRIVER_STUFFUP;
707 1.1 is siopng_scsidone(acb, acb->stat[0]);
708 1.1 is }
709 1.1 is }
710 1.1 is
711 1.1 is sc->sc_flags |= SIOP_ALIVE;
712 1.1 is sc->sc_flags &= ~(SIOP_INTDEFER|SIOP_INTSOFF);
713 1.1 is /* enable SCSI and DMA interrupts */
714 1.1 is sc->sc_sien = SIOP_SIEN_MA | SIOP_SIEN_STO | /*SIOP_SIEN_GEN |*/
715 1.1 is /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE | SIOP_SIEN_UDC |
716 1.1 is SIOP_SIEN_RST | SIOP_SIEN_PAR;
717 1.1 is sc->sc_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR |
718 1.1 is /*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID;
719 1.1 is rp->siop_sien = sc->sc_sien;
720 1.1 is rp->siop_dien = sc->sc_dien;
721 1.1 is siopng_dump_registers(sc);
722 1.1 is }
723 1.1 is
724 1.1 is /*
725 1.1 is * Setup Data Storage for 53C720/770 and start SCRIPTS processing
726 1.1 is */
727 1.1 is
728 1.1 is void
729 1.1 is siopng_start (sc, target, lun, cbuf, clen, buf, len)
730 1.1 is struct siop_softc *sc;
731 1.1 is int target;
732 1.1 is int lun;
733 1.1 is u_char *cbuf;
734 1.1 is int clen;
735 1.1 is u_char *buf;
736 1.1 is int len;
737 1.1 is {
738 1.1 is siop_regmap_p rp = sc->sc_siopp;
739 1.1 is int nchain;
740 1.1 is int count, tcount;
741 1.1 is char *addr, *dmaend;
742 1.1 is struct siop_acb *acb = sc->sc_nexus;
743 1.1 is #ifdef DEBUG
744 1.1 is int i;
745 1.1 is #endif
746 1.1 is
747 1.1 is #ifdef DEBUG
748 1.1 is if (siopng_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
749 1.1 is printf ("ACK! siopng was busy: rp %p script %p dsa %p active %ld\n",
750 1.2 is rp, &siopng_scripts, &acb->ds, sc->sc_active);
751 1.1 is printf ("istat %02x sfbr %02x respid %02x sien %04x dien %02x\n",
752 1.1 is rp->siop_istat, rp->siop_sfbr, rp->siop_respid,
753 1.1 is rp->siop_sien, rp->siop_dien);
754 1.1 is #ifdef DDB
755 1.1 is /*Debugger();*/
756 1.1 is #endif
757 1.1 is }
758 1.1 is #endif
759 1.1 is acb->msgout[0] = MSG_IDENTIFY | lun;
760 1.1 is if (siopng_allow_disc[target] & 2 ||
761 1.1 is (siopng_allow_disc[target] && len == 0))
762 1.1 is acb->msgout[0] = MSG_IDENTIFY_DR | lun;
763 1.1 is acb->status = 0;
764 1.1 is acb->stat[0] = -1;
765 1.1 is acb->msg[0] = -1;
766 1.1 is acb->ds.scsi_addr = (target << 16) | (sc->sc_sync[target].sxfer << 8) |
767 1.1 is (sc->sc_sync[target].sbcl << 24);
768 1.1 is acb->ds.idlen = 1;
769 1.1 is acb->ds.idbuf = (char *) kvtop(&acb->msgout[0]);
770 1.1 is acb->ds.cmdlen = clen;
771 1.1 is acb->ds.cmdbuf = (char *) kvtop(cbuf);
772 1.1 is acb->ds.stslen = 1;
773 1.1 is acb->ds.stsbuf = (char *) kvtop(&acb->stat[0]);
774 1.1 is acb->ds.msglen = 1;
775 1.1 is acb->ds.msgbuf = (char *) kvtop(&acb->msg[0]);
776 1.1 is acb->msg[1] = -1;
777 1.1 is acb->ds.msginlen = 1;
778 1.1 is acb->ds.extmsglen = 1;
779 1.1 is acb->ds.synmsglen = 3;
780 1.1 is acb->ds.msginbuf = (char *) kvtop(&acb->msg[1]);
781 1.1 is acb->ds.extmsgbuf = (char *) kvtop(&acb->msg[2]);
782 1.1 is acb->ds.synmsgbuf = (char *) kvtop(&acb->msg[3]);
783 1.1 is bzero(&acb->ds.chain, sizeof (acb->ds.chain));
784 1.1 is
785 1.1 is if (sc->sc_sync[target].state == SYNC_START) {
786 1.1 is if (siopng_inhibit_sync[target]) {
787 1.1 is sc->sc_sync[target].state = SYNC_DONE;
788 1.1 is sc->sc_sync[target].sbcl = 5; /* XXX */
789 1.1 is sc->sc_sync[target].sxfer = 0;
790 1.1 is #ifdef DEBUG
791 1.1 is if (siopngsync_debug)
792 1.1 is printf ("Forcing target %d asynchronous\n", target);
793 1.1 is #endif
794 1.1 is }
795 1.1 is else {
796 1.1 is acb->msg[2] = -1;
797 1.1 is acb->msgout[1] = MSG_EXT_MESSAGE;
798 1.1 is acb->msgout[2] = 3;
799 1.1 is acb->msgout[3] = MSG_SYNC_REQ;
800 1.1 is #ifdef MAXTOR_SYNC_KLUDGE
801 1.1 is acb->msgout[4] = 50 / 4; /* ask for ridiculous period */
802 1.1 is #else
803 1.1 is acb->msgout[4] = sc->sc_minsync;
804 1.1 is #endif
805 1.1 is acb->msgout[5] = SIOP_MAX_OFFSET;
806 1.1 is acb->ds.idlen = 6;
807 1.1 is sc->sc_sync[target].state = SYNC_SENT;
808 1.1 is #ifdef DEBUG
809 1.1 is if (siopngsync_debug)
810 1.1 is printf ("Sending sync request to target %d\n", target);
811 1.1 is #endif
812 1.1 is }
813 1.1 is }
814 1.1 is
815 1.1 is /*
816 1.1 is * Build physical DMA addresses for scatter/gather I/O
817 1.1 is */
818 1.1 is acb->iob_buf = buf;
819 1.1 is acb->iob_len = len;
820 1.1 is acb->iob_curbuf = acb->iob_curlen = 0;
821 1.1 is nchain = 0;
822 1.1 is count = len;
823 1.1 is addr = buf;
824 1.1 is dmaend = NULL;
825 1.1 is while (count > 0) {
826 1.1 is acb->ds.chain[nchain].databuf = (char *) kvtop (addr);
827 1.1 is if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
828 1.1 is tcount = count;
829 1.3 is
830 1.3 is #if DEBUG_ONLY_IF_DESPERATE
831 1.3 is printf("chain[%d]: count %d tcount %d vaddr %p paddr %p\n",
832 1.3 is nchain, count, tcount, addr,
833 1.3 is acb->ds.chain[nchain].databuf);
834 1.3 is #endif
835 1.1 is acb->ds.chain[nchain].datalen = tcount;
836 1.1 is addr += tcount;
837 1.1 is count -= tcount;
838 1.1 is if (acb->ds.chain[nchain].databuf == dmaend) {
839 1.1 is dmaend += acb->ds.chain[nchain].datalen;
840 1.1 is acb->ds.chain[nchain].datalen = 0;
841 1.1 is acb->ds.chain[--nchain].datalen += tcount;
842 1.1 is #ifdef DEBUG
843 1.1 is ++siopngdma_hits;
844 1.1 is #endif
845 1.1 is }
846 1.1 is else {
847 1.1 is dmaend = acb->ds.chain[nchain].databuf +
848 1.1 is acb->ds.chain[nchain].datalen;
849 1.1 is acb->ds.chain[nchain].datalen = tcount;
850 1.1 is #ifdef DEBUG
851 1.1 is if (nchain) /* Don't count miss on first one */
852 1.1 is ++siopngdma_misses;
853 1.1 is #endif
854 1.1 is }
855 1.1 is ++nchain;
856 1.1 is }
857 1.1 is #ifdef DEBUG
858 1.1 is if (nchain != 1 && len != 0 && siopng_debug & 3) {
859 1.1 is printf ("DMA chaining set: %d\n", nchain);
860 1.1 is for (i = 0; i < nchain; ++i) {
861 1.1 is printf (" [%d] %8p %lx\n", i, acb->ds.chain[i].databuf,
862 1.1 is acb->ds.chain[i].datalen);
863 1.1 is }
864 1.1 is }
865 1.1 is #endif
866 1.1 is
867 1.1 is /* push data cache for all data the 53c720/770 needs to access */
868 1.1 is dma_cachectl ((caddr_t)acb, sizeof (struct siop_acb));
869 1.1 is dma_cachectl (cbuf, clen);
870 1.1 is if (buf != NULL && len != 0)
871 1.1 is dma_cachectl (buf, len);
872 1.1 is #ifdef DEBUG
873 1.1 is if (siopng_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
874 1.1 is printf ("ACK! siopng was busy at start: rp %p script %p dsa %p active %ld\n",
875 1.2 is rp, &siopng_scripts, &acb->ds, sc->sc_active);
876 1.1 is #ifdef DDB
877 1.1 is /*Debugger();*/
878 1.1 is #endif
879 1.1 is }
880 1.1 is #endif
881 1.1 is if (sc->nexus_list.tqh_first == NULL) {
882 1.1 is if (rp->siop_istat & SIOP_ISTAT_CON)
883 1.1 is printf("%s: siopng_select while connected?\n",
884 1.1 is sc->sc_dev.dv_xname);
885 1.1 is rp->siop_temp = 0;
886 1.1 is #ifndef FIXME
887 1.1 is rp->siop_scntl3 = sc->sc_sync[target].sbcl;
888 1.1 is #endif
889 1.1 is rp->siop_dsa = kvtop((caddr_t)&acb->ds);
890 1.1 is rp->siop_dsp = sc->sc_scriptspa;
891 1.1 is SIOP_TRACE('s',1,0,0)
892 1.1 is } else {
893 1.1 is if ((rp->siop_istat & SIOP_ISTAT_CON) == 0) {
894 1.1 is rp->siop_istat = SIOP_ISTAT_SIGP;
895 1.1 is SIOP_TRACE('s',2,0,0);
896 1.1 is }
897 1.1 is else {
898 1.1 is SIOP_TRACE('s',3,rp->siop_istat,0);
899 1.1 is }
900 1.1 is }
901 1.1 is #ifdef DEBUG
902 1.1 is ++siopngstarts;
903 1.1 is #endif
904 1.1 is }
905 1.1 is
906 1.1 is /*
907 1.1 is * Process a DMA or SCSI interrupt from the 53C720/770 SIOP
908 1.1 is */
909 1.1 is
910 1.1 is int
911 1.1 is siopng_checkintr(sc, istat, dstat, sist, status)
912 1.1 is struct siop_softc *sc;
913 1.1 is u_char istat;
914 1.1 is u_char dstat;
915 1.1 is u_short sist;
916 1.1 is int *status;
917 1.1 is {
918 1.1 is siop_regmap_p rp = sc->sc_siopp;
919 1.1 is struct siop_acb *acb = sc->sc_nexus;
920 1.1 is int target = 0;
921 1.3 is int dfifo, dbc, sstat0, sstat1, sstat2;
922 1.1 is
923 1.1 is dfifo = rp->siop_dfifo;
924 1.1 is dbc = rp->siop_dbc0;
925 1.3 is sstat0 = rp->siop_sstat0;
926 1.1 is sstat1 = rp->siop_sstat1;
927 1.3 is sstat2 = rp->siop_sstat2;
928 1.1 is rp->siop_ctest3 |= SIOP_CTEST8_CLF;
929 1.1 is while ((rp->siop_ctest1 & SIOP_CTEST1_FMT) != SIOP_CTEST1_FMT)
930 1.1 is ;
931 1.1 is rp->siop_ctest3 &= ~SIOP_CTEST8_CLF;
932 1.1 is #ifdef DEBUG
933 1.1 is ++siopngints;
934 1.1 is #if 0
935 1.1 is if (siopng_debug & 0x100) {
936 1.1 is DCIAS(&acb->stat[0]); /* XXX */
937 1.1 is printf ("siopngchkintr: istat %x dstat %x sist %x dsps %x sbcl %x sts %x msg %x\n",
938 1.1 is istat, dstat, sist, rp->siop_dsps, rp->siop_sbcl, acb->stat[0], acb->msg[0]);
939 1.1 is printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
940 1.1 is acb->msg[0], acb->msg[1], acb->msg[2],
941 1.1 is acb->msg[3], acb->msg[4], acb->msg[5]);
942 1.1 is }
943 1.1 is #endif
944 1.1 is if (rp->siop_dsp && (rp->siop_dsp < sc->sc_scriptspa ||
945 1.2 is rp->siop_dsp >= sc->sc_scriptspa + sizeof(siopng_scripts))) {
946 1.1 is printf ("%s: dsp not within script dsp %lx scripts %lx:%lx",
947 1.1 is sc->sc_dev.dv_xname, rp->siop_dsp, sc->sc_scriptspa,
948 1.2 is sc->sc_scriptspa + sizeof(siopng_scripts));
949 1.1 is printf(" istat %x dstat %x sist %x\n",
950 1.1 is istat, dstat, sist);
951 1.1 is #ifdef DDB
952 1.1 is Debugger();
953 1.1 is #endif
954 1.1 is }
955 1.1 is #endif
956 1.1 is SIOP_TRACE('i',dstat,istat,(istat&SIOP_ISTAT_DIP)?rp->siop_dsps&0xff:sist);
957 1.1 is if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff00) {
958 1.1 is /* Normal completion status, or check condition */
959 1.1 is #ifdef DEBUG
960 1.1 is if (rp->siop_dsa != kvtop((caddr_t)&acb->ds)) {
961 1.1 is printf ("siopng: invalid dsa: %lx %x\n", rp->siop_dsa,
962 1.1 is kvtop((caddr_t)&acb->ds));
963 1.1 is panic("*** siopng DSA invalid ***");
964 1.1 is }
965 1.1 is #endif
966 1.1 is target = acb->xs->sc_link->scsipi_scsi.target;
967 1.1 is if (sc->sc_sync[target].state == SYNC_SENT) {
968 1.1 is #ifdef DEBUG
969 1.1 is if (siopngsync_debug)
970 1.1 is printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
971 1.1 is acb->msg[0], acb->msg[1], acb->msg[2],
972 1.1 is acb->msg[3], acb->msg[4], acb->msg[5]);
973 1.1 is #endif
974 1.1 is if (acb->msg[1] == 0xff)
975 1.1 is printf ("%s: target %d ignored sync request\n",
976 1.1 is sc->sc_dev.dv_xname, target);
977 1.1 is else if (acb->msg[1] == MSG_REJECT)
978 1.1 is printf ("%s: target %d rejected sync request\n",
979 1.1 is sc->sc_dev.dv_xname, target);
980 1.1 is sc->sc_sync[target].state = SYNC_DONE;
981 1.1 is sc->sc_sync[target].sxfer = 0;
982 1.1 is sc->sc_sync[target].sbcl = 5; /* XXX */
983 1.1 is if (acb->msg[2] == 3 &&
984 1.1 is acb->msg[3] == MSG_SYNC_REQ &&
985 1.1 is acb->msg[5] != 0) {
986 1.1 is #ifdef MAXTOR_KLUDGE
987 1.1 is /*
988 1.1 is * Kludge for my Maxtor XT8580S
989 1.1 is * It accepts whatever we request, even
990 1.1 is * though it won't work. So we ask for
991 1.1 is * a short period than we can handle. If
992 1.1 is * the device says it can do it, use 208ns.
993 1.1 is * If the device says it can do less than
994 1.1 is * 100ns, then we limit it to 100ns.
995 1.1 is */
996 1.1 is if (acb->msg[4] && acb->msg[4] < 100 / 4) {
997 1.1 is #ifdef DEBUG
998 1.1 is printf ("%d: target %d wanted %dns period\n",
999 1.1 is sc->sc_dev.dv_xname, target,
1000 1.1 is acb->msg[4] * 4);
1001 1.1 is #endif
1002 1.1 is if (acb->msg[4] == 50 / 4)
1003 1.1 is acb->msg[4] = 208 / 4;
1004 1.1 is else
1005 1.1 is acb->msg[4] = 100 / 4;
1006 1.1 is }
1007 1.1 is #endif /* MAXTOR_KLUDGE */
1008 1.1 is printf ("%s: target %d now synchronous, period=%dns, offset=%d\n",
1009 1.1 is sc->sc_dev.dv_xname, target,
1010 1.1 is acb->msg[4] * 4, acb->msg[5]);
1011 1.1 is scsi_period_to_siopng (sc, target);
1012 1.1 is }
1013 1.1 is }
1014 1.1 is dma_cachectl(&acb->stat[0], 1);
1015 1.1 is *status = acb->stat[0];
1016 1.1 is #ifdef DEBUG
1017 1.1 is if (rp->siop_sbcl & SIOP_BSY) {
1018 1.1 is /*printf ("ACK! siop was busy at end: rp %x script %x dsa %x\n",
1019 1.2 is rp, &siopng_scripts, &acb->ds);*/
1020 1.1 is #ifdef DDB
1021 1.1 is /*Debugger();*/
1022 1.1 is #endif
1023 1.1 is }
1024 1.1 is if (acb->msg[0] != 0x00)
1025 1.1 is printf("%s: message was not COMMAND COMPLETE: %x\n",
1026 1.1 is sc->sc_dev.dv_xname, acb->msg[0]);
1027 1.1 is #endif
1028 1.1 is if (sc->nexus_list.tqh_first)
1029 1.1 is rp->siop_dcntl |= SIOP_DCNTL_STD;
1030 1.1 is return 1;
1031 1.1 is }
1032 1.1 is if (sist & SIOP_SIST_MA) { /* Phase mismatch */
1033 1.1 is #ifdef DEBUG
1034 1.1 is ++siopngphmm;
1035 1.1 is if (acb == NULL)
1036 1.1 is printf("%s: Phase mismatch with no active command?\n",
1037 1.1 is sc->sc_dev.dv_xname);
1038 1.1 is #endif
1039 1.1 is if (acb->iob_len) {
1040 1.1 is int adjust;
1041 1.1 is adjust = ((dfifo - (dbc & 0x7f)) & 0x7f);
1042 1.3 is if (sstat0 & (1<<5)) /* sstat0 SODL lsb */
1043 1.3 is ++adjust;
1044 1.3 is if (sstat0 & (1<<6)) /* sstat0 SODR lsb */
1045 1.3 is ++adjust;
1046 1.3 is if (sstat2 & (1<<5)) /* sstat2 SODL msb */
1047 1.1 is ++adjust;
1048 1.3 is if (sstat2 & (1<<6)) /* sstat2 SODR msb */
1049 1.1 is ++adjust;
1050 1.1 is acb->iob_curlen = *((long *)&rp->siop_dcmd) & 0xffffff;
1051 1.1 is acb->iob_curlen += adjust;
1052 1.1 is acb->iob_curbuf = *((long *)&rp->siop_dnad) - adjust;
1053 1.1 is #ifdef DEBUG
1054 1.1 is if (siopng_debug & 0x100) {
1055 1.1 is int i;
1056 1.1 is printf ("Phase mismatch: curbuf %lx curlen %lx dfifo %x dbc %x sstat1 %x adjust %x sbcl %x starts %d acb %p\n",
1057 1.1 is acb->iob_curbuf, acb->iob_curlen, dfifo,
1058 1.1 is dbc, sstat1, adjust, rp->siop_sbcl, siopngstarts, acb);
1059 1.1 is if (acb->ds.chain[1].datalen) {
1060 1.1 is for (i = 0; acb->ds.chain[i].datalen; ++i)
1061 1.1 is printf("chain[%d] addr %p len %lx\n",
1062 1.1 is i, acb->ds.chain[i].databuf,
1063 1.1 is acb->ds.chain[i].datalen);
1064 1.1 is }
1065 1.1 is }
1066 1.1 is #endif
1067 1.1 is dma_cachectl ((caddr_t)acb, sizeof(*acb));
1068 1.1 is }
1069 1.1 is #ifdef DEBUG
1070 1.1 is SIOP_TRACE('m',rp->siop_sbcl,(rp->siop_dsp>>8),rp->siop_dsp);
1071 1.1 is if (siopng_debug & 9)
1072 1.1 is printf ("Phase mismatch: %x dsp +%lx dcmd %lx\n",
1073 1.1 is rp->siop_sbcl,
1074 1.1 is rp->siop_dsp - sc->sc_scriptspa,
1075 1.1 is *((long *)&rp->siop_dcmd));
1076 1.1 is #endif
1077 1.1 is if ((rp->siop_sbcl & SIOP_REQ) == 0) {
1078 1.1 is printf ("Phase mismatch: REQ not asserted! %02x dsp %lx\n",
1079 1.1 is rp->siop_sbcl, rp->siop_dsp);
1080 1.1 is #if defined(DEBUG) && defined(DDB)
1081 1.1 is Debugger();
1082 1.1 is #endif
1083 1.1 is }
1084 1.1 is switch (rp->siop_sbcl & 7) {
1085 1.1 is case 0: /* data out */
1086 1.1 is case 1: /* data in */
1087 1.1 is case 2: /* status */
1088 1.1 is case 3: /* command */
1089 1.1 is case 6: /* message in */
1090 1.1 is case 7: /* message out */
1091 1.1 is rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
1092 1.1 is break;
1093 1.1 is default:
1094 1.1 is goto bad_phase;
1095 1.1 is }
1096 1.1 is return 0;
1097 1.1 is }
1098 1.1 is if (sist & SIOP_SIST_STO) { /* Select timed out */
1099 1.1 is #ifdef DEBUG
1100 1.1 is if (acb == NULL)
1101 1.1 is printf("%s: Select timeout with no active command?\n",
1102 1.1 is sc->sc_dev.dv_xname);
1103 1.1 is if (rp->siop_sbcl & SIOP_BSY) {
1104 1.1 is printf ("ACK! siop was busy at timeout: rp %p script %p dsa %p\n",
1105 1.2 is rp, &siopng_scripts, &acb->ds);
1106 1.1 is printf(" sbcl %x sdid %x istat %x dstat %x sist %x\n",
1107 1.1 is rp->siop_sbcl, rp->siop_sdid, istat, dstat, sist);
1108 1.1 is if (!(rp->siop_sbcl & SIOP_BSY)) {
1109 1.1 is printf ("Yikes, it's not busy now!\n");
1110 1.1 is #if 0
1111 1.1 is *status = -1;
1112 1.1 is if (sc->nexus_list.tqh_first)
1113 1.1 is rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1114 1.1 is return 1;
1115 1.1 is #endif
1116 1.1 is }
1117 1.1 is /* rp->siop_dcntl |= SIOP_DCNTL_STD;*/
1118 1.1 is return (0);
1119 1.1 is #ifdef DDB
1120 1.1 is Debugger();
1121 1.1 is #endif
1122 1.1 is }
1123 1.1 is #endif
1124 1.1 is *status = -1;
1125 1.1 is acb->xs->error = XS_SELTIMEOUT;
1126 1.1 is if (sc->nexus_list.tqh_first)
1127 1.1 is rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1128 1.1 is return 1;
1129 1.1 is }
1130 1.1 is if (acb)
1131 1.1 is target = acb->xs->sc_link->scsipi_scsi.target;
1132 1.1 is else
1133 1.1 is target = 7;
1134 1.1 is if (sist & SIOP_SIST_UDC) {
1135 1.1 is #ifdef DEBUG
1136 1.1 is if (acb == NULL)
1137 1.1 is printf("%s: Unexpected disconnect with no active command?\n",
1138 1.1 is sc->sc_dev.dv_xname);
1139 1.1 is printf ("%s: target %d disconnected unexpectedly\n",
1140 1.1 is sc->sc_dev.dv_xname, target);
1141 1.1 is siopng_dump_registers(sc);
1142 1.1 is siopng_dump(sc);
1143 1.1 is #endif
1144 1.1 is #if 0
1145 1.1 is siopngabort (sc, rp, "siopngchkintr");
1146 1.1 is #endif
1147 1.1 is *status = STS_BUSY;
1148 1.1 is if (sc->nexus_list.tqh_first)
1149 1.1 is rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1150 1.1 is return (acb != NULL);
1151 1.1 is }
1152 1.1 is if (dstat & SIOP_DSTAT_SIR && (rp->siop_dsps == 0xff01 ||
1153 1.1 is rp->siop_dsps == 0xff02)) {
1154 1.1 is #ifdef DEBUG
1155 1.1 is if (siopng_debug & 0x100)
1156 1.1 is printf ("%s: ID %02x disconnected TEMP %lx (+%lx) curbuf %lx curlen %lx buf %p len %lx dfifo %x dbc %x sstat1 %x starts %d acb %p\n",
1157 1.1 is sc->sc_dev.dv_xname, 1 << target, rp->siop_temp,
1158 1.1 is rp->siop_temp ? rp->siop_temp - sc->sc_scriptspa : 0,
1159 1.1 is acb->iob_curbuf, acb->iob_curlen,
1160 1.1 is acb->ds.chain[0].databuf, acb->ds.chain[0].datalen, dfifo, dbc, sstat1, siopngstarts, acb);
1161 1.1 is #endif
1162 1.1 is if (acb == NULL) {
1163 1.1 is printf("%s: Disconnect with no active command?\n",
1164 1.1 is sc->sc_dev.dv_xname);
1165 1.1 is return (0);
1166 1.1 is }
1167 1.1 is /*
1168 1.1 is * XXXX need to update iob_curbuf/iob_curlen to reflect
1169 1.1 is * current data transferred. If device disconnected in
1170 1.1 is * the middle of a DMA block, they should already be set
1171 1.1 is * by the phase change interrupt. If the disconnect
1172 1.1 is * occurs on a DMA block boundary, we have to figure out
1173 1.1 is * which DMA block it was.
1174 1.1 is */
1175 1.1 is if (acb->iob_len && rp->siop_temp) {
1176 1.1 is int n = rp->siop_temp - sc->sc_scriptspa;
1177 1.1 is
1178 1.1 is if (acb->iob_curlen && acb->iob_curlen != acb->ds.chain[0].datalen)
1179 1.1 is printf("%s: iob_curbuf/len already set? n %x iob %lx/%lx chain[0] %p/%lx\n",
1180 1.1 is sc->sc_dev.dv_xname, n, acb->iob_curbuf, acb->iob_curlen,
1181 1.1 is acb->ds.chain[0].databuf, acb->ds.chain[0].datalen);
1182 1.1 is if (n < Ent_datain)
1183 1.1 is n = (n - Ent_dataout) / 16;
1184 1.1 is else
1185 1.1 is n = (n - Ent_datain) / 16;
1186 1.1 is if (n <= 0 && n > DMAMAXIO)
1187 1.1 is printf("TEMP invalid %d\n", n);
1188 1.1 is else {
1189 1.1 is acb->iob_curbuf = (u_long)acb->ds.chain[n].databuf;
1190 1.1 is acb->iob_curlen = acb->ds.chain[n].datalen;
1191 1.1 is }
1192 1.1 is #ifdef DEBUG
1193 1.1 is if (siopng_debug & 0x100) {
1194 1.1 is printf("%s: TEMP offset %d", sc->sc_dev.dv_xname, n);
1195 1.1 is printf(" curbuf %lx curlen %lx\n", acb->iob_curbuf,
1196 1.1 is acb->iob_curlen);
1197 1.1 is }
1198 1.1 is #endif
1199 1.1 is }
1200 1.1 is /*
1201 1.1 is * If data transfer was interrupted by disconnect, iob_curbuf
1202 1.1 is * and iob_curlen should reflect the point of interruption.
1203 1.1 is * Adjust the DMA chain so that the data transfer begins
1204 1.1 is * at the appropriate place upon reselection.
1205 1.1 is * XXX This should only be done on save data pointer message?
1206 1.1 is */
1207 1.1 is if (acb->iob_curlen) {
1208 1.1 is int i, j;
1209 1.1 is
1210 1.1 is #ifdef DEBUG
1211 1.1 is if (siopng_debug & 0x100)
1212 1.1 is printf ("%s: adjusting DMA chain\n",
1213 1.1 is sc->sc_dev.dv_xname);
1214 1.1 is if (rp->siop_dsps == 0xff02)
1215 1.1 is printf ("%s: ID %02x disconnected without Save Data Pointers\n",
1216 1.1 is sc->sc_dev.dv_xname, 1 << target);
1217 1.1 is #endif
1218 1.1 is for (i = 0; i < DMAMAXIO; ++i) {
1219 1.1 is if (acb->ds.chain[i].datalen == 0)
1220 1.1 is break;
1221 1.1 is if (acb->iob_curbuf >= (long)acb->ds.chain[i].databuf &&
1222 1.1 is acb->iob_curbuf < (long)(acb->ds.chain[i].databuf +
1223 1.1 is acb->ds.chain[i].datalen))
1224 1.1 is break;
1225 1.1 is }
1226 1.1 is if (i >= DMAMAXIO || acb->ds.chain[i].datalen == 0) {
1227 1.1 is printf("couldn't find saved data pointer: ");
1228 1.1 is printf("curbuf %lx curlen %lx i %d\n",
1229 1.1 is acb->iob_curbuf, acb->iob_curlen, i);
1230 1.1 is #ifdef DDB
1231 1.1 is Debugger();
1232 1.1 is #endif
1233 1.1 is }
1234 1.1 is #ifdef DEBUG
1235 1.1 is if (siopng_debug & 0x100)
1236 1.1 is printf(" chain[0]: %p/%lx -> %lx/%lx\n",
1237 1.1 is acb->ds.chain[0].databuf,
1238 1.1 is acb->ds.chain[0].datalen,
1239 1.1 is acb->iob_curbuf,
1240 1.1 is acb->iob_curlen);
1241 1.1 is #endif
1242 1.1 is acb->ds.chain[0].databuf = (char *)acb->iob_curbuf;
1243 1.1 is acb->ds.chain[0].datalen = acb->iob_curlen;
1244 1.1 is for (j = 1, ++i; i < DMAMAXIO && acb->ds.chain[i].datalen; ++i, ++j) {
1245 1.1 is #ifdef DEBUG
1246 1.1 is if (siopng_debug & 0x100)
1247 1.1 is printf(" chain[%d]: %p/%lx -> %p/%lx\n", j,
1248 1.1 is acb->ds.chain[j].databuf,
1249 1.1 is acb->ds.chain[j].datalen,
1250 1.1 is acb->ds.chain[i].databuf,
1251 1.1 is acb->ds.chain[i].datalen);
1252 1.1 is #endif
1253 1.1 is acb->ds.chain[j].databuf = acb->ds.chain[i].databuf;
1254 1.1 is acb->ds.chain[j].datalen = acb->ds.chain[i].datalen;
1255 1.1 is }
1256 1.1 is if (j < DMAMAXIO)
1257 1.1 is acb->ds.chain[j].datalen = 0;
1258 1.1 is DCIAS(kvtop((caddr_t)&acb->ds.chain));
1259 1.1 is }
1260 1.1 is ++sc->sc_tinfo[target].dconns;
1261 1.1 is /*
1262 1.1 is * add nexus to waiting list
1263 1.1 is * clear nexus
1264 1.1 is * try to start another command for another target/lun
1265 1.1 is */
1266 1.1 is acb->status = sc->sc_flags & SIOP_INTSOFF;
1267 1.1 is TAILQ_INSERT_HEAD(&sc->nexus_list, acb, chain);
1268 1.1 is sc->sc_nexus = NULL; /* no current device */
1269 1.1 is /* start script to wait for reselect */
1270 1.1 is if (sc->sc_nexus == NULL)
1271 1.1 is rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1272 1.1 is /* XXXX start another command ? */
1273 1.1 is if (sc->ready_list.tqh_first)
1274 1.1 is siopng_sched(sc);
1275 1.1 is #if 0
1276 1.1 is else
1277 1.1 is rp->siop_dcntl |= SIOP_DCNTL_STD;
1278 1.1 is #endif
1279 1.1 is return (0);
1280 1.1 is }
1281 1.1 is if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff03) {
1282 1.1 is int reselid = rp->siop_scratcha & 0x7f;
1283 1.1 is int reselun = rp->siop_sfbr & 0x07;
1284 1.1 is
1285 1.1 is sc->sc_sstat1 = rp->siop_sbcl; /* XXXX save current SBCL */
1286 1.1 is #ifdef DEBUG
1287 1.1 is if (siopng_debug & 0x100)
1288 1.1 is printf ("%s: target ID %02x reselected dsps %lx\n",
1289 1.1 is sc->sc_dev.dv_xname, reselid,
1290 1.1 is rp->siop_dsps);
1291 1.1 is if ((rp->siop_sfbr & 0x80) == 0)
1292 1.1 is printf("%s: Reselect message in was not identify: %x\n",
1293 1.1 is sc->sc_dev.dv_xname, rp->siop_sfbr);
1294 1.1 is #endif
1295 1.1 is if (sc->sc_nexus) {
1296 1.1 is #ifdef DEBUG
1297 1.1 is if (siopng_debug & 0x100)
1298 1.1 is printf ("%s: reselect ID %02x w/active\n",
1299 1.1 is sc->sc_dev.dv_xname, reselid);
1300 1.1 is #endif
1301 1.1 is TAILQ_INSERT_HEAD(&sc->ready_list, sc->sc_nexus, chain);
1302 1.1 is sc->sc_tinfo[sc->sc_nexus->xs->sc_link->scsipi_scsi.target].lubusy
1303 1.1 is &= ~(1 << sc->sc_nexus->xs->sc_link->scsipi_scsi.lun);
1304 1.1 is --sc->sc_active;
1305 1.1 is }
1306 1.1 is /*
1307 1.1 is * locate acb of reselecting device
1308 1.1 is * set sc->sc_nexus to acb
1309 1.1 is */
1310 1.1 is for (acb = sc->nexus_list.tqh_first; acb;
1311 1.1 is acb = acb->chain.tqe_next) {
1312 1.1 is if (reselid != ((acb->ds.scsi_addr >> 16) & 0xff) ||
1313 1.1 is reselun != (acb->msgout[0] & 0x07))
1314 1.1 is continue;
1315 1.1 is TAILQ_REMOVE(&sc->nexus_list, acb, chain);
1316 1.1 is sc->sc_nexus = acb;
1317 1.1 is sc->sc_flags |= acb->status;
1318 1.1 is acb->status = 0;
1319 1.1 is DCIAS(kvtop(&acb->stat[0]));
1320 1.1 is rp->siop_dsa = kvtop((caddr_t)&acb->ds);
1321 1.1 is rp->siop_sxfer =
1322 1.1 is sc->sc_sync[acb->xs->sc_link->scsipi_scsi.target].sxfer;
1323 1.1 is #ifndef FIXME
1324 1.1 is rp->siop_scntl3 =
1325 1.1 is sc->sc_sync[acb->xs->sc_link->scsipi_scsi.target].sbcl;
1326 1.1 is #endif
1327 1.1 is break;
1328 1.1 is }
1329 1.1 is if (acb == NULL) {
1330 1.1 is printf("%s: target ID %02x reselect nexus_list %p\n",
1331 1.1 is sc->sc_dev.dv_xname, reselid,
1332 1.1 is sc->nexus_list.tqh_first);
1333 1.1 is panic("unable to find reselecting device");
1334 1.1 is }
1335 1.1 is dma_cachectl ((caddr_t)acb, sizeof(*acb));
1336 1.1 is rp->siop_temp = 0;
1337 1.1 is rp->siop_dcntl |= SIOP_DCNTL_STD;
1338 1.1 is return (0);
1339 1.1 is }
1340 1.1 is if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff04) {
1341 1.1 is #ifdef DEBUG
1342 1.1 is u_short ctest2 = rp->siop_ctest2;
1343 1.1 is
1344 1.1 is /* reselect was interrupted (by Sig_P or select) */
1345 1.1 is if (siopng_debug & 0x100 ||
1346 1.1 is (ctest2 & SIOP_CTEST2_SIGP) == 0)
1347 1.1 is printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x istat %x/%x\n",
1348 1.1 is sc->sc_dev.dv_xname, rp->siop_scntl1,
1349 1.1 is ctest2, rp->siop_sfbr, istat, rp->siop_istat);
1350 1.1 is #endif
1351 1.1 is /* XXX assumes it was not select */
1352 1.1 is if (sc->sc_nexus == NULL) {
1353 1.1 is #ifdef DEBUG
1354 1.1 is printf("%s: reselect interrupted, sc_nexus == NULL\n",
1355 1.1 is sc->sc_dev.dv_xname);
1356 1.1 is #if 0
1357 1.1 is siopng_dump(sc);
1358 1.1 is #ifdef DDB
1359 1.1 is Debugger();
1360 1.1 is #endif
1361 1.1 is #endif
1362 1.1 is #endif
1363 1.1 is rp->siop_dcntl |= SIOP_DCNTL_STD;
1364 1.1 is return(0);
1365 1.1 is }
1366 1.1 is target = sc->sc_nexus->xs->sc_link->scsipi_scsi.target;
1367 1.1 is rp->siop_temp = 0;
1368 1.1 is rp->siop_dsa = kvtop((caddr_t)&sc->sc_nexus->ds);
1369 1.1 is rp->siop_sxfer = sc->sc_sync[target].sxfer;
1370 1.1 is #ifndef FIXME
1371 1.1 is rp->siop_scntl3 = sc->sc_sync[target].sbcl;
1372 1.1 is #endif
1373 1.1 is rp->siop_dsp = sc->sc_scriptspa;
1374 1.1 is return (0);
1375 1.1 is }
1376 1.1 is if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff06) {
1377 1.1 is if (acb == NULL)
1378 1.1 is printf("%s: Bad message-in with no active command?\n",
1379 1.1 is sc->sc_dev.dv_xname);
1380 1.1 is /* Unrecognized message in byte */
1381 1.1 is dma_cachectl (&acb->msg[1],1);
1382 1.1 is printf ("%s: Unrecognized message in data sfbr %x msg %x sbcl %x\n",
1383 1.1 is sc->sc_dev.dv_xname, rp->siop_sfbr, acb->msg[1], rp->siop_sbcl);
1384 1.1 is /* what should be done here? */
1385 1.1 is DCIAS(kvtop(&acb->msg[1]));
1386 1.1 is rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
1387 1.1 is return (0);
1388 1.1 is }
1389 1.1 is if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0a) {
1390 1.1 is /* Status phase wasn't followed by message in phase? */
1391 1.1 is printf ("%s: Status phase not followed by message in phase? sbcl %x sbdl %x\n",
1392 1.1 is sc->sc_dev.dv_xname, rp->siop_sbcl, rp->siop_sbdl);
1393 1.1 is if (rp->siop_sbcl == 0xa7) {
1394 1.1 is /* It is now, just continue the script? */
1395 1.1 is rp->siop_dcntl |= SIOP_DCNTL_STD;
1396 1.1 is return (0);
1397 1.1 is }
1398 1.1 is }
1399 1.1 is if (sist == 0 && dstat & SIOP_DSTAT_SIR) {
1400 1.1 is dma_cachectl (&acb->stat[0], 1);
1401 1.1 is dma_cachectl (&acb->msg[0], 1);
1402 1.1 is printf ("SIOP interrupt: %lx sts %x msg %x %x sbcl %x\n",
1403 1.1 is rp->siop_dsps, acb->stat[0], acb->msg[0], acb->msg[1],
1404 1.1 is rp->siop_sbcl);
1405 1.1 is siopngreset (sc);
1406 1.1 is *status = -1;
1407 1.1 is return 0; /* siopngreset has cleaned up */
1408 1.1 is }
1409 1.1 is if (sist & SIOP_SIST_SGE)
1410 1.1 is printf ("SIOP: SCSI Gross Error\n");
1411 1.1 is if (sist & SIOP_SIST_PAR)
1412 1.1 is printf ("SIOP: Parity Error\n");
1413 1.1 is if (dstat & SIOP_DSTAT_IID)
1414 1.1 is printf ("SIOP: Invalid instruction detected\n");
1415 1.1 is bad_phase:
1416 1.1 is /*
1417 1.1 is * temporary panic for unhandled conditions
1418 1.1 is * displays various things about the 53C720/770 status and registers
1419 1.1 is * then panics.
1420 1.1 is * XXXX need to clean this up to print out the info, reset, and continue
1421 1.1 is */
1422 1.1 is printf ("siopngchkintr: target %x ds %p\n", target, &acb->ds);
1423 1.1 is printf ("scripts %lx ds %x rp %x dsp %lx dcmd %lx\n", sc->sc_scriptspa,
1424 1.1 is kvtop((caddr_t)&acb->ds), kvtop((caddr_t)rp), rp->siop_dsp,
1425 1.1 is *((long *)&rp->siop_dcmd));
1426 1.1 is printf ("siopngchkintr: istat %x dstat %x sist %x dsps %lx dsa %lx sbcl %x sts %x msg %x %x sfbr %x\n",
1427 1.1 is istat, dstat, sist, rp->siop_dsps, rp->siop_dsa,
1428 1.1 is rp->siop_sbcl, acb->stat[0], acb->msg[0], acb->msg[1], rp->siop_sfbr);
1429 1.1 is #ifdef DEBUG
1430 1.1 is if (siopng_debug & 0x20)
1431 1.1 is panic("siopngchkintr: **** temp ****");
1432 1.1 is #endif
1433 1.1 is #ifdef DDB
1434 1.1 is Debugger ();
1435 1.1 is #endif
1436 1.1 is siopngreset (sc); /* hard reset */
1437 1.1 is *status = -1;
1438 1.1 is return 0; /* siopngreset cleaned up */
1439 1.1 is }
1440 1.1 is
1441 1.1 is void
1442 1.1 is siopng_select(sc)
1443 1.1 is struct siop_softc *sc;
1444 1.1 is {
1445 1.1 is siop_regmap_p rp;
1446 1.1 is struct siop_acb *acb = sc->sc_nexus;
1447 1.1 is
1448 1.1 is #ifdef DEBUG
1449 1.1 is if (siopng_debug & 1)
1450 1.1 is printf ("%s: select ", sc->sc_dev.dv_xname);
1451 1.1 is #endif
1452 1.1 is
1453 1.1 is rp = sc->sc_siopp;
1454 1.1 is if (acb->xs->flags & SCSI_POLL || siopng_no_dma) {
1455 1.1 is sc->sc_flags |= SIOP_INTSOFF;
1456 1.1 is sc->sc_flags &= ~SIOP_INTDEFER;
1457 1.1 is if ((rp->siop_istat & 0x08) == 0) {
1458 1.1 is rp->siop_sien = 0;
1459 1.1 is rp->siop_dien = 0;
1460 1.1 is }
1461 1.1 is #if 0
1462 1.1 is } else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
1463 1.1 is sc->sc_flags &= ~SIOP_INTSOFF;
1464 1.1 is if ((rp->siop_istat & 0x08) == 0) {
1465 1.1 is rp->siop_sien = sc->sc_sien;
1466 1.1 is rp->siop_dien = sc->sc_dien;
1467 1.1 is }
1468 1.1 is #endif
1469 1.1 is }
1470 1.1 is #ifdef DEBUG
1471 1.1 is if (siopng_debug & 1)
1472 1.1 is printf ("siopng_select: target %x cmd %02x ds %p\n",
1473 1.1 is acb->xs->sc_link->scsipi_scsi.target, acb->cmd.opcode,
1474 1.1 is &sc->sc_nexus->ds);
1475 1.1 is #endif
1476 1.1 is
1477 1.1 is siopng_start(sc, acb->xs->sc_link->scsipi_scsi.target,
1478 1.1 is acb->xs->sc_link->scsipi_scsi.lun,
1479 1.1 is (u_char *)&acb->cmd, acb->clen, acb->daddr, acb->dleft);
1480 1.1 is
1481 1.1 is return;
1482 1.1 is }
1483 1.1 is
1484 1.1 is /*
1485 1.1 is * 53C720/770 interrupt handler
1486 1.1 is */
1487 1.1 is
1488 1.1 is void
1489 1.1 is siopngintr (sc)
1490 1.1 is register struct siop_softc *sc;
1491 1.1 is {
1492 1.1 is siop_regmap_p rp;
1493 1.1 is u_char istat, dstat;
1494 1.1 is u_short sist;
1495 1.1 is int status;
1496 1.1 is int s = splbio();
1497 1.1 is
1498 1.1 is istat = sc->sc_istat;
1499 1.1 is if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
1500 1.1 is splx(s);
1501 1.1 is return;
1502 1.1 is }
1503 1.1 is
1504 1.1 is /* Got a valid interrupt on this device */
1505 1.1 is rp = sc->sc_siopp;
1506 1.1 is dstat = sc->sc_dstat;
1507 1.1 is sist = sc->sc_sist;
1508 1.1 is if (dstat & SIOP_DSTAT_SIR)
1509 1.1 is sc->sc_intcode = rp->siop_dsps;
1510 1.1 is sc->sc_istat = 0;
1511 1.1 is #ifdef DEBUG
1512 1.1 is if (siopng_debug & 1)
1513 1.1 is printf ("%s: intr istat %x dstat %x sist %x\n",
1514 1.1 is sc->sc_dev.dv_xname, istat, dstat, sist);
1515 1.1 is if (!sc->sc_active) {
1516 1.1 is printf ("%s: spurious interrupt? istat %x dstat %x sist %x nexus %p status %x\n",
1517 1.1 is sc->sc_dev.dv_xname, istat, dstat, sist,
1518 1.1 is sc->sc_nexus, sc->sc_nexus ? sc->sc_nexus->stat[0] : 0);
1519 1.1 is }
1520 1.1 is #endif
1521 1.1 is
1522 1.1 is #ifdef DEBUG
1523 1.1 is if (siopng_debug & 5) {
1524 1.1 is DCIAS(kvtop(&sc->sc_nexus->stat[0]));
1525 1.1 is printf ("%s: intr istat %x dstat %x sist %x dsps %lx sbcl %x sts %x msg %x\n",
1526 1.1 is sc->sc_dev.dv_xname, istat, dstat, sist,
1527 1.1 is rp->siop_dsps, rp->siop_sbcl,
1528 1.1 is sc->sc_nexus->stat[0], sc->sc_nexus->msg[0]);
1529 1.1 is }
1530 1.1 is #endif
1531 1.1 is if (sc->sc_flags & SIOP_INTDEFER) {
1532 1.1 is sc->sc_flags &= ~(SIOP_INTDEFER | SIOP_INTSOFF);
1533 1.1 is rp->siop_sien = sc->sc_sien;
1534 1.1 is rp->siop_dien = sc->sc_dien;
1535 1.1 is }
1536 1.1 is if (siopng_checkintr (sc, istat, dstat, sist, &status)) {
1537 1.1 is #if 1
1538 1.1 is if (status == 0xff)
1539 1.1 is printf ("siopngintr: status == 0xff\n");
1540 1.1 is #endif
1541 1.1 is if ((sc->sc_flags & (SIOP_INTSOFF | SIOP_INTDEFER)) != SIOP_INTSOFF) {
1542 1.1 is #if 0
1543 1.1 is if (rp->siop_sbcl & SIOP_BSY) {
1544 1.1 is printf ("%s: SCSI bus busy at completion",
1545 1.1 is sc->sc_dev.dv_xname);
1546 1.1 is printf(" targ %d sbcl %02x sfbr %x respid %02x dsp +%x\n",
1547 1.1 is sc->sc_nexus->xs->sc_link->scsipi_scsi.target,
1548 1.1 is rp->siop_sbcl, rp->siop_sfbr, rp->siop_respid,
1549 1.1 is rp->siop_dsp - sc->sc_scriptspa);
1550 1.1 is }
1551 1.1 is #endif
1552 1.1 is siopng_scsidone(sc->sc_nexus, sc->sc_nexus ?
1553 1.1 is sc->sc_nexus->stat[0] : -1);
1554 1.1 is }
1555 1.1 is }
1556 1.1 is splx(s);
1557 1.1 is }
1558 1.1 is
1559 1.1 is /*
1560 1.1 is * This is based on the Progressive Peripherals 33Mhz Zeus driver and will
1561 1.1 is * not be correct for other 53c710 boards.
1562 1.1 is *
1563 1.1 is */
1564 1.1 is void
1565 1.1 is scsi_period_to_siopng (sc, target)
1566 1.1 is struct siop_softc *sc;
1567 1.1 is int target;
1568 1.1 is {
1569 1.1 is int period, offset, sxfer, scntl3 = 0;
1570 1.1 is #ifdef DEBUG_SYNC
1571 1.1 is #ifdef FIXME
1572 1.1 is int i;
1573 1.1 is #endif
1574 1.1 is #endif
1575 1.1 is
1576 1.1 is period = sc->sc_nexus->msg[4];
1577 1.1 is offset = sc->sc_nexus->msg[5];
1578 1.1 is #ifdef FIXME
1579 1.1 is #ifdef DEBUG_SYNC
1580 1.1 is sxfer = 0;
1581 1.1 is if (offset <= SIOP_MAX_OFFSET)
1582 1.1 is sxfer = offset;
1583 1.1 is else
1584 1.1 is sxfer = SIOP_MAX_OFFSET;
1585 1.1 is for (i = 0; i < sizeof (sync_tab) / 2; ++i) {
1586 1.1 is if (period <= sync_tab[i].p) {
1587 1.1 is sxfer |= sync_tab[i].r & 0x70;
1588 1.1 is scntl3 = sync_tab[i].r & 0x03;
1589 1.1 is break;
1590 1.1 is }
1591 1.1 is }
1592 1.1 is printf ("siopng sync old: siop_sxfr %02x, siop_scntl3 %02x\n", sxfer, scntl3);
1593 1.1 is #endif /* DEBUG_SYNC */
1594 1.1 is for (scntl3 = 1; scntl3 < 4; ++scntl3) {
1595 1.1 is sxfer = (period * 4 - 1) / sc->sc_tcp[scntl3] - 3;
1596 1.1 is if (sxfer >= 0 && sxfer <= 7)
1597 1.1 is break;
1598 1.1 is }
1599 1.1 is if (scntl3 > 3) {
1600 1.1 is printf("siopng sync: unable to compute sync params for period %dns\n",
1601 1.1 is period * 4);
1602 1.1 is /*
1603 1.1 is * XXX need to pick a value we can do and renegotiate
1604 1.1 is */
1605 1.1 is sxfer = scntl3 = 0;
1606 1.1 is } else {
1607 1.1 is sxfer = (sxfer << 4) | ((offset <= SIOP_MAX_OFFSET) ?
1608 1.1 is offset : SIOP_MAX_OFFSET);
1609 1.1 is #ifdef DEBUG_SYNC
1610 1.1 is printf("siopng sync: params for period %dns: sxfer %x scntl3 %x",
1611 1.1 is period * 4, sxfer, scntl3);
1612 1.1 is printf(" actual period %dns\n",
1613 1.1 is sc->sc_tcp[scntl3] * ((sxfer >> 4) + 4));
1614 1.1 is #endif /* DEBUG_SYNC */
1615 1.1 is }
1616 1.1 is #else /* FIXME */
1617 1.1 is sxfer = offset <= SIOP_MAX_OFFSET ? offset : SIOP_MAX_OFFSET;
1618 1.1 is sxfer |= 0xc0; /* XXX */
1619 1.1 is #ifndef FIXME
1620 1.1 is scntl3 = 0x15;
1621 1.1 is #else
1622 1.1 is scntl3 = 5;
1623 1.1 is #endif
1624 1.1 is #endif
1625 1.1 is sc->sc_sync[target].sxfer = sxfer;
1626 1.1 is sc->sc_sync[target].sbcl = scntl3;
1627 1.1 is #ifdef DEBUG_SYNC
1628 1.1 is printf ("siopng sync: siop_sxfr %02x, siop_scntl3 %02x\n", sxfer, scntl3);
1629 1.1 is #endif
1630 1.1 is }
1631 1.1 is
1632 1.1 is void
1633 1.1 is siopng_dump_registers(sc)
1634 1.1 is struct siop_softc *sc;
1635 1.1 is {
1636 1.1 is siop_regmap_p rp = sc->sc_siopp;
1637 1.1 is
1638 1.1 is printf(" scntl0 %02x scntl1 %02x scntl2 %02x scntl3 %02x\n",
1639 1.1 is rp->siop_scntl0, rp->siop_scntl1, rp->siop_scntl2, rp->siop_scntl3);
1640 1.1 is printf(" scid %02x sxfer %02x sdid %02x gpreg %02x\n",
1641 1.1 is rp->siop_scid, rp->siop_sxfer, rp->siop_sdid, rp->siop_gpreg);
1642 1.1 is printf(" sfbr %02x socl %02x ssid %02x sbcl %02x\n",
1643 1.1 is rp->siop_sfbr, rp->siop_socl, rp->siop_ssid, rp->siop_sbcl);
1644 1.1 is printf(" dstat %02x sstat0 %02x sstat1 %02x sstat2 %02x\n",
1645 1.1 is rp->siop_dstat, rp->siop_sstat0, rp->siop_sstat1, rp->siop_sstat2);
1646 1.1 is printf(" ctest0 %02x ctest1 %02x ctest2 %02x ctest3 %02x\n",
1647 1.1 is rp->siop_ctest0, rp->siop_ctest1, rp->siop_ctest2, rp->siop_ctest3);
1648 1.1 is printf(" dfifo %02x ctest4 %02x ctest5 %02x ctest6 %02x\n",
1649 1.1 is 0, rp->siop_ctest4, rp->siop_ctest5, rp->siop_ctest6);
1650 1.1 is printf(" dcmd %02x dbc2 %02x dbc1 %02x dbc0 %02x\n",
1651 1.1 is rp->siop_dcmd, rp->siop_dbc2, rp->siop_dbc1, rp->siop_dbc0);
1652 1.1 is printf(" dmode %02x dien %02x dwt %02x dcntl %02x\n",
1653 1.1 is rp->siop_dmode, rp->siop_dien, rp->siop_dwt, rp->siop_dcntl);
1654 1.1 is printf(" stest0 %02x stest1 %02x stest2 %02x stest3 %02x\n",
1655 1.1 is rp->siop_stest0, rp->siop_stest1, rp->siop_stest2, rp->siop_stest3);
1656 1.1 is printf(" istat %02x sien %04x sist %04x respid %04x\n",
1657 1.1 is rp->siop_istat, rp->siop_sien, rp->siop_sist, rp->siop_respid);
1658 1.1 is printf(" sidl %04x sodl %04x sbdl %04x\n",
1659 1.1 is rp->siop_sidl, rp->siop_sodl, rp->siop_sbdl);
1660 1.1 is printf(" dsps %08lx dsp %08lx (+%lx)\n",
1661 1.1 is rp->siop_dsps, rp->siop_dsp, rp->siop_dsp > sc->sc_scriptspa ?
1662 1.1 is rp->siop_dsp - sc->sc_scriptspa : 0);
1663 1.1 is printf(" dsa %08lx temp %08lx dnad %08lx\n",
1664 1.1 is rp->siop_dsa, rp->siop_temp, rp->siop_dnad);
1665 1.1 is printf(" scratcha %08lx scratchb %08lx adder %08lx\n",
1666 1.1 is rp->siop_scratcha, rp->siop_scratchb, rp->siop_adder);
1667 1.1 is }
1668 1.1 is
1669 1.1 is #ifdef DEBUG
1670 1.1 is
1671 1.1 is #if SIOP_TRACE_SIZE
1672 1.1 is void
1673 1.1 is siopng_dump_trace()
1674 1.1 is {
1675 1.1 is int i;
1676 1.1 is
1677 1.1 is printf("siopng trace: next index %d\n", siopng_trix);
1678 1.1 is i = siopng_trix;
1679 1.1 is do {
1680 1.1 is printf("%3d: '%c' %02x %02x %02x\n", i, siopng_trbuf[i],
1681 1.1 is siopng_trbuf[i + 1], siopng_trbuf[i + 2], siopng_trbuf[i + 3]);
1682 1.1 is i = (i + 4) & (SIOP_TRACE_SIZE - 1);
1683 1.1 is } while (i != siopng_trix);
1684 1.1 is }
1685 1.1 is #endif
1686 1.1 is
1687 1.1 is void
1688 1.1 is siopng_dump_acb(acb)
1689 1.1 is struct siop_acb *acb;
1690 1.1 is {
1691 1.1 is u_char *b = (u_char *) &acb->cmd;
1692 1.1 is int i;
1693 1.1 is
1694 1.1 is printf("acb@%p ", acb);
1695 1.1 is if (acb->xs == NULL) {
1696 1.1 is printf("<unused>\n");
1697 1.1 is return;
1698 1.1 is }
1699 1.1 is printf("(%d:%d) flags %2x clen %2d cmd ",
1700 1.1 is acb->xs->sc_link->scsipi_scsi.target,
1701 1.1 is acb->xs->sc_link->scsipi_scsi.lun, acb->flags, acb->clen);
1702 1.1 is for (i = acb->clen; i; --i)
1703 1.1 is printf(" %02x", *b++);
1704 1.1 is printf("\n");
1705 1.1 is printf(" xs: %p data %p:%04x ", acb->xs, acb->xs->data,
1706 1.1 is acb->xs->datalen);
1707 1.1 is printf("va %p:%lx ", acb->iob_buf, acb->iob_len);
1708 1.1 is printf("cur %lx:%lx\n", acb->iob_curbuf, acb->iob_curlen);
1709 1.1 is }
1710 1.1 is
1711 1.1 is void
1712 1.1 is siopng_dump(sc)
1713 1.1 is struct siop_softc *sc;
1714 1.1 is {
1715 1.1 is struct siop_acb *acb;
1716 1.1 is siop_regmap_p rp = sc->sc_siopp;
1717 1.1 is int s;
1718 1.1 is int i;
1719 1.1 is
1720 1.1 is s = splbio();
1721 1.1 is #if SIOP_TRACE_SIZE
1722 1.1 is siopng_dump_trace();
1723 1.1 is #endif
1724 1.1 is printf("%s@%p regs %p istat %x\n",
1725 1.1 is sc->sc_dev.dv_xname, sc, rp, rp->siop_istat);
1726 1.1 is if ((acb = sc->free_list.tqh_first) > 0) {
1727 1.1 is printf("Free list:\n");
1728 1.1 is while (acb) {
1729 1.1 is siopng_dump_acb(acb);
1730 1.1 is acb = acb->chain.tqe_next;
1731 1.1 is }
1732 1.1 is }
1733 1.1 is if ((acb = sc->ready_list.tqh_first) > 0) {
1734 1.1 is printf("Ready list:\n");
1735 1.1 is while (acb) {
1736 1.1 is siopng_dump_acb(acb);
1737 1.1 is acb = acb->chain.tqe_next;
1738 1.1 is }
1739 1.1 is }
1740 1.1 is if ((acb = sc->nexus_list.tqh_first) > 0) {
1741 1.1 is printf("Nexus list:\n");
1742 1.1 is while (acb) {
1743 1.1 is siopng_dump_acb(acb);
1744 1.1 is acb = acb->chain.tqe_next;
1745 1.1 is }
1746 1.1 is }
1747 1.1 is if (sc->sc_nexus) {
1748 1.1 is printf("Nexus:\n");
1749 1.1 is siopng_dump_acb(sc->sc_nexus);
1750 1.1 is }
1751 1.1 is for (i = 0; i < 8; ++i) {
1752 1.1 is if (sc->sc_tinfo[i].cmds > 2) {
1753 1.1 is printf("tgt %d: cmds %d disc %d senses %d lubusy %x\n",
1754 1.1 is i, sc->sc_tinfo[i].cmds,
1755 1.1 is sc->sc_tinfo[i].dconns,
1756 1.1 is sc->sc_tinfo[i].senses,
1757 1.1 is sc->sc_tinfo[i].lubusy);
1758 1.1 is }
1759 1.1 is }
1760 1.1 is splx(s);
1761 1.1 is }
1762 1.1 is #endif
1763