summaryrefslogtreecommitdiff
path: root/sys/arch/sun3/dev/ncr_si.c
blob: 951e37340d60d0b68d3f85fb5572ade65ced845f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
/*	$NetBSD: ncr_si.c,v 1.1 1995/10/29 21:19:11 gwr Exp $	*/

/*
 * Copyright (c) 1995 David Jones
 * Copyright (c) 1994 Adam Glass, Gordon W. Ross
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the authors may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 * 4. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by
 *      Adam Glass, David Jones and Gordon Ross
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * This file contains only the machine-dependent parts of the
 * Sun3 SCSI driver.  (Autoconfig stuff and DMA functions.)
 * The machine-independent parts are in ncr5380sbc.c
 */

#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/device.h>

#include <scsi/scsi_all.h>
#include <scsi/scsi_debug.h>
#include <scsi/scsiconf.h>

#include <machine/autoconf.h>
#include <machine/isr.h>
#include <machine/obio.h>
#include <machine/dvma.h>

#if 0	/* XXX - not yet... */
#include <dev/ic/ncr5380reg.h>
#include <dev/ic/ncr5380var.h>
#else
#include "ncr5380reg.h"
#include "ncr5380var.h"
#endif

#include "ncr_sireg.h"
#include "am9516.h"

/*
 * Transfers smaller than this are done using PIO
 * (on assumption they're not worth DMA overhead)
 */
#define	MIN_DMA_LEN 128

/*
 * Transfers lager than 63K need to be broken up
 * because some of the device counters are 16 bits.
 */
#define	MAX_DMA_LEN 0xFC00

/*
 * How many uS. to delay after touching the am9616 UDC.
 */
#define UDC_WAIT_USEC 5

#define DEBUG XXX

#ifdef	DEBUG
int si_debug = 0;
static int si_flags = 0 /* | SDEV_DB2 */ ;
static int Seq = 0;
static int Nwrite = 0;
struct si_softc *TheSoftC;
volatile struct si_regs *TheRegs;
void log_intr(void);
void log_start(void);
void si_printregs(void);
#endif

/*
 * This structure is used to keep track of mapped DMA requests.
 * Note: combined the UDC command block with this structure, so
 * the array of these has to be in DVMA space.
 */
struct si_dma_handle {
	u_long		dh_addr;	/* KVA of start of buffer */
	int 		dh_len;		/* Original data length */
	u_long		dh_dvma;	/* VA of buffer in DVMA space */
	int 		dh_flags;
#define	SIDH_BUSY	1		/* This DH is in use */
#define	SIDH_OUT	2		/* DMA does data out (write) */
	/* DMA command block for the OBIO controller. */
	struct udc_table dh_cmd;
};

/*
 * The first structure member has to be the ncr5380_softc
 * so we can just cast to go back and fourth between them.
 */
struct si_softc {
	struct ncr5380_softc	ncr;
	volatile struct si_regs	*sc_regs;
	int		sc_adapter_type;
	int		sc_adapter_iv_am; /* int. vec + address modifier */
	int		sc_timo;
	struct si_dma_handle *sc_dma;
};

/*
 * XXX: Note that reselect CAN NOT WORK given the current need
 * to set the damn FIFO count logic during dma_alloc, because
 * the DMA might be need by another target in the mean time.
 * (It works when there is only one target/lun though...)
 */
int si_permit_reselect = 0;	/* XXX: Do not set this yet. */
int si_polled_dma = 0;	/* Set if interrupts don't work */

/* How long to wait for DMA before declaring an error. */
int si_dma_intr_timo = 500;	/* ticks (sec. X 100) */

static char si_name[] = "si";
static int	si_match();
static void	si_attach();
static int	si_intr(void *arg);
static void	si_reset_adapter(struct ncr5380_softc *sc);
static void	si_minphys(struct buf *bp);

void si_dma_alloc __P((struct ncr5380_softc *));
void si_dma_free __P((struct ncr5380_softc *));
void si_dma_poll __P((struct ncr5380_softc *));

void si_vme_dma_start __P((struct ncr5380_softc *));
void si_vme_dma_eop __P((struct ncr5380_softc *));
void si_vme_dma_stop __P((struct ncr5380_softc *));

void si_obio_dma_start __P((struct ncr5380_softc *));
void si_obio_dma_eop __P((struct ncr5380_softc *));
void si_obio_dma_stop __P((struct ncr5380_softc *));


static struct scsi_adapter	si_ops = {
	ncr5380_scsi_cmd,		/* scsi_cmd()		*/
	si_minphys,			/* scsi_minphys()	*/
	NULL,				/* open_target_lu()	*/
	NULL,				/* close_target_lu()	*/
};

/* This is copied from julian's bt driver */
/* "so we have a default dev struct for our link struct." */
static struct scsi_device si_dev = {
	NULL,		/* Use default error handler.	    */
	NULL,		/* Use default start handler.		*/
	NULL,		/* Use default async handler.	    */
	NULL,		/* Use default "done" routine.	    */
};


struct cfdriver ncr_sicd = {
	NULL, si_name, si_match, si_attach, DV_DULL,
	sizeof(struct si_softc), NULL, 0,
};

static int
si_print(aux, name)
	void *aux;
	char *name;
{
	if (name != NULL)
		printf("%s: scsibus ", name);
	return UNCONF;
}

