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