Home | History | Annotate | Line # | Download | only in dev
ivsc.c revision 1.35.112.2
      1  1.35.112.2      yamt /*	$NetBSD: ivsc.c,v 1.35.112.2 2014/05/22 11:39:28 yamt 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.33       agc  * 3. Neither the name of the University nor the names of its contributors
     16        1.33       agc  *    may be used to endorse or promote products derived from this software
     17        1.33       agc  *    without specific prior written permission.
     18        1.33       agc  *
     19        1.33       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20        1.33       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21        1.33       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22        1.33       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23        1.33       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24        1.33       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25        1.33       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26        1.33       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27        1.33       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28        1.33       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29        1.33       agc  * SUCH DAMAGE.
     30        1.33       agc  *
     31        1.33       agc  *	@(#)ivsdma.c
     32        1.33       agc  */
     33        1.33       agc 
     34        1.33       agc /*
     35        1.33       agc  * Copyright (c) 1994 Michael L. Hitch
     36        1.33       agc  *
     37        1.33       agc  * Redistribution and use in source and binary forms, with or without
     38        1.33       agc  * modification, are permitted provided that the following conditions
     39        1.33       agc  * are met:
     40        1.33       agc  * 1. Redistributions of source code must retain the above copyright
     41        1.33       agc  *    notice, this list of conditions and the following disclaimer.
     42        1.33       agc  * 2. Redistributions in binary form must reproduce the above copyright
     43        1.33       agc  *    notice, this list of conditions and the following disclaimer in the
     44        1.33       agc  *    documentation and/or other materials provided with the distribution.
     45         1.1    chopps  *
     46        1.34    mhitch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     47        1.34    mhitch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     48        1.34    mhitch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     49        1.34    mhitch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     50        1.34    mhitch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     51        1.34    mhitch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     52        1.34    mhitch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     53        1.34    mhitch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     54        1.34    mhitch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     55        1.34    mhitch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     56         1.1    chopps  *
     57         1.1    chopps  *	@(#)ivsdma.c
     58         1.1    chopps  */
     59        1.30   aymeric 
     60        1.30   aymeric #include <sys/cdefs.h>
     61  1.35.112.2      yamt __KERNEL_RCSID(0, "$NetBSD: ivsc.c,v 1.35.112.2 2014/05/22 11:39:28 yamt 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.35.112.1      yamt void ivscattach(device_t, device_t, void *);
     78  1.35.112.1      yamt int ivscmatch(device_t, cfdata_t, 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.35.112.1      yamt CFATTACH_DECL_NEW(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.35.112.1      yamt ivscmatch(device_t parent, cfdata_t cf, void *aux)
    106         1.2    chopps {
    107         1.7    chopps 	struct zbus_args *zap;
    108         1.1    chopps 
    109  1.35.112.1      yamt 	zap = aux;
    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.35.112.1      yamt ivscattach(device_t parent, device_t self, void *aux)
    124         1.2    chopps {
    125         1.2    chopps 	volatile u_char *rp;
    126  1.35.112.1      yamt 	struct sci_softc *sc = device_private(self);
    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.35.112.1      yamt 	sc->sc_dev = self;
    132  1.35.112.1      yamt 
    133        1.19  christos 	printf("\n");
    134         1.2    chopps 
    135  1.35.112.1      yamt 	zap = aux;
    136        1.29   aymeric 
    137        1.27      tron 	rp = (u_char *)zap->va + 0x40;
    138         1.2    chopps 	sc->sci_data = rp;
    139         1.2    chopps 	sc->sci_odata = rp;
    140         1.2    chopps 	sc->sci_icmd = rp + 2;
    141         1.2    chopps 	sc->sci_mode = rp + 4;
    142         1.2    chopps 	sc->sci_tcmd = rp + 6;
    143         1.2    chopps 	sc->sci_bus_csr = rp + 8;
    144         1.2    chopps 	sc->sci_sel_enb = rp + 8;
    145         1.2    chopps 	sc->sci_csr = rp + 10;
    146         1.2    chopps 	sc->sci_dma_send = rp + 10;
    147         1.2    chopps 	sc->sci_idata = rp + 12;
    148         1.2    chopps 	sc->sci_trecv = rp + 12;
    149         1.2    chopps 	sc->sci_iack = rp + 14;
    150         1.2    chopps 	sc->sci_irecv = rp + 14;
    151         1.2    chopps 
    152        1.11    chopps 	if (ivsdma_pseudo == 1) {
    153        1.11    chopps 		sc->dma_xfer_in = ivsc_dma_xfer_in;
    154        1.11    chopps 		sc->dma_xfer_out = ivsc_dma_xfer_out;
    155        1.11    chopps 	}
    156         1.2    chopps 
    157         1.9    chopps 	sc->sc_isr.isr_intr = ivsc_intr;
    158         1.9    chopps 	sc->sc_isr.isr_arg = sc;
    159         1.9    chopps 	sc->sc_isr.isr_ipl = 2;
    160         1.9    chopps 	add_isr(&sc->sc_isr);
    161         1.9    chopps 
    162         1.2    chopps 	scireset(sc);
    163         1.2    chopps 
    164        1.28    bouyer 	/*
    165        1.28    bouyer 	 * Fill in the scsipi_adapter.
    166        1.28    bouyer 	 */
    167        1.28    bouyer 	memset(adapt, 0, sizeof(*adapt));
    168  1.35.112.1      yamt 	adapt->adapt_dev = self;
    169        1.28    bouyer 	adapt->adapt_nchannels = 1;
    170        1.28    bouyer 	adapt->adapt_openings = 7;
    171        1.28    bouyer 	adapt->adapt_max_periph = 1;
    172        1.28    bouyer 	adapt->adapt_request = sci_scsipi_request;
    173        1.28    bouyer 	adapt->adapt_minphys = sci_minphys;
    174        1.25   thorpej 
    175        1.28    bouyer 	/*
    176        1.28    bouyer 	 * Fill in the scsipi_channel.
    177        1.28    bouyer 	 */
    178        1.28    bouyer 	memset(chan, 0, sizeof(*chan));
    179        1.28    bouyer 	chan->chan_adapter = adapt;
    180        1.28    bouyer 	chan->chan_bustype = &scsi_bustype;
    181        1.28    bouyer 	chan->chan_channel = 0;
    182        1.29   aymeric 	chan->chan_ntargets = 8;
    183        1.28    bouyer 	chan->chan_nluns = 8;
    184        1.28    bouyer 	chan->chan_id = 7;
    185         1.2    chopps 
    186         1.2    chopps 	/*
    187         1.2    chopps 	 * attach all scsi units on us
    188         1.2    chopps 	 */
    189  1.35.112.1      yamt 	config_found(self, chan, scsiprint);
    190         1.2    chopps }
    191         1.2    chopps 
    192         1.2    chopps int
    193        1.29   aymeric ivsc_dma_xfer_in(struct sci_softc *dev, int len, register u_char *buf,
    194        1.29   aymeric                  int phase)
    195         1.2    chopps {
    196        1.11    chopps 	int wait = sci_data_wait;
    197        1.11    chopps 	volatile register u_char *sci_dma = dev->sci_idata + 0x20;
    198        1.11    chopps 	volatile register u_char *sci_csr = dev->sci_csr;
    199        1.15     veego #ifdef DEBUG
    200        1.15     veego 	u_char *obp = buf;
    201        1.15     veego #endif
    202        1.11    chopps 
    203        1.11    chopps 	QPRINTF(("ivsc_dma_in %d, csr=%02x\n", len, *dev->sci_bus_csr));
    204        1.11    chopps 
    205        1.11    chopps 	*dev->sci_tcmd = phase;
    206        1.11    chopps 	*dev->sci_mode |= SCI_MODE_DMA;
    207        1.11    chopps 	*dev->sci_irecv = 0;
    208        1.11    chopps 
    209        1.11    chopps 	while (len >= 128) {
    210        1.11    chopps 		wait = sci_data_wait;
    211        1.11    chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
    212        1.11    chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    213        1.11    chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
    214        1.11    chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
    215        1.11    chopps 			  || --wait < 0) {
    216        1.11    chopps #ifdef DEBUG
    217        1.11    chopps 				if (sci_debug)
    218        1.19  christos 					printf("ivsc_dma_in2 fail: l%d i%x w%d\n",
    219        1.15     veego 					len, *dev->sci_bus_csr, wait);
    220        1.11    chopps #endif
    221        1.11    chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    222        1.11    chopps 				return 0;
    223        1.11    chopps 			}
    224        1.11    chopps 		}
    225        1.11    chopps 
    226        1.11    chopps #define	R1	(*buf++ = *sci_dma)
    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 		R1; R1; R1; R1; R1; R1; R1; R1;
    242        1.11    chopps 		R1; R1; R1; R1; R1; R1; R1; R1;
    243        1.11    chopps 		len -= 128;
    244        1.11    chopps 	}
    245        1.11    chopps 
    246        1.11    chopps   	while (len > 0) {
    247        1.11    chopps 		wait = sci_data_wait;
    248        1.11    chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
    249        1.11    chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    250        1.11    chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
    251        1.11    chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
    252        1.11    chopps 			  || --wait < 0) {
    253        1.11    chopps #ifdef DEBUG
    254        1.11    chopps 				if (sci_debug)
    255        1.19  christos 					printf("ivsc_dma_in1 fail: l%d i%x w%d\n",
    256        1.15     veego 					len, *dev->sci_bus_csr, wait);
    257        1.11    chopps #endif
    258        1.11    chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    259        1.11    chopps 				return 0;
    260        1.11    chopps 			}
    261        1.11    chopps 		}
    262        1.11    chopps 
    263        1.11    chopps 		*buf++ = *sci_dma;
    264        1.11    chopps 		len--;
    265        1.11    chopps 	}
    266        1.11    chopps 
    267        1.11    chopps 	QPRINTF(("ivsc_dma_in {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    268        1.11    chopps 	  len, obp[0], obp[1], obp[2], obp[3], obp[4], obp[5],
    269        1.11    chopps 	  obp[6], obp[7], obp[8], obp[9]));
    270        1.11    chopps 
    271        1.11    chopps 	*dev->sci_mode &= ~SCI_MODE_DMA;
    272        1.11    chopps 	return 0;
    273         1.2    chopps }
    274         1.2    chopps 
    275         1.2    chopps int
    276        1.29   aymeric ivsc_dma_xfer_out(struct sci_softc *dev, int len, register u_char *buf,
    277        1.29   aymeric                   int phase)
    278         1.1    chopps {
    279        1.11    chopps 	int wait = sci_data_wait;
    280        1.11    chopps 	volatile register u_char *sci_dma = dev->sci_data + 0x20;
    281        1.11    chopps 	volatile register u_char *sci_csr = dev->sci_csr;
    282        1.11    chopps 
    283        1.11    chopps 	QPRINTF(("ivsc_dma_out %d, csr=%02x\n", len, *dev->sci_bus_csr));
    284        1.11    chopps 
    285        1.11    chopps 	QPRINTF(("ivsc_dma_out {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    286        1.11    chopps   	 len, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
    287        1.11    chopps 	 buf[6], buf[7], buf[8], buf[9]));
    288        1.11    chopps 
    289        1.11    chopps 	*dev->sci_tcmd = phase;
    290        1.11    chopps 	*dev->sci_mode |= SCI_MODE_DMA;
    291        1.11    chopps 	*dev->sci_icmd |= SCI_ICMD_DATA;
    292        1.11    chopps 	*dev->sci_dma_send = 0;
    293        1.11    chopps 	while (len > 0) {
    294        1.11    chopps 		wait = sci_data_wait;
    295        1.11    chopps 		while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
    296        1.11    chopps 		  (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    297        1.11    chopps 			if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
    298        1.11    chopps 			  || !(*dev->sci_bus_csr & SCI_BUS_BSY)
    299        1.11    chopps 			  || --wait < 0) {
    300        1.11    chopps #ifdef DEBUG
    301        1.11    chopps 				if (sci_debug)
    302        1.19  christos 					printf("ivsc_dma_out fail: l%d i%x w%d\n",
    303        1.15     veego 					len, *dev->sci_bus_csr, wait);
    304        1.11    chopps #endif
    305        1.11    chopps 				*dev->sci_mode &= ~SCI_MODE_DMA;
    306        1.11    chopps 				return 0;
    307        1.11    chopps 			}
    308        1.11    chopps 		}
    309        1.11    chopps 
    310        1.11    chopps 		*sci_dma = *buf++;
    311        1.11    chopps 		len--;
    312        1.11    chopps 	}
    313        1.11    chopps 
    314        1.11    chopps 	wait = sci_data_wait;
    315        1.11    chopps 	while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) ==
    316        1.11    chopps 	  SCI_CSR_PHASE_MATCH && --wait);
    317        1.11    chopps 
    318        1.11    chopps 
    319        1.11    chopps 	*dev->sci_mode &= ~SCI_MODE_DMA;
    320        1.11    chopps 	return 0;
    321         1.1    chopps }
    322         1.2    chopps 
    323         1.2    chopps int
    324        1.29   aymeric ivsc_intr(void *arg)
    325         1.2    chopps {
    326        1.15     veego 	struct sci_softc *dev = arg;
    327         1.2    chopps 	u_char stat;
    328         1.2    chopps 
    329         1.9    chopps 	if ((*dev->sci_csr & SCI_CSR_INT) == 0)
    330         1.9    chopps 		return(0);
    331         1.9    chopps 	stat = *dev->sci_iack;
    332  1.35.112.2      yamt 	__USE(stat);
    333        1.14        is 	/* XXXX is: something is missing here, at least a: */
    334        1.14        is 	return(1);
    335         1.2    chopps }
    336