static int
si_match(parent, vcf, args)
	struct device	*parent;
	void		*vcf, *args;
{
	struct cfdata	*cf = vcf;
	struct confargs *ca = args;
	int x, probe_addr;

	/* Default interrupt priority always splbio==2 */
	if (ca->ca_intpri == -1)
		ca->ca_intpri = 2;

	if ((cpu_machine_id == SUN3_MACH_50) ||
	    (cpu_machine_id == SUN3_MACH_60) )
	{
		/* Sun3/50 or Sun3/60 have only OBIO "si" */
		if (ca->ca_bustype != BUS_OBIO)
			return(0);
		if (ca->ca_paddr == -1)
			ca->ca_paddr = OBIO_NCR_SCSI;
		/* OK... */
	} else {
		/* Other Sun3 models may have VME "si" or "sc" */
		if (ca->ca_bustype != BUS_VME16)
			return (0);
		if (ca->ca_paddr == -1)
			return (0);
		/* OK... */
	}

	/* Make sure there is something there... */
	x = bus_peek(ca->ca_bustype, ca->ca_paddr + 1, 1);
	if (x == -1)
		return (0);

	/*
	 * If this is a VME SCSI board, we have to determine whether
	 * it is an "sc" (Sun2) or "si" (Sun3) SCSI board.  This can
	 * be determined using the fact that the "sc" board occupies
	 * 4K bytes in VME space but the "si" board occupies 2K bytes.
	 */
	if (ca->ca_bustype == BUS_VME16) {
		/* Note, the "si" board should NOT respond here. */
		x = bus_peek(ca->ca_bustype, ca->ca_paddr + 0x801, 1);
		if (x != -1)
			return(0);
	}

    return (1);
}

static void
si_attach(parent, self, args)
	struct device	*parent, *self;
	void		*args;
{
	struct si_softc *sc = (struct si_softc *) self;
	volatile struct si_regs *regs;
	struct confargs *ca = args;
	int i;

	switch (ca->ca_bustype) {

	case BUS_OBIO:
		regs = (struct si_regs *)
			obio_alloc(ca->ca_paddr, sizeof(*regs));
		isr_add_autovect(si_intr, (void *)sc,
						 ca->ca_intpri);
		break;

	case BUS_VME16:
		regs = (struct si_regs *)
			bus_mapin(ca->ca_bustype, ca->ca_paddr, sizeof(*regs));
		isr_add_vectored(si_intr, (void *)sc,
						 ca->ca_intpri, ca->ca_intvec);
		sc->sc_adapter_iv_am =
			VME_SUPV_DATA_24 | (ca->ca_intvec & 0xFF);
		break;

	default:
		printf("unknown\n");
		return;
	}
	printf("\n");

	/*
	 * Fill in the prototype scsi_link.
	 */
	sc->ncr.sc_link.adapter_softc = sc;
	sc->ncr.sc_link.adapter_target = 7;
	sc->ncr.sc_link.adapter = &si_ops;
	sc->ncr.sc_link.device = &si_dev;

	/*
	 * Initialize fields used by the MI code
	 */
	sc->ncr.sci_data = &regs->sci.sci_data;
	sc->ncr.sci_icmd = &regs->sci.sci_icmd;
	sc->ncr.sci_mode = &regs->sci.sci_mode;
	sc->ncr.sci_tcmd = &regs->sci.sci_tcmd;
	sc->ncr.sci_bus_csr = &regs->sci.sci_bus_csr;
	sc->ncr.sci_csr = &regs->sci.sci_csr;
	sc->ncr.sci_idata = &regs->sci.sci_idata;
	sc->ncr.sci_iack = &regs->sci.sci_iack;

	/*
	 * MD function pointers used by the MI code.
	 */
	sc->ncr.sc_pio_out = ncr5380_pio_out;
	sc->ncr.sc_pio_in =  ncr5380_pio_in;
	sc->ncr.sc_dma_alloc = si_dma_alloc;
	sc->ncr.sc_dma_free  = si_dma_free;
	sc->ncr.sc_dma_poll  = si_dma_poll;
	if (ca->ca_bustype == BUS_VME16) {
		sc->ncr.sc_dma_start = si_vme_dma_start;
		sc->ncr.sc_dma_eop   = si_vme_dma_stop;
		sc->ncr.sc_dma_stop  = si_vme_dma_stop;
	} else {
		sc->ncr.sc_dma_start = si_obio_dma_start;
		sc->ncr.sc_dma_eop   = si_obio_dma_stop;
		sc->ncr.sc_dma_stop  = si_obio_dma_stop;
	}
	sc->ncr.sc_flags = (si_permit_reselect) ?
		NCR5380_PERMIT_RESELECT : 0;
	sc->ncr.sc_min_dma_len = MIN_DMA_LEN;

	/*
	 * Initialize fields used only here in the MD code.
	 */
	sc->sc_regs = regs;
	sc->sc_adapter_type = ca->ca_bustype;
	/*  sc_adapter_iv_am = (was set above) */
	sc->sc_timo = 0;	/* no timeout armed. */

	/* Need DVMA-capable memory for the UDC command blocks. */
	i = SCI_OPENINGS * sizeof(struct si_dma_handle);
	sc->sc_dma = (struct si_dma_handle *) dvma_malloc(i);
	if (sc->sc_dma == NULL)
		panic("si: dvma_malloc failed\n");
	for (i = 0; i < SCI_OPENINGS; i++)
		sc->sc_dma[i].dh_flags = 0;

#ifdef	DEBUG
	if (si_debug)
		printf("Set TheSoftC=%x TheRegs=%x\n", sc, regs);
	TheSoftC = sc;
	TheRegs = regs;
	sc->ncr.sc_link.flags |= si_flags;
#endif

	/*
	 *  Initialize si board itself.
	 */
	si_reset_adapter(&sc->ncr);
	ncr5380_init(&sc->ncr);
	ncr5380_reset_scsibus(&sc->ncr);
	config_found(self, &(sc->ncr.sc_link), si_print);
}

