Home | History | Annotate | Line # | Download | only in dev
ivsc.c revision 1.32.6.3
      1  1.32.6.3     skrll /*	$NetBSD: ivsc.c,v 1.32.6.3 2004/09/21 13:12:30 skrll Exp $ */
      2       1.5       cgd 
      3       1.1    chopps /*
      4       1.1    chopps  * Copyright (c) 1982, 1990 The Regents of the University of California.
      5       1.1    chopps  * All rights reserved.
      6       1.1    chopps  *
      7       1.1    chopps  * Redistribution and use in source and binary forms, with or without
      8       1.1    chopps  * modification, are permitted provided that the following conditions
      9       1.1    chopps  * are met:
     10       1.1    chopps  * 1. Redistributions of source code must retain the above copyright
     11       1.1    chopps  *    notice, this list of conditions and the following disclaimer.
     12       1.1    chopps  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1    chopps  *    notice, this list of conditions and the following disclaimer in the
     14       1.1    chopps  *    documentation and/or other materials provided with the distribution.
     15  1.32.6.1     skrll  * 3. Neither the name of the University nor the names of its contributors
     16       1.1    chopps  *    may be used to endorse or promote products derived from this software
     17       1.1    chopps  *    without specific prior written permission.
     18       1.1    chopps  *
     19       1.1    chopps  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1    chopps  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1    chopps  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1    chopps  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1    chopps  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1    chopps  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1    chopps  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1    chopps  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1    chopps  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1    chopps  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1    chopps  * SUCH DAMAGE.
     30       1.1    chopps  *
     31       1.1    chopps  *	@(#)ivsdma.c
     32       1.1    chopps  */
     33      1.30   aymeric 
     34  1.32.6.1     skrll /*
     35  1.32.6.1     skrll  * Copyright (c) 1994 Michael L. Hitch
     36  1.32.6.1     skrll  *
     37  1.32.6.1     skrll  * Redistribution and use in source and binary forms, with or without
     38  1.32.6.1     skrll  * modification, are permitted provided that the following conditions
     39  1.32.6.1     skrll  * are met:
     40  1.32.6.1     skrll  * 1. Redistributions of source code must retain the above copyright
     41  1.32.6.1     skrll  *    notice, this list of conditions and the following disclaimer.
     42  1.32.6.1     skrll  * 2. Redistributions in binary form must reproduce the above copyright
     43  1.32.6.1     skrll  *    notice, this list of conditions and the following disclaimer in the
     44  1.32.6.1     skrll  *    documentation and/or other materials provided with the distribution.
     45  1.32.6.1     skrll  *
     46  1.32.6.1     skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     47  1.32.6.1     skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     48  1.32.6.1     skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     49  1.32.6.1     skrll  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     50  1.32.6.1     skrll  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     51  1.32.6.1     skrll  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     52  1.32.6.1     skrll  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     53  1.32.6.1     skrll  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     54  1.32.6.1     skrll  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     55  1.32.6.1     skrll  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     56  1.32.6.1     skrll  *
     57  1.32.6.1     skrll  *	@(#)ivsdma.c
     58  1.32.6.1     skrll  */
     59  1.32.6.1     skrll 
     60      1.30   aymeric #include <sys/cdefs.h>
     61  1.32.6.3     skrll __KERNEL_RCSID(0, "$NetBSD: ivsc.c,v 1.32.6.3 2004/09/21 13:12:30 skrll Exp $");
     62      1.30   aymeric 
     63       1.2    chopps #include <sys/param.h>
     64       1.2    chopps #include <sys/systm.h>
     65       1.2    chopps #include <sys/kernel.h>
     66       1.2    chopps #include <sys/device.h>
     67      1.22    bouyer #include <dev/scsipi/scsi_all.h>
     68      1.22    bouyer #include <dev/scsipi/scsipi_all.h>
     69      1.22    bouyer #include <dev/scsipi/scsiconf.h>
     70       1.2    chopps #include <amiga/amiga/custom.h>
     71       1.2    chopps #include <amiga/amiga/device.h>
     72       1.9    chopps #include <amiga/amiga/isr.h>
     73       1.2    chopps #include <amiga/dev/scireg.h>
     74       1.2    chopps #include <amiga/dev/scivar.h>
     75       1.7    chopps #include <amiga/dev/zbusvar.h>
     76       1.2    chopps 
     77      1.29   aymeric void ivscattach(struct device *, struct device *, void *);
     78      1.29   aymeric int ivscmatch(struct device *, struct cfdata *, void *);
     79       1.2    chopps 
     80      1.29   aymeric int ivsc_intr(void *);
     81      1.29   aymeric int ivsc_dma_xfer_in(struct sci_softc *dev, int len,
     82      1.29   aymeric     register u_char *buf, int phase);
     83      1.29   aymeric int ivsc_dma_xfer_out(struct sci_softc *dev, int len,
     84      1.29   aymeric     register u_char *buf, int phase);
     85       1.2    chopps 
     86       1.2    chopps 
     87       1.2    chopps #ifdef DEBUG
     88       1.2    chopps extern int sci_debug;
     89      1.19  christos #define QPRINTF(a) if (sci_debug > 1) printf a
     90      1.15     veego #else
     91      1.15     veego #define QPRINTF(a)
     92       1.2    chopps #endif
     93       1.2    chopps 
     94       1.2    chopps extern int sci_data_wait;
     95       1.2    chopps 
     96      1.11    chopps int ivsdma_pseudo = 1;		/* 0=off, 1=on */
     97      1.11    chopps 
     98      1.32   thorpej CFATTACH_DECL(ivsc, sizeof(struct sci_softc),
     99      1.32   thorpej     ivscmatch, ivscattach, NULL, NULL);
    100       1.1    chopps 
    101       1.1    chopps /*
    102       1.2    chopps  * if this is an IVS board
    103       1.1    chopps  */
    104       1.2    chopps int
    105      1.29   aymeric ivscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
    106       1.2    chopps {
    107       1.7    chopps 	struct zbus_args *zap;
    108       1.1    chopps 
    109       1.2    chopps 	zap = auxp;
    110       1.1    chopps 
    111       1.2    chopps 	/*
    112       1.2    chopps 	 * Check manufacturer and product id.
    113       1.2    chopps 	 */
    114       1.2    chopps 	if (zap->manid != 2112 ||	/* If manufacturer is IVS */
    115      1.12    chopps 	    (zap->prodid != 48 &&	/*   product = Trumpcard 500 */
    116      1.12    chopps 	    zap->prodid != 52 &&	/*   product = Trumpcard */
    117       1.2    chopps 	    zap->prodid != 243))	/*   product = Vector SCSI */
    118       1.2    chopps 		return(0);		/* didn't match */
    119       1.2    chopps 	return(1);
    120       1.2    chopps }
    121       1.1    chopps 
    122       1.1    chopps void
    123      1.29   aymeric ivscattach(struct device *pdp, struct device *dp, void *auxp)
    124       1.2    chopps {
    125       1.2    chopps 	volatile u_char *rp;
    126      1.28    bouyer 	struct sci_softc *sc = (struct sci_softc *)dp;
    127       1.7    chopps 	struct zbus_args *zap;
    128      1.28    bouyer 	struct scsipi_adapter *adapt = &sc->sc_adapter;
    129      1.28    bouyer 	struct scsipi_channel *chan = &sc->sc_channel;
    130       1.3    chopps 
    131      1.19  christos 	printf("\n");
    132       1.2    chopps 
    133       1.2    chopps 	zap = auxp;
    134      1.29   aymeric 
    135      1.27      tron 	rp = (u_char *)zap->va + 0x40;
    136       1.2    chopps 	sc->sci_data = rp;
    137       1.2    chopps 	sc->sci_odata = rp;
    138       1.2    chopps 	sc->sci_icmd = rp + 2;
    139       1.2    chopps 	sc->sci_mode = rp + 4;
    140       1.2    chopps 	sc->sci_tcmd = rp + 6;
    141       1.2    chopps 	sc->sci_bus_csr = rp + 8;
    142       1.2    chopps 	sc->sci_sel_enb = rp + 8;
    143       1.2    chopps 	sc->sci_csr = rp + 10;
    144       1.2    chopps 	sc->sci_dma_send = rp + 10;
    145       1.2    chopps 	sc->sci_idata = rp + 12;
    146       1.2    chopps 	sc->sci_trecv = rp + 12;
    147       1.2    chopps 	sc->sci_iack = rp + 14;
    148       1.2    chopps 	sc->sci_irecv = rp + 14;
    149       1.2    chopps 
    150      1.11    chopps 	if (ivsdma_pseudo == 1) {
    151      1.11    chopps 		sc->dma_xfer_in = ivsc_dma_xfer_in;
    152      1.11    chopps 		sc->dma_xfer_out = ivsc_dma_xfer_out;
    153      1.11    chopps 	}
    154       1.2    chopps 
    155       1.9    chopps 	sc->sc_isr.isr_intr = ivsc_intr;
    156       1.9    chopps 	sc->sc_isr.isr_arg = sc;
    157       1.9    chopps 	sc->sc_isr.isr_ipl = 2;
    158       1.9    chopps 	add_isr(&sc->sc_isr);
    159       1.9    chopps 
    160       1.2    chopps 	scireset(sc);
    161       1.2    chopps 
    162      1.28    bouyer 	/*
    163      1.28    bouyer 	 * Fill in the scsipi_adapter.
    164      1.28    bouyer 	 */
    165      1.28    bouyer 	memset(adapt, 0, sizeof(*adapt));
    166      1.28    bouyer 	adapt->adapt_dev = &sc->sc_dev;
    167      1.28    bouyer 	adapt->adapt_nchannels = 1;
    168      1.28    bouyer 	adapt->adapt_openings = 7;
    169      1.28    bouyer 	adapt->adapt_max_periph = 1;
    170      1.28    bouyer 	adapt->adapt_request = sci_scsipi_request;
    171      1.28    bouyer 	adapt->adapt_minphys = sci_minphys;
    172      1.25   thorpej 
    173      1.28    bouyer 	/*
    174      1.28    bouyer 	 * Fill in the scsipi_channel.
    175      1.28    bouyer 	 */
    176      1.28    bouyer 	memset(chan, 0, sizeof(*chan));
    177      1.28    bouyer 	chan->chan_adapter = adapt;
    178      1.28    bouyer 	chan->chan_bustype = &scsi_bustype;
    179      1.28    bouyer 	chan->chan_channel = 0;
    180      1.29   aymeric 	chan->chan_ntargets = 8;
    181      1.28    bouyer 	chan->chan_nluns = 8;
    182      1.28    bouyer 	chan->chan_id = 7;
    183       1.2    chopps 
    184       1.2    chopps 	/*
    185       1.2    chopps 	 * attach all scsi units on us
    186       1.2    chopps 	 */
    187      1.28    bouyer 	config_found(dp, chan, scsiprint);
    188       1.2    chopps }
    189       1.2    chopps 
    190       1.2    chopps int
    191      1.29   aymeric ivsc_dma_xfer_in(struct sci_softc *dev, int len, register u_char *buf,
    192      1.29   aymeric                  int phase)
    193       1.2    chopps {
    194      1.11    chopps 	int wait = sci_data_wait;
    195      1.11    chopps 	volatile register u_char *sci_dma = dev->sci_idata + 0x20;
    196      1.11    chopps 	volatile register u_char *sci_csr = dev->sci_csr;
    197      1.15     veego #ifdef DEBUG
    198      1.15     veego 	u_char *obp = buf;
    199      1.15     veego #endif
    200      1.11    chopps 
    201      1.11    chopps 	QPRINTF(("ivsc_dma_in %d, csr=%02x\n", len, *dev->sci_bus_csr));
    202      1.11    chopps 
    203      1.11    chopps 	*dev->sci_tcmd = phase;
    204      1.11    chopps 	*dev->sci_mode |= SCI_MODE_DMA;
    205      1.11    chopps 	*dev->sci_irecv = 0;
    206      1.11    chopps 
    207      1.11    chopps 	while (len >= 128) {
    208      1.11    chopps 		wait = sci_data_wait;
    209      1.11    chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
    210      1.11    chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    211      1.11    chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
    212      1.11    chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
    213      1.11    chopps 			  || --wait < 0) {
    214      1.11    chopps #ifdef DEBUG
    215      1.11    chopps 				if (sci_debug)
    216      1.19  christos 					printf("ivsc_dma_in2 fail: l%d i%x w%d\n",
    217      1.15     veego 					len, *dev->sci_bus_csr, wait);
    218      1.11    chopps #endif
    219      1.11    chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    220      1.11    chopps 				return 0;
    221      1.11    chopps 			}
    222      1.11    chopps 		}
    223      1.11    chopps 
    224      1.11    chopps #define	R1	(*buf++ = *sci_dma)
    225      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    226      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    227      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    228      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    229      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    230      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    231      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    232      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    233      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    234      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    235      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    236      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    237      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    238      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    239      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    240      1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    241      1.11    chopps 		len -= 128;
    242      1.11    chopps 	}
    243      1.11    chopps 
    244      1.11    chopps   	while (len > 0) {
    245      1.11    chopps 		wait = sci_data_wait;
    246      1.11    chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
    247      1.11    chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    248      1.11    chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
    249      1.11    chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
    250      1.11    chopps 			  || --wait < 0) {
    251      1.11    chopps #ifdef DEBUG
    252      1.11    chopps 				if (sci_debug)
    253      1.19  christos 					printf("ivsc_dma_in1 fail: l%d i%x w%d\n",
    254      1.15     veego 					len, *dev->sci_bus_csr, wait);
    255      1.11    chopps #endif
    256      1.11    chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    257      1.11    chopps 				return 0;
    258      1.11    chopps 			}
    259      1.11    chopps 		}
    260      1.11    chopps 
    261      1.11    chopps 		*buf++ = *sci_dma;
    262      1.11    chopps 		len--;
    263      1.11    chopps 	}
    264      1.11    chopps 
    265      1.11    chopps 	QPRINTF(("ivsc_dma_in {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    266      1.11    chopps 	  len, obp[0], obp[1], obp[2], obp[3], obp[4], obp[5],
    267      1.11    chopps 	  obp[6], obp[7], obp[8], obp[9]));
    268      1.11    chopps 
    269      1.11    chopps 	*dev->sci_mode &= ~SCI_MODE_DMA;
    270      1.11    chopps 	return 0;
    271       1.2    chopps }
    272       1.2    chopps 
    273       1.2    chopps int
    274      1.29   aymeric ivsc_dma_xfer_out(struct sci_softc *dev, int len, register u_char *buf,
    275      1.29   aymeric                   int phase)
    276       1.1    chopps {
    277      1.11    chopps 	int wait = sci_data_wait;
    278      1.11    chopps 	volatile register u_char *sci_dma = dev->sci_data + 0x20;
    279      1.11    chopps 	volatile register u_char *sci_csr = dev->sci_csr;
    280      1.11    chopps 
    281      1.11    chopps 	QPRINTF(("ivsc_dma_out %d, csr=%02x\n", len, *dev->sci_bus_csr));
    282      1.11    chopps 
    283      1.11    chopps 	QPRINTF(("ivsc_dma_out {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    284      1.11    chopps   	 len, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
    285      1.11    chopps 	 buf[6], buf[7], buf[8], buf[9]));
    286      1.11    chopps 
    287      1.11    chopps 	*dev->sci_tcmd = phase;
    288      1.11    chopps 	*dev->sci_mode |= SCI_MODE_DMA;
    289      1.11    chopps 	*dev->sci_icmd |= SCI_ICMD_DATA;
    290      1.11    chopps 	*dev->sci_dma_send = 0;
    291      1.11    chopps 	while (len > 0) {
    292      1.11    chopps 		wait = sci_data_wait;
    293      1.11    chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
    294      1.11    chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    295      1.11    chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
    296      1.11    chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
    297      1.11    chopps 			  || --wait < 0) {
    298      1.11    chopps #ifdef DEBUG
    299      1.11    chopps 				if (sci_debug)
    300      1.19  christos 					printf("ivsc_dma_out fail: l%d i%x w%d\n",
    301      1.15     veego 					len, *dev->sci_bus_csr, wait);
    302      1.11    chopps #endif
    303      1.11    chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    304      1.11    chopps 				return 0;
    305      1.11    chopps 			}
    306      1.11    chopps 		}
    307      1.11    chopps 
    308      1.11    chopps 		*sci_dma = *buf++;
    309      1.11    chopps 		len--;
    310      1.11    chopps 	}
    311      1.11    chopps 
    312      1.11    chopps 	wait = sci_data_wait;
    313      1.11    chopps 	while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) ==
    314      1.11    chopps 	  SCI_CSR_PHASE_MATCH && --wait);
    315      1.11    chopps 
    316      1.11    chopps 
    317      1.11    chopps 	*dev->sci_mode &= ~SCI_MODE_DMA;
    318      1.11    chopps 	return 0;
    319       1.1    chopps }
    320       1.2    chopps 
    321       1.2    chopps int
    322      1.29   aymeric ivsc_intr(void *arg)
    323       1.2    chopps {
    324      1.15     veego 	struct sci_softc *dev = arg;
    325       1.2    chopps 	u_char stat;
    326       1.2    chopps 
    327       1.9    chopps 	if ((*dev->sci_csr & SCI_CSR_INT) == 0)
    328       1.9    chopps 		return(0);
    329       1.9    chopps 	stat = *dev->sci_iack;
    330      1.14        is 	/* XXXX is: something is missing here, at least a: */
    331      1.14        is 	return(1);
    332       1.2    chopps }
    333