static void
si_minphys(struct buf *bp)
{
	if (bp->b_bcount > MAX_DMA_LEN) {
		printf("si_minphys len = %x.\n", MAX_DMA_LEN);
		bp->b_bcount = MAX_DMA_LEN;
	}
	return (minphys(bp));
}


static int
si_intr(void *arg)
{
	struct si_softc *sc = arg;
	volatile struct si_regs *si = sc->sc_regs;
	int claimed, rv = 0;

	/* DMA interrupt? */
	if (si->si_csr & SI_CSR_DMA_IP) {
		rv |= SI_CSR_DMA_IP;
		(*sc->ncr.sc_dma_stop)(&sc->ncr);
	}

	/* SBC interrupt? */
	if (si->si_csr & SI_CSR_SBC_IP) {
		rv |= SI_CSR_SBC_IP;
		claimed = ncr5380_sbc_intr(&sc->ncr);
#ifdef	DEBUG
		if (!claimed) {
			printf("si_intr: spurious from SBC\n");
			if (si_debug & 4) {
				Debugger();	/* XXX */
			}
		}
#endif
	}

	return (rv);
}


static void
si_dma_timeout(arg)
	void *arg;
{
	struct si_softc *sc = arg;
	int s;

	s = splbio();

	sc->sc_timo = 0;

	/* Timeout during DMA transfer? */
	if (sc->ncr.sc_dma_flags & DMA5380_INPROGRESS) {
		sc->ncr.sc_dma_flags |= DMA5380_ERROR;
		printf("si: DMA timeout (resetting)\n");
		si_reset_adapter(&sc->ncr);
		ncr5380_sbc_intr(&sc->ncr);
	}

	splx(s);
}


static void
si_reset_adapter(struct ncr5380_softc *ncr)
{
	struct si_softc *sc = (struct si_softc *)ncr;
	volatile struct si_regs *si = sc->sc_regs;

#ifdef	DEBUG
	if (si_debug) {
		printf("si_reset_adapter\n");
	}
#endif

	/*
	 * The SCSI3 controller has an 8K FIFO to buffer data between the
	 * 5380 and the DMA.  Make sure it starts out empty.
	 *
	 * The reset bits in the CSR are active low.
	 */
	si->si_csr = 0;
	delay(10);
	si->si_csr = SI_CSR_FIFO_RES | SI_CSR_SCSI_RES | SI_CSR_INTR_EN;
	delay(10);
	si->fifo_count = 0;

	if (sc->sc_adapter_type == BUS_VME16) {
		si->dma_addrh = 0;
		si->dma_addrl = 0;
		si->dma_counth = 0;
		si->dma_countl = 0;
		si->si_iv_am = sc->sc_adapter_iv_am;
		si->fifo_cnt_hi = 0;
	}

	SCI_CLR_INTR(ncr);
}


/*****************************************************************
 * Common functions for DMA
 ****************************************************************/

/*
 * Allocate a DMA handle and put it in sc->sc_dma.  Prepare
 * for DMA transfer.  On the Sun3, this means mapping the buffer
 * into DVMA space.  dvma_mapin() flushes the cache for us.
 */
void
si_dma_alloc(ncr)
	struct ncr5380_softc *ncr;
{
	struct si_softc *sc = (struct si_softc *)ncr;
	volatile struct si_regs *si = sc->sc_regs;
	struct si_dma_handle *dh;
	int i, xlen;
	u_long addr;

#if 1
	/* XXX - In case we don't trust interrupts... */
	if (si_polled_dma)
		sc->ncr.sc_dma_flags |= DMA5380_POLL;
#endif

	addr = (u_long) sc->ncr.sc_dataptr;
	xlen = sc->ncr.sc_datalen;

	/* If the DMA start addr is misaligned then do PIO */
	if ((addr & 1) || (xlen & 1)) {
		printf("si_dma_alloc: misaligned.\n");
		goto no_dma;
	}

	/* Make sure our caller checked sc_min_dma_len. */
	if (xlen < MIN_DMA_LEN)
		panic("si_dma_alloc: xlen=0x%x\n", xlen);

	/*
	 * Never attempt single transfers of more than 63k, because
	 * our count register may be only 16 bits (an OBIO adapter).
	 * This should never happen since already bounded by minphys().
	 */
	if (xlen > MAX_DMA_LEN) {
		printf("si_dma_alloc: excessive xlen=0x%x\n", xlen);
		Debugger();
		xlen = MAX_DMA_LEN;
	}

	/* Find free DMA handle.  Guaranteed to find one since we have
	   as many DMA handles as the driver has processes. */
	for (i = 0; i < SCI_OPENINGS; i++) {
		if ((sc->sc_dma[i].dh_flags & SIDH_BUSY) == 0)
			goto found;
	}
	panic("si: no free DMA handles.");
found:

	dh = &sc->sc_dma[i];
	sc->ncr.sc_dma_hand = dh;
	dh->dh_addr = addr;
	dh->dh_len = xlen;
	dh->dh_flags = SIDH_BUSY;

	/* Copy the "write" flag for convenience. */
	if (sc->ncr.sc_dma_flags & DMA5380_WRITE)
		dh->dh_flags |= SIDH_OUT;

	/*
	 * We don't care about (sc_dma_flags & DMA5380_PHYS)
	 * because we always have to dup mappings anyway.
	 */
	dh->dh_dvma = (u_long) dvma_mapin((char *)addr, xlen);
	if (!dh->dh_dvma) {
		/* Can't remap segment */
		printf("si_dma_alloc: can't remap %x/%x\n",
			dh->dh_addr, dh->dh_len);
		dh->dh_flags = 0;
		goto no_dma;
	}

	/*
	 * Note:  We have to initialize the FIFO logic NOW,
	 * (just after selection, before talking on the bus)
	 * because after this point, (much to my surprise)
	 * writes to the fifo_count register ARE IGNORED!!!
	 */
	si->fifo_count = 0;		/* also hits dma_count */
	if (dh->dh_flags & SIDH_OUT) {
		si->si_csr |= SI_CSR_SEND;
	} else {
		si->si_csr &= ~SI_CSR_SEND;
	}
	si->si_csr &= ~SI_CSR_FIFO_RES; 	/* active low */
	delay(10);
	si->si_csr |= SI_CSR_FIFO_RES;
	delay(10);
	si->fifo_count = xlen;
	if (sc->sc_adapter_type == BUS_VME16)
		si->fifo_cnt_hi = 0;

#ifdef	DEBUG
	if ((si->fifo_count > xlen) || (si->fifo_count < (xlen - 1))) {
		printf("si_dma_alloc: fifo_count=0x%x, xlen=0x%x\n",
			   si->fifo_count, xlen);
		Debugger();
	}
#endif

	return;	/* success */

no_dma:
	sc->ncr.sc_dma_hand = NULL;
}


void
si_dma_free(ncr)
	struct ncr5380_softc *ncr;
{
	struct si_dma_handle *dh = ncr->sc_dma_hand;

	if (ncr->sc_dma_flags & DMA5380_INPROGRESS)
		panic("si_dma_free: free while in progress");

	if (dh->dh_flags & SIDH_BUSY) {
		/* XXX - Should separate allocation and mapping. */
		/* Give back the DVMA space. */
		dvma_mapout((caddr_t)dh->dh_dvma, dh->dh_len);
		dh->dh_dvma = 0;
		dh->dh_flags = 0;
	}
}


/*
 * Poll (spin-wait) for DMA completion.
 * Same for either VME or OBIO.
 */
void
si_dma_poll(ncr)
	struct ncr5380_softc *ncr;
{
	struct si_softc *sc = (struct si_softc *)ncr;
	volatile struct si_regs *si = sc->sc_regs;
	int tmo, csr_mask;

	/* Make sure the DMA actually started... */
	/* XXX - Check DMA5380_INPROGRESS instead? */
	if (sc->ncr.sc_dma_flags & DMA5380_ERROR)
		return;

	csr_mask = SI_CSR_SBC_IP | SI_CSR_DMA_IP |
		SI_CSR_DMA_CONFLICT | SI_CSR_DMA_BUS_ERR;

	tmo = 50000;	/* X100 = 5 sec. */
	for (;;) {
		if (si->si_csr & csr_mask)
			break;
		if (--tmo <= 0) {
			printf("si: DMA timeout\n");
			sc->ncr.sc_dma_flags |= DMA5380_ERROR;
			si_reset_adapter(&sc->ncr);
			break;
		}
		delay(100);
	}

#ifdef	DEBUG
	if (si_debug) {
		printf("si_dma_poll: done, csr=0x%x\n", si->si_csr);
	}
#endif
}


/*****************************************************************
 * VME functions for DMA
 ****************************************************************/


void
si_vme_dma_start(ncr)
	struct ncr5380_softc *ncr;
{
	struct si_softc *sc = (struct si_softc *)ncr;
	struct si_dma_handle *dh = sc->ncr.sc_dma_hand;
	volatile struct si_regs *si = sc->sc_regs;
	u_long data_pa;

	/*
	 * Get the DVMA mapping for this segment.
	 * XXX - Should separate allocation and mapin.
	 */
	data_pa = dvma_kvtopa((long)dh->dh_dvma, sc->sc_adapter_type) +
		((u_long)sc->ncr.sc_dataptr - dh->dh_addr);
	if (data_pa & 1)
		panic("si_dma_start: bad pa=0x%x", data_pa);

#ifdef	DEBUG
	if (si_debug & 2) {
		printf("si_dma_start: dh=0x%x, pa=0x%x, xlen=%d\n",
			   dh, data_pa, dh->dh_len);
	}
#endif

	/* Already setup FIFO in si_dma_alloc() */

#ifdef	DEBUG
	if ((si->fifo_count > dh->dh_len) ||
		(si->fifo_count < (dh->dh_len - 1)))
	{
		printf("si_dma_start: fifo_count=0x%x, xlen=0x%x\n",
			   si->fifo_count, dh->dh_len);
		Debugger();
	}
#endif

	/*
	 * Set up the DMA controller.
	 * Note that (dh-dh_len < sc_datalen)
	 */
	if (data_pa & 2) {
		si->si_csr |= SI_CSR_BPCON;
	} else {
		si->si_csr &= ~SI_CSR_BPCON;
	}
	si->dma_addrh = data_pa >> 16;
	si->dma_addrl = data_pa & 0xFFFF;
	si->dma_counth = dh->dh_len >> 16;
	si->dma_countl = dh->dh_len & 0xFFFF;

#if 0	/* XXX: Whack the FIFO again? */
	si->si_csr &= ~SI_CSR_FIFO_RES;
	delay(10);
	si->si_csr |= SI_CSR_FIFO_RES;
	delay(10);
#endif

	/*
	 * Put the SBIC into DMA mode and start the transfer.
	 */
	*sc->ncr.sci_mode |= (SCI_MODE_DMA | SCI_MODE_DMA_IE);
	if (dh->dh_flags & SIDH_OUT) {
		*sc->ncr.sci_icmd = SCI_ICMD_DATA;
		*sc->ncr.sci_dma_send = 0;	/* start it */
	} else {
		*sc->ncr.sci_icmd = 0;
		*sc->ncr.sci_irecv = 0;	/* start it */
	}
	si->si_csr |= SI_CSR_DMA_EN;	/* vme only */

	sc->ncr.sc_dma_flags |= DMA5380_INPROGRESS;

	if ((sc->ncr.sc_dma_flags & DMA5380_POLL) == 0) {
		/* Expect an interrupt when DMA completes. */
		sc->sc_timo = si_dma_intr_timo;
		timeout(si_dma_timeout, sc, sc->sc_timo);
	}

#ifdef	DEBUG
	if (si_debug & 2) {
		printf("si_dma_start: started, flags=0x%x\n",
			   sc->ncr.sc_dma_flags);
	}
#endif
}


void
si_vme_dma_eop(ncr)
	struct ncr5380_softc *ncr;
{

	/* Not needed - DMA was stopped prior to examining sci_csr */
}


void
si_vme_dma_stop(ncr)
	struct ncr5380_softc *ncr;
{
	struct si_softc *sc = (struct si_softc *)ncr;
	struct si_dma_handle *dh = sc->ncr.sc_dma_hand;
	volatile struct si_regs *si = sc->sc_regs;
	int resid, ntrans, si_csr;

	if ((sc->ncr.sc_dma_flags & DMA5380_INPROGRESS) == 0) {
#ifdef	DEBUG
		printf("si_dma_stop: dma not running\n");
#endif
		return;
	}
	sc->ncr.sc_dma_flags &= ~DMA5380_INPROGRESS;
	if (sc->sc_timo) {
		sc->sc_timo = 0;
		untimeout(si_dma_timeout, sc);
	}

#ifdef DEBUG
	log_intr();
#endif

	/* First, save csr bits and halt DMA. */
	si_csr = si->si_csr;
	si_csr &= ~SI_CSR_DMA_EN;	/* VME only */
	si->si_csr = si_csr;

	if (si_csr & (SI_CSR_DMA_CONFLICT | SI_CSR_DMA_BUS_ERR)) {
		printf("si: DMA error, csr=0x%x, reset\n", si_csr);
		sc->ncr.sc_dma_flags |= DMA5380_ERROR;
		si_reset_adapter(&sc->ncr);
	}

	/* Note that timeout may have set the error flag. */
	if (sc->ncr.sc_dma_flags & DMA5380_ERROR)
		goto out;

	resid = si->fifo_count;
#ifdef	DEBUG
	if (resid != 0) {
		printf("si_dma_stop: fifo resid=%d (ok?)\n", resid);
		Debugger();
	}
#endif
	/* XXX - Was getting (resid==-1), fixed now. */
	if (resid & ~3) {
		printf("si: fifo count: 0x%x\n", resid);
		sc->ncr.sc_dma_flags |= DMA5380_ERROR;
		goto out;
	}

	/* Adjust data pointer */
	ntrans = dh->dh_len - resid;
	sc->ncr.sc_dataptr += ntrans;
	sc->ncr.sc_datalen -= ntrans;

#ifdef	DEBUG
	if (si_debug & 2) {
		printf("si_dma_stop: ntrans=0x%x\n", ntrans);
	}
#endif

	/*
	 * After a read, we may need to clean-up
	 * "Left-over bytes" (yuck!)
	 */
	if (((dh->dh_flags & SIDH_OUT) == 0) &&
		((si->si_csr & SI_CSR_LOB) != 0))
	{
		char *cp = sc->ncr.sc_dataptr;
#ifdef DEBUG
		printf("si: Got Left-over bytes!\n");
#endif
		if (si->si_csr & SI_CSR_BPCON) {
			/* have SI_CSR_BPCON */
			cp[-1] = (si->si_bprl & 0xff00) >> 8;
		} else {
			switch (si->si_csr & SI_CSR_LOB) {
			case SI_CSR_LOB_THREE:
				cp[-3] = (si->si_bprh & 0xff00) >> 8;
				cp[-2] = (si->si_bprh & 0x00ff);
				cp[-1] = (si->si_bprl & 0xff00) >> 8;
				break;
			case SI_CSR_LOB_TWO:
				cp[-2] = (si->si_bprh & 0xff00) >> 8;
				cp[-1] = (si->si_bprh & 0x00ff);
				break;
			case SI_CSR_LOB_ONE:
				cp[-1] = (si->si_bprh & 0xff00) >> 8;
				break;
			}
		}
	}

out:
	si->dma_addrh = 0;
	si->dma_addrl = 0;

	/* Put SBIC back in PIO mode. */
	*sc->ncr.sci_mode &= ~(SCI_MODE_DMA | SCI_MODE_DMA_IE);
	*sc->ncr.sci_icmd = 0;
}


/*****************************************************************
 * OBIO functions for DMA
 ****************************************************************/


static __inline__ void
si_obio_udc_write(si, regnum, value)
	volatile struct si_regs *si;
	int regnum, value;
{
	delay(UDC_WAIT_USEC);
	si->udc_addr = regnum;
	delay(UDC_WAIT_USEC);
	si->udc_data = value;
}

static __inline__ int
si_obio_udc_read(si, regnum)
	volatile struct si_regs *si;
	int regnum;
{
	delay(UDC_WAIT_USEC);
	si->udc_addr = regnum;
	delay(UDC_WAIT_USEC);
	return (si->udc_data);
}


void
si_obio_dma_start(ncr)
	struct ncr5380_softc *ncr;
{
	struct si_softc *sc = (struct si_softc *)ncr;
	struct si_dma_handle *dh = sc->ncr.sc_dma_hand;
	volatile struct si_regs *si = sc->sc_regs;
	struct udc_table *cmd;
	u_long data_pa, cmd_pa;

	/*
	 * Get the DVMA mapping for this segment.
	 * XXX - Should separate allocation and mapin.
	 */
	data_pa = dvma_kvtopa((long)dh->dh_dvma, sc->sc_adapter_type) +
		((u_long)sc->ncr.sc_dataptr - dh->dh_addr);
	if (data_pa & 1)
		panic("si_dma_start: bad pa=0x%x", data_pa);
	if (dh->dh_len & 1)
		panic("si_dma_start: bad len=0x%x", dh->dh_len);

#ifdef	DEBUG
	if (si_debug & 2) {
		printf("si_dma_start: dh=0x%x, pa=0x%x, xlen=%d\n",
			   dh, data_pa, dh->dh_len);
	}
#endif

	/* Already setup FIFO in si_dma_alloc() */

#ifdef	DEBUG
	if ((si->fifo_count > dh->dh_len) ||
		(si->fifo_count < (dh->dh_len - 1)))
	{
		printf("si_dma_start: fifo_count=0x%x, xlen=0x%x\n",
			   si->fifo_count, dh->dh_len);
		Debugger();
	}
#endif

	/*
	 * Set up the DMA controller.
	 * Note that (dh-dh_len < sc_datalen)
	 */

	/*
	 * The OBIO controller needs a command block.
	 */
	cmd = &dh->dh_cmd;
	cmd->addrh = ((data_pa & 0xFF0000) >> 8) | UDC_ADDR_INFO;
	cmd->addrl = data_pa & 0xFFFF;
	cmd->count = dh->dh_len / 2;	/* bytes -> words */
	cmd->cmrh = UDC_CMR_HIGH;
	if (dh->dh_flags & SIDH_OUT) {
		cmd->cmrl = UDC_CMR_LSEND;
		cmd->rsel = UDC_RSEL_SEND;
	} else {
		cmd->cmrl = UDC_CMR_LRECV;
		cmd->rsel = UDC_RSEL_RECV;
	}

	/* Tell the DMA chip where the control block is. */
	cmd_pa = dvma_kvtopa((long)cmd, BUS_OBIO);
	si_obio_udc_write(si, UDC_ADR_CAR_HIGH,
					  (cmd_pa & 0xff0000) >> 8);
	si_obio_udc_write(si, UDC_ADR_CAR_LOW,
					  (cmd_pa & 0xffff));

	/* Tell the chip to be a DMA master. */
	si_obio_udc_write(si, UDC_ADR_MODE, UDC_MODE);

	/* Tell the chip to interrupt on error. */
	si_obio_udc_write(si, UDC_ADR_COMMAND, UDC_CMD_CIE);

	/* Finally, give the UDC a "start chain" command. */
	si_obio_udc_write(si, UDC_ADR_COMMAND, UDC_CMD_STRT_CHN);

	/*
	 * Put the SBIC into DMA mode and start the transfer.
	 */
	*sc->ncr.sci_mode |= (SCI_MODE_DMA | SCI_MODE_DMA_IE);
	if (dh->dh_flags & SIDH_OUT) {
		*sc->ncr.sci_icmd = SCI_ICMD_DATA;
		*sc->ncr.sci_dma_send = 0;	/* start it */
	} else {
		*sc->ncr.sci_icmd = 0;
		*sc->ncr.sci_irecv = 0;	/* start it */
	}

	sc->ncr.sc_dma_flags |= DMA5380_INPROGRESS;

	if ((sc->ncr.sc_dma_flags & DMA5380_POLL) == 0) {
		/* Expect an interrupt when DMA completes. */
		sc->sc_timo = si_dma_intr_timo;
		timeout(si_dma_timeout, sc, sc->sc_timo);
	}

#ifdef	DEBUG
	if (si_debug & 2) {
		printf("si_dma_start: started, flags=0x%x\n",
			   sc->ncr.sc_dma_flags);
	}
#endif
}


void
si_obio_dma_eop(ncr)
	struct ncr5380_softc *ncr;
{

	/* Not needed - DMA was stopped prior to examining sci_csr */
}


void
si_obio_dma_stop(ncr)
	struct ncr5380_softc *ncr;
{
	struct si_softc *sc = (struct si_softc *)ncr;
	struct si_dma_handle *dh = sc->ncr.sc_dma_hand;
	volatile struct si_regs *si = sc->sc_regs;
	int resid, ntrans, tmo, udc_cnt;

	if ((sc->ncr.sc_dma_flags & DMA5380_INPROGRESS) == 0) {
#ifdef	DEBUG
		printf("si_dma_stop: dma not running\n");
#endif
		return;
	}
	sc->ncr.sc_dma_flags &= ~DMA5380_INPROGRESS;
	if (sc->sc_timo) {
		sc->sc_timo = 0;
		untimeout(si_dma_timeout, sc);
	}

	if (si->si_csr & (SI_CSR_DMA_CONFLICT | SI_CSR_DMA_BUS_ERR)) {
		printf("si: DMA error, csr=0x%x, reset\n", si->si_csr);
		sc->ncr.sc_dma_flags |= DMA5380_ERROR;
		si_reset_adapter(&sc->ncr);
	}

	/* Note that timeout may have set the error flag. */
	if (sc->ncr.sc_dma_flags & DMA5380_ERROR)
		goto out;

	/* After a read, wait for the FIFO to empty. */
	if ((dh->dh_flags & SIDH_OUT) == 0) {
		/* XXX: This bit is not reliable.  Beware! -dej */
		tmo = 200000;	/* X10 = 2 sec. */
		for (;;) {
			if (si->si_csr & SI_CSR_FIFO_EMPTY)
				break;
			if (--tmo <= 0) {
				printf("si: dma fifo did not empty, reset\n");
				sc->ncr.sc_dma_flags |= DMA5380_ERROR;
				si_reset_adapter(&sc->ncr);
				goto out;
			}
			delay(10);
		}
	}


	resid = si->fifo_count;
#ifdef	DEBUG
	if (resid != 0) {
		printf("si_dma_stop: fifo resid=%d (ok?)\n", resid);
		Debugger();
	}
#endif
	/* XXX - Was getting (resid==-1), fixed now. */
	if (resid & ~3) {
		printf("si: fifo count: 0x%x\n", resid);
		sc->ncr.sc_dma_flags |= DMA5380_ERROR;
		goto out;
	}

	/* Adjust data pointer */
	ntrans = dh->dh_len - resid;
	sc->ncr.sc_dataptr += ntrans;
	sc->ncr.sc_datalen -= ntrans;

#ifdef	DEBUG
	if (si_debug & 2) {
		printf("si_dma_stop: ntrans=0x%x\n", ntrans);
	}
#endif

	/*
	 * After a read, we may need to clean-up
	 * "Left-over bytes" (yuck!)
	 */
	if ((dh->dh_flags & SIDH_OUT) == 0) {
		/* If odd transfer count, grab last byte by hand. */
		if (ntrans & 1) {
			sc->ncr.sc_dataptr[-1] =
				(si->fifo_data & 0xff00) >> 8;
			goto out;
		}
		/* UDC might not have transfered the last word. */
		udc_cnt = si_obio_udc_read(si, UDC_ADR_COUNT);
		if (((udc_cnt * 2) - si->fifo_count) == 2) {
			sc->ncr.sc_dataptr[-2] =
				(si->fifo_data & 0xff00) >> 8;
			sc->ncr.sc_dataptr[-1] =
				(si->fifo_data & 0x00ff);
		}
	}

out:
	/* Reset the UDC. */
	si_obio_udc_write(si, UDC_ADR_COMMAND, UDC_CMD_RESET);

	/* Put SBIC back in PIO mode. */
	*sc->ncr.sci_mode &= ~(SCI_MODE_DMA | SCI_MODE_DMA_IE);
	*sc->ncr.sci_icmd = 0;
}


#if 0
int hexdigit(char c)
{

	if (c >= '0' && c <= '9') return c - '0';
	else return c - ('a' - 10);
}


struct scsi_link *thescsilink;

void sicmdloop(void)
{
char hexbuf[40];
int c, i, pos;
u_char cmdbuf[6];

	while (1) {
		pos = 0;
		while (1) {
			c = cngetc();
			if ((c == 0x7F || c == 0x08) && pos) {
				pos--;
				cnputc(0x08);
				cnputc(' ');
				cnputc(0x08);
			}
			else if (c == '\r' || c == '\n') {
				hexbuf[pos] = 0;
				break;
			}
			else {
				hexbuf[pos++] = c;
				cnputc(c);
			}
		}

		pos = 0;
		for (i = 0; i < 6; i++) {
		    while (hexbuf[pos] == ' ') pos++;
		    cmdbuf[i] = 16 * hexdigit(hexbuf[pos++]) + hexdigit(hexbuf[pos++]);
		}

		scsi_scsi_cmd(thescsilink, (struct scsi_generic *)cmdbuf, 6,
			0, 0, 1, 1000, 0, SCSI_POLL);
	}
}
#endif


#ifdef DEBUG

#define NQENT 10
static int Qptr = 0;
static struct qent {
    int seq;
    int si_csr;
    int sci_csr;
    int sci_bus_csr;
    long dma_addr, dma_count, fifo_len;
    long start_addr, start_count, start_len;
} Qents[NQENT];


void log_start(void)
{
struct si_softc *sc = TheSoftC;
volatile struct si_regs *si = sc->sc_regs;

    Qents[Qptr].start_addr = (si->dma_addrh << 16) + si->dma_addrl;
    Qents[Qptr].start_count = (si->dma_counth << 16) + si->dma_countl;
    Qents[Qptr].start_len = si->fifo_count;
    Qents[Qptr].seq = Seq++;
}


void log_intr(void)
{
struct si_softc *sc = TheSoftC;
volatile struct si_regs *si = sc->sc_regs;

    Qents[Qptr].si_csr = si->si_csr;
    while (!(si->si_csr & SI_CSR_FIFO_EMPTY)) {
	printf("log_intr: FIFO not empty before DMA disable at %d\n", Seq);
    }

    if (sc->sc_adapter_type == BUS_VME16)
	    si->si_csr &= ~SI_CSR_DMA_EN;
    if (!(si->si_csr & SI_CSR_FIFO_EMPTY)) {
	printf("log_intr: FIFO not empty after DMA disable at %d\n", Seq);
    }
    Qents[Qptr].dma_addr = (si->dma_addrh << 16) + si->dma_addrl;

    Qents[Qptr].dma_count = (si->dma_counth << 16) + si->dma_countl;
    Qents[Qptr].fifo_len = si->fifo_count;
    Qents[Qptr].sci_csr = *sc->ncr.sci_csr;
    Qents[Qptr].sci_bus_csr = *sc->ncr.sci_bus_csr;
    Qptr++;
    if (Qptr == NQENT) Qptr = 0;
}


void si_printregs(void)
{
struct si_softc *sc = TheSoftC;
volatile struct si_regs *si = TheRegs;
struct sci_req *sr;
int i;
int a, b, c, d;

    if (!TheRegs) {
	printf("TheRegs == NULL, please re-set!\n");
	return;
    }

    c = si->si_csr;
    printf("si->si_csr=%04x\n", c);
    si->si_csr &= ~SI_CSR_DMA_EN;

    a = si->dma_addrh; b = si->dma_addrl;
    printf("si->dma_addr=%04x%04x\n", a, b);

    /* printf("si->dma_addr=%04x%04x\n", si->dma_addrh, si->dma_addrl); */
    printf("si->dma_count=%04x%04x\n", si->dma_counth, si->dma_countl);
    printf("si->fifo_count=%04x\n", si->fifo_count);
    printf("sci_icmd=%02x\n", si->sci.sci_icmd);
    printf("sci_mode=%02x\n", si->sci.sci_mode);
    printf("sci_tcmd=%02x\n", si->sci.sci_tcmd);
    printf("sci_bus_csr=%02x\n", si->sci.sci_bus_csr);
    printf("sci_csr=%02x\n", si->sci.sci_csr);
    printf("sci_data=%02x\n\n", si->sci.sci_data);

    if (!TheSoftC) {
	printf("TheSoftC == NULL, can't continue.\n");
	return;
    }

    printf("DMA handles:\n");
    for (i = 0; i < SCI_OPENINGS; i++) {
	if (sc->sc_dma[i].dh_flags & SIDH_BUSY) {
	    printf("%d: %x/%x => %x/%d %s\n", i,
		sc->sc_dma[i].dh_addr,
		sc->sc_dma[i].dh_len,
		sc->sc_dma[i].dh_dvma,
		sc->sc_dma[i].dh_flags,
		(&sc->sc_dma[i] == sc->ncr.sc_dma_hand) ? "(active)" : "");
	}
	else {
	    printf("%d: idle\n", i);
	}
    }

    printf("i\nsci_req queue:\n");
    for (i = 0; i < SCI_OPENINGS; i++) {
	sr = &sc->ncr.sc_ring[i];
	printf("%d: %d/%d %x/%x => %x\n", i, sr->sr_target, sr->sr_lun,
	    sr->sr_data, sr->sr_datalen,
	    sr->sr_dma_hand);
    }
    printf("Total commands (sc_ncmds): %d\n", sc->ncr.sc_ncmds);
    printf("\nCurrent SCSI data pointer: %x/%x\n", sc->ncr.sc_dataptr,
	sc->ncr.sc_datalen);
}

void print_qent(void)
{
int i;

    i = Qptr;
    do {
	printf("%d: si_csr=%04x csr=%02x bus_csr=%02x addr=%08x count=%08x fifo=%08x\n",
	    Qents[i].seq, Qents[i].si_csr, Qents[i].sci_csr, Qents[i].sci_bus_csr,
	    Qents[i].dma_addr, Qents[i].dma_count, Qents[i].fifo_len);
	printf("    from addr=%08x count=%08x fifo=%08x\n",
	    Qents[i].start_addr, Qents[i].start_count, Qents[i].start_len);
	i++;
	if (i == NQENT) i = 0;
    } while (i != Qptr);
}

#